From 7819a05515c4f18eafd0ac112b66fed37beae73a Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 11 Jan 2013 21:51:37 +1100 Subject: [PATCH] Fixes for ADSL traffic collection and other ADSL items --- application/classes/Task.php | 2 ++ modules/adsl/classes/ADSL.php | 2 +- .../adsl/classes/Model/{ADSL => Adsl}/Plan.php | 2 +- .../classes/Model/{ADSL => Adsl}/Supplier.php | 8 ++++---- .../Model/{ADSL => Adsl}/Supplier/Plan.php | 6 +++--- .../Model/Service/Plugin/Adsl/Traffic.php | 4 ++-- .../Service/Traffic/{ADSL.php => Adsl.php} | 4 ++-- .../{ADSL/ExetelHSPA.php => Adsl/Exetelhspa.php} | 16 ++++++++-------- .../{ADSL/ExetelPE.php => Adsl/Exetelpe.php} | 12 ++++++------ .../{ADSL/ExetelVISP.php => Adsl/Exetelvisp.php} | 2 +- .../Traffic/{ADSL => Adsl}/PeopleAgent.php | 0 .../Service/Traffic/{ADSL => Adsl}/iiNetADSL.php | 0 .../service/classes/Controller/Admin/Service.php | 2 +- .../service/classes/Controller/Task/Service.php | 6 +++--- modules/task/classes/Model/Task.php | 4 ++-- modules/task/classes/Task/Task/Run.php | 4 ++-- 16 files changed, 38 insertions(+), 36 deletions(-) rename modules/adsl/classes/Model/{ADSL => Adsl}/Plan.php (96%) rename modules/adsl/classes/Model/{ADSL => Adsl}/Supplier.php (90%) rename modules/adsl/classes/Model/{ADSL => Adsl}/Supplier/Plan.php (85%) rename modules/adsl/classes/Service/Traffic/{ADSL.php => Adsl.php} (97%) rename modules/adsl/classes/Service/Traffic/{ADSL/ExetelHSPA.php => Adsl/Exetelhspa.php} (93%) rename modules/adsl/classes/Service/Traffic/{ADSL/ExetelPE.php => Adsl/Exetelpe.php} (94%) rename modules/adsl/classes/Service/Traffic/{ADSL/ExetelVISP.php => Adsl/Exetelvisp.php} (96%) rename modules/adsl/classes/Service/Traffic/{ADSL => Adsl}/PeopleAgent.php (100%) rename modules/adsl/classes/Service/Traffic/{ADSL => Adsl}/iiNetADSL.php (100%) diff --git a/application/classes/Task.php b/application/classes/Task.php index 0d10935d..8243efc9 100644 --- a/application/classes/Task.php +++ b/application/classes/Task.php @@ -14,6 +14,8 @@ abstract class Task extends Minion_Task { protected $_options = array( 'site'=>NULL, 'id'=>NULL, + 'force'=>FALSE, + 'verbose'=>FALSE, ); } ?> diff --git a/modules/adsl/classes/ADSL.php b/modules/adsl/classes/ADSL.php index db178bcd..02898e11 100644 --- a/modules/adsl/classes/ADSL.php +++ b/modules/adsl/classes/ADSL.php @@ -33,7 +33,7 @@ class ADSL { if (preg_match('/^a:/',$data)) throw new Kohana_Exception('Data shouldnt be a serialized array'); - $ao = ORM::factory('ADSL_Plan',$data); + $ao = ORM::factory('Adsl_Plan',$data); $output = View::factory('adsl/contract_view') ->set('record',$ao) ->set('price_base',$price_base) diff --git a/modules/adsl/classes/Model/ADSL/Plan.php b/modules/adsl/classes/Model/Adsl/Plan.php similarity index 96% rename from modules/adsl/classes/Model/ADSL/Plan.php rename to modules/adsl/classes/Model/Adsl/Plan.php index 466f8e2b..e7169ac0 100644 --- a/modules/adsl/classes/Model/ADSL/Plan.php +++ b/modules/adsl/classes/Model/Adsl/Plan.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Plan extends ORM_OSB { +class Model_Adsl_Plan extends ORM_OSB { // Relationships // @todo This model should probably be joined with product_plugin_adsl protected $_belongs_to = array( diff --git a/modules/adsl/classes/Model/ADSL/Supplier.php b/modules/adsl/classes/Model/Adsl/Supplier.php similarity index 90% rename from modules/adsl/classes/Model/ADSL/Supplier.php rename to modules/adsl/classes/Model/Adsl/Supplier.php index 8e899aae..4bdb7b49 100644 --- a/modules/adsl/classes/Model/ADSL/Supplier.php +++ b/modules/adsl/classes/Model/Adsl/Supplier.php @@ -10,10 +10,10 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Supplier extends ORM_OSB { +class Model_Adsl_Supplier extends ORM_OSB { // Relationships protected $_has_many = array( - 'ADSL_supplier_plan'=>array('foreign_key'=>'supplier_id','far_key'=>'id'), + 'adsl_supplier_plan'=>array('foreign_key'=>'supplier_id','far_key'=>'id'), ); protected $_updated_column = FALSE; @@ -22,7 +22,7 @@ class Model_ADSL_Supplier extends ORM_OSB { * Return a list of plans that this supplier makes available */ public function plans($active=TRUE) { - $a = $this->ADSL_supplier_plan; + $a = $this->adsl_supplier_plan; if ($active) $a->where_active(); @@ -37,7 +37,7 @@ class Model_ADSL_Supplier extends ORM_OSB { $return = array(); foreach ($this->plans($active)->find_all() as $po) - foreach ($po->ADSL_plan->find_all() as $apo) + foreach ($po->adsl_plan->find_all() as $apo) $return[$apo->id] = $apo; return $return; diff --git a/modules/adsl/classes/Model/ADSL/Supplier/Plan.php b/modules/adsl/classes/Model/Adsl/Supplier/Plan.php similarity index 85% rename from modules/adsl/classes/Model/ADSL/Supplier/Plan.php rename to modules/adsl/classes/Model/Adsl/Supplier/Plan.php index 7c8ad355..4a3cdace 100644 --- a/modules/adsl/classes/Model/ADSL/Supplier/Plan.php +++ b/modules/adsl/classes/Model/Adsl/Supplier/Plan.php @@ -10,13 +10,13 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_ADSL_Supplier_Plan extends ORM_OSB { +class Model_Adsl_Supplier_Plan extends ORM_OSB { // Relationships protected $_has_many = array( - 'ADSL_plan'=>array('far_key'=>'id'), + 'adsl_plan'=>array('far_key'=>'id'), ); protected $_belongs_to = array( - 'ADSL_supplier'=>array('foreign_key'=>'supplier_id'), + 'adsl_supplier'=>array('foreign_key'=>'supplier_id'), ); /** diff --git a/modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php b/modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php index bbe9c13e..731815a6 100644 --- a/modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php +++ b/modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Model_Service_Plugin_ADSL_Traffic extends ORM_OSB { +class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB { protected $_table_name = 'service__adsl_traffic'; protected $_primary_key = 'service'; protected $_disable_wild_select = TRUE; @@ -27,7 +27,7 @@ class Model_Service_Plugin_ADSL_Traffic extends ORM_OSB { return $result; } - public function traffic(Model_Product_Plugin_ADSL $plan) { + public function traffic(Model_Product_Plugin_Adsl $plan) { // Roll up the charges according to the product plan configuration return ADSL::allowance(array( 'base_down_peak'=>is_null($plan->base_down_peak) ? NULL : $this->down_peak, diff --git a/modules/adsl/classes/Service/Traffic/ADSL.php b/modules/adsl/classes/Service/Traffic/Adsl.php similarity index 97% rename from modules/adsl/classes/Service/Traffic/ADSL.php rename to modules/adsl/classes/Service/Traffic/Adsl.php index 4396186e..a7a0dc4d 100644 --- a/modules/adsl/classes/Service/Traffic/ADSL.php +++ b/modules/adsl/classes/Service/Traffic/Adsl.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Service_Traffic_ADSL { +class Service_Traffic_Adsl { protected $so; protected $today; protected $fetchresult = NULL; @@ -51,7 +51,7 @@ class Service_Traffic_ADSL { * @return HeadImage */ public static function instance($supplier) { - $sc = sprintf('%s_%s',get_called_class(),$supplier); + $sc = sprintf('%s_%s',get_called_class(),ucwords(strtolower($supplier))); if (! class_exists($sc)) throw new Kohana_Exception('Class doesnt exist for :supplier',array(':supplier'=>$supplier)); diff --git a/modules/adsl/classes/Service/Traffic/ADSL/ExetelHSPA.php b/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php similarity index 93% rename from modules/adsl/classes/Service/Traffic/ADSL/ExetelHSPA.php rename to modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php index ee5fe51d..0f50177b 100644 --- a/modules/adsl/classes/Service/Traffic/ADSL/ExetelHSPA.php +++ b/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php @@ -1,7 +1,7 @@ fetchresult = TRUE; // If we have already collected the date data, return it. - if (! empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date])) - return Service_Traffic_ADSL_ExetelHSPA::$return[$date]; + if (! empty(Service_Traffic_Adsl_Exetelhspa::$return[$date])) + return Service_Traffic_Adsl_Exetelhspa::$return[$date]; include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php'; @@ -174,14 +174,14 @@ class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL { // Reformat the data into date order. foreach ($update as $service => $sdata) foreach ($sdata as $sdate => $details) - Service_Traffic_ADSL_ExetelHSPA::$return[$sdate][$service] = $details; + Service_Traffic_Adsl_Exetelhspa::$return[$sdate][$service] = $details; // If the date we want is empty, return an array - if (empty(Service_Traffic_ADSL_ExetelHSPA::$return[$date])) + if (empty(Service_Traffic_Adsl_Exetelhspa::$return[$date])) return array(); // Return the date we asked for - return Service_Traffic_ADSL_ExetelHSPA::$return[$date]; + return Service_Traffic_Adsl_Exetelhspa::$return[$date]; } } ?> diff --git a/modules/adsl/classes/Service/Traffic/ADSL/ExetelPE.php b/modules/adsl/classes/Service/Traffic/Adsl/Exetelpe.php similarity index 94% rename from modules/adsl/classes/Service/Traffic/ADSL/ExetelPE.php rename to modules/adsl/classes/Service/Traffic/Adsl/Exetelpe.php index b0566706..bdf5f980 100644 --- a/modules/adsl/classes/Service/Traffic/ADSL/ExetelPE.php +++ b/modules/adsl/classes/Service/Traffic/Adsl/Exetelpe.php @@ -13,7 +13,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Service_Traffic_ADSL_ExetelPE extends Service_Traffic_ADSL { +class Service_Traffic_Adsl_Exetelpe extends Service_Traffic_Adsl { private $login_user_field = 'login_name'; private $login_pass_field = 'password'; private $date_field = 'date'; @@ -30,8 +30,8 @@ class Service_Traffic_ADSL_ExetelPE extends Service_Traffic_ADSL { $this->fetchresult = TRUE; // If we have already collected the date data, return it. - if (! empty(Service_Traffic_ADSL_ExetelPE::$return[$date])) - return Service_Traffic_ADSL_ExetelPE::$return[$date]; + if (! empty(Service_Traffic_Adsl_Exetelpe::$return[$date])) + return Service_Traffic_Adsl_Exetelpe::$return[$date]; include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php'; @@ -167,14 +167,14 @@ class Service_Traffic_ADSL_ExetelPE extends Service_Traffic_ADSL { // Reformat the data into date order. foreach ($update as $service => $sdata) foreach ($sdata as $sdate => $details) - Service_Traffic_ADSL_ExetelPE::$return[$sdate][$service] = $details; + Service_Traffic_Adsl_Exetelpe::$return[$sdate][$service] = $details; // If the date we want is empty, return an array - if (empty(Service_Traffic_ADSL_ExetelPE::$return[$date])) + if (empty(Service_Traffic_Adsl_Exetelpe::$return[$date])) return array(); // Return the date we asked for - return Service_Traffic_ADSL_ExetelPE::$return[$date]; + return Service_Traffic_Adsl_Exetelpe::$return[$date]; } } ?> diff --git a/modules/adsl/classes/Service/Traffic/ADSL/ExetelVISP.php b/modules/adsl/classes/Service/Traffic/Adsl/Exetelvisp.php similarity index 96% rename from modules/adsl/classes/Service/Traffic/ADSL/ExetelVISP.php rename to modules/adsl/classes/Service/Traffic/Adsl/Exetelvisp.php index 4a0c1c2f..3dacd8ff 100644 --- a/modules/adsl/classes/Service/Traffic/ADSL/ExetelVISP.php +++ b/modules/adsl/classes/Service/Traffic/Adsl/Exetelvisp.php @@ -10,7 +10,7 @@ * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ -class Service_Traffic_ADSL_ExetelVisp extends Service_Traffic_ADSL { +class Service_Traffic_Adsl_Exetelvisp extends Service_Traffic_Adsl { private $login_user_field = 'username'; private $login_pass_field = 'password'; private $date_field = 'date'; diff --git a/modules/adsl/classes/Service/Traffic/ADSL/PeopleAgent.php b/modules/adsl/classes/Service/Traffic/Adsl/PeopleAgent.php similarity index 100% rename from modules/adsl/classes/Service/Traffic/ADSL/PeopleAgent.php rename to modules/adsl/classes/Service/Traffic/Adsl/PeopleAgent.php diff --git a/modules/adsl/classes/Service/Traffic/ADSL/iiNetADSL.php b/modules/adsl/classes/Service/Traffic/Adsl/iiNetADSL.php similarity index 100% rename from modules/adsl/classes/Service/Traffic/ADSL/iiNetADSL.php rename to modules/adsl/classes/Service/Traffic/Adsl/iiNetADSL.php diff --git a/modules/service/classes/Controller/Admin/Service.php b/modules/service/classes/Controller/Admin/Service.php index 28a7b31f..e336c3db 100644 --- a/modules/service/classes/Controller/Admin/Service.php +++ b/modules/service/classes/Controller/Admin/Service.php @@ -480,7 +480,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { public function action_listadslbilling() { $id = $this->request->param('id'); - $aso = ORM::factory('ADSL_Supplier',$id); + $aso = ORM::factory('Adsl_Supplier',$id); // Process upload // @todo This should be separated out by supplier in case each supplier has a different format diff --git a/modules/service/classes/Controller/Task/Service.php b/modules/service/classes/Controller/Task/Service.php index 7fac9123..7e4dba8d 100644 --- a/modules/service/classes/Controller/Task/Service.php +++ b/modules/service/classes/Controller/Task/Service.php @@ -25,7 +25,7 @@ class Controller_Task_Service extends Controller_Task { if (Minion_CLI::options('verbose')) echo $aso->name."\n"; - $traffic = Service_Traffic_ADSL::instance($aso->name)->update_traffic(); + $traffic = Service_Traffic_Adsl::instance($aso->name)->update_traffic(); } } @@ -34,7 +34,7 @@ class Controller_Task_Service extends Controller_Task { */ public function action_chargetraffic() { foreach ($this->_traffic_suppliers(TRUE) as $aso) - $traffic = Service_Traffic_ADSL::instance($aso->name)->charge_excess_traffic(); + $traffic = Service_Traffic_Adsl::instance($aso->name)->charge_excess_traffic(); } /** @@ -42,7 +42,7 @@ class Controller_Task_Service extends Controller_Task { */ public function action_alerttraffic() { foreach ($this->_traffic_suppliers(TRUE) as $aso) - $traffic = Service_Traffic_ADSL::instance($aso->name)->alert_traffic(); + $traffic = Service_Traffic_Adsl::instance($aso->name)->alert_traffic(); } } ?> diff --git a/modules/task/classes/Model/Task.php b/modules/task/classes/Model/Task.php index 818cd10f..611176a1 100644 --- a/modules/task/classes/Model/Task.php +++ b/modules/task/classes/Model/Task.php @@ -17,7 +17,7 @@ class Model_Task extends ORM_OSB { ), ); - public function run() { + public function run($force=FALSE) { $r = rand(0,9999); $tlo = ORM::factory('Task_Log'); $tlo->task_id = $this->id; @@ -28,7 +28,7 @@ class Model_Task extends ORM_OSB { elseif (! $this->status) $tlo->message = sprintf('Task %s is not active',$this->id); - elseif ($this->running) + elseif ($this->running AND ! $force) $tlo->message = sprintf('Task %s is already running',$this->id); elseif (! preg_match('/\//',$this->command)) diff --git a/modules/task/classes/Task/Task/Run.php b/modules/task/classes/Task/Task/Run.php index 4a691372..f4f05fcc 100644 --- a/modules/task/classes/Task/Task/Run.php +++ b/modules/task/classes/Task/Task/Run.php @@ -12,7 +12,7 @@ */ class Task_Task_Run extends Task { protected function _execute(array $params) { - if (isset($params['id'])) { + if ($params['id']) { $to = ORM::factory('Task',$params['id']); if ($to->loaded()) { @@ -20,7 +20,7 @@ class Task_Task_Run extends Task { throw new Minion_Exception_InvalidTask('Task :task (:name) NOT active',array(':task'=>$params['id'],':name'=>$to->name)); if (! Kohana::$config->load('debug')->task_sim) - $to->run(); + $to->run($params['force']); else printf('Would Run task: (%s) %s',$params['id'],$to->name);