From 4206b683dac0d310395b92fbd900fb5960556a68 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 7 Jul 2013 00:00:10 +1000 Subject: [PATCH] Moved all service tasks to minion --- modules/adsl/classes/Service/Traffic/Adsl.php | 4 +- .../adsl/classes/Task/Adsl/Trafficalert.php | 22 ++++++++ .../adsl/classes/Task/Adsl/Trafficcharge.php | 22 ++++++++ modules/adsl/classes/Task/Adsl/Trafficget.php | 2 +- .../invoice/classes/Task/Invoice/Complete.php | 2 +- .../classes/Task/Invoice/Reminddue.php | 55 +++++++++++++++++++ .../classes/Controller/Task/Service.php | 35 ------------ 7 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 modules/adsl/classes/Task/Adsl/Trafficalert.php create mode 100644 modules/adsl/classes/Task/Adsl/Trafficcharge.php create mode 100644 modules/invoice/classes/Task/Invoice/Reminddue.php delete mode 100644 modules/service/classes/Controller/Task/Service.php diff --git a/modules/adsl/classes/Service/Traffic/Adsl.php b/modules/adsl/classes/Service/Traffic/Adsl.php index 7b94e9de..417952ae 100644 --- a/modules/adsl/classes/Service/Traffic/Adsl.php +++ b/modules/adsl/classes/Service/Traffic/Adsl.php @@ -141,12 +141,12 @@ abstract class Service_Traffic_Adsl { } public function alert_traffic() { - $et = Email_Template::instance('adsl_traffic_notice'); - foreach ($this->aso->services() as $so) { if (! $so->plugin()->report_traffic()) continue; + $et = Email_Template::instance('adsl_traffic_notice'); + // Get our variable data $et->to = array('account'=>array($so->account_id)); $et->variables = $so->plugin()->template_variables($et->variables()); diff --git a/modules/adsl/classes/Task/Adsl/Trafficalert.php b/modules/adsl/classes/Task/Adsl/Trafficalert.php new file mode 100644 index 00000000..ad791b93 --- /dev/null +++ b/modules/adsl/classes/Task/Adsl/Trafficalert.php @@ -0,0 +1,22 @@ +_traffic_suppliers(TRUE) as $aso) { + if ($params['verbose']) + echo $aso->name."\n"; + + Service_Traffic_Adsl::instance($aso->name)->alert_traffic(); + } + } +} +?> diff --git a/modules/adsl/classes/Task/Adsl/Trafficcharge.php b/modules/adsl/classes/Task/Adsl/Trafficcharge.php new file mode 100644 index 00000000..d77f447b --- /dev/null +++ b/modules/adsl/classes/Task/Adsl/Trafficcharge.php @@ -0,0 +1,22 @@ +_traffic_suppliers(TRUE) as $aso) { + if ($params['verbose']) + echo $aso->name."\n"; + + Service_Traffic_Adsl::instance($aso->name)->charge_excess_traffic(); + } + } +} +?> diff --git a/modules/adsl/classes/Task/Adsl/Trafficget.php b/modules/adsl/classes/Task/Adsl/Trafficget.php index 9b7b1426..139bf07d 100644 --- a/modules/adsl/classes/Task/Adsl/Trafficget.php +++ b/modules/adsl/classes/Task/Adsl/Trafficget.php @@ -10,7 +10,7 @@ * @license http://dev.osbill.net/license.html */ class Task_Adsl_Trafficget extends Minion_Task { - private function _traffic_suppliers($active=FALSE) { + protected function _traffic_suppliers($active=FALSE) { $suppliers = ORM::factory('ADSL_Supplier'); return $active ? $suppliers->list_active() : $suppliers->find_all(); diff --git a/modules/invoice/classes/Task/Invoice/Complete.php b/modules/invoice/classes/Task/Invoice/Complete.php index d983156f..1a34d217 100644 --- a/modules/invoice/classes/Task/Invoice/Complete.php +++ b/modules/invoice/classes/Task/Invoice/Complete.php @@ -26,7 +26,7 @@ class Task_Invoice_Complete extends Minion_Task { $c++; } - printf('%s invoices updated',$c); + return sprintf('%s invoices updated',$c); } } ?> diff --git a/modules/invoice/classes/Task/Invoice/Reminddue.php b/modules/invoice/classes/Task/Invoice/Reminddue.php new file mode 100644 index 00000000..5fbb8c13 --- /dev/null +++ b/modules/invoice/classes/Task/Invoice/Reminddue.php @@ -0,0 +1,55 @@ +config(strtoupper($key)); + + foreach (ORM::factory('Invoice')->list_due(time()+86400*$days) as $io) { + // @todo Use another option to supress reminders + // If we have already sent a reminder, we'll skip to the next one. + if (($io->remind($key) AND (is_null($x=$this->request->param('id')) OR $x != 'again')) OR ($io->account->invoice_delivery != 1)) + continue; + + // Generate a token to view the invoice online + $token = ORM::factory('Module_Method_Token') + ->method(array('invoice','user_view')) + ->account($io->account) + ->expire(time()+86400*21) + ->uses(3) + ->generate(); + + // Send our email + $et = Email_Template::instance('task_invoice_'.$key); + + $et->to = array('account'=>array($io->account_id)); + $et->variables = array( + 'DUE'=>$io->due(TRUE), + 'DUE_DATE'=>$io->display('due_date'), + 'FIRST_NAME'=>$io->account->first_name, + 'INV_NUM'=>$io->refnum(), + 'INV_URL'=>URL::site(URL::link('user',sprintf('invoice/view/%s?token=%s',$io->id,$token)),'http'), + 'SITE_NAME'=>Company::instance()->name(), + ); + + // @todo Record email log id if possible. + if ($et->send()) { + $io->set_remind($key,time()); + array_push($action,(string)$io); + } + } + + return _('Due Reminders Sent: ').join('|',$action); + } +} +?> diff --git a/modules/service/classes/Controller/Task/Service.php b/modules/service/classes/Controller/Task/Service.php deleted file mode 100644 index 3ec35f94..00000000 --- a/modules/service/classes/Controller/Task/Service.php +++ /dev/null @@ -1,35 +0,0 @@ -list_active() : $suppliers->find_all(); - } - - /** - * Charges for excess traffic usage - */ - public function action_chargetraffic() { - foreach ($this->_traffic_suppliers(TRUE) as $aso) - $traffic = Service_Traffic_Adsl::instance($aso->name)->charge_excess_traffic(); - } - - /** - * Send alerts to users when they exceed their traffic allowance - */ - public function action_alerttraffic() { - foreach ($this->_traffic_suppliers(TRUE) as $aso) - $traffic = Service_Traffic_Adsl::instance($aso->name)->alert_traffic(); - } -} -?>