diff --git a/poll-billing.php b/poll-billing.php index 38de5660cc..193f398aef 100755 --- a/poll-billing.php +++ b/poll-billing.php @@ -11,41 +11,39 @@ * @copyright (C) 2006 - 2012 Adam Armstrong */ -// FIXME - implement cli switches, debugging, etc. $init_modules = array(); require __DIR__ . '/includes/init.php'; -$iter = '0'; +if (isset($argv[1]) && is_numeric($argv[1])) { + // allow old cli style + $options = ['b' => $argv[1]]; +} else { + $options = getopt('db:'); +} + +set_debug(isset($options['d'])); + +// Wait for schema update, as running during update can break update +if (get_db_schema() < 107) { + logfile("BILLING: Cannot continue until the database schema update to >= 107 is complete"); + exit(1); +} rrdtool_initialize(); $poller_start = microtime(true); echo "Starting Polling Session ... \n\n"; -// Wait for schema update, as running during update can break update -$dbVersion = get_db_schema(); -if ($dbVersion < 107) { - logfile("BILLING: Cannot continue until the database schema update to >= 107 is complete"); - exit(1); +$query = \LibreNMS\DB\Eloquent::DB()->table('bills'); + +if (isset($options['b'])) { + $query->where('bill_id', $options['b']); } -foreach (dbFetchRows('SELECT * FROM `bills`') as $bill_data) { - echo 'Bill : '.$bill_data['bill_name']."\n"; +foreach ($query->get(['bill_id', 'bill_name']) as $bill) { + echo 'Bill : '.$bill->bill_name."\n"; + $bill_id = $bill->bill_id; - // replace old bill_gb with bill_quota (we're now storing bytes, not gigabytes) - if ($bill_data['bill_type'] == 'quota' && !is_numeric($bill_data['bill_quota'])) { - $bill_data['bill_quota'] = ($bill_data['bill_gb'] * $config['billing']['base'] * $config['billing']['base']); - dbUpdate(array('bill_quota' => $bill_data['bill_quota']), 'bills', '`bill_id` = ?', array($bill_data['bill_id'])); - echo 'Quota -> '.$bill_data['bill_quota']; - } - - CollectData($bill_data['bill_id']); - $iter++; -} - - -function CollectData($bill_id) -{ $port_list = dbFetchRows('SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($bill_id)); $now = dbFetchCell('SELECT NOW()'); @@ -134,10 +132,6 @@ function CollectData($bill_id) }//end CollectData() -if ($argv[1]) { - CollectData($argv[1]); -} - $poller_end = microtime(true); $poller_run = ($poller_end - $poller_start); $poller_time = substr($poller_run, 0, 5);