Fixed ADSL traffic collection, and migrated Task to Minion
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_Adsl {
|
||||
protected $so;
|
||||
abstract class Service_Traffic_Adsl {
|
||||
protected $aso;
|
||||
protected $today;
|
||||
protected $fetchresult = NULL;
|
||||
protected $curlopts = array(
|
||||
@@ -33,14 +33,14 @@ class Service_Traffic_Adsl {
|
||||
// Our DB record must be the suffix of this class name
|
||||
$supplier = preg_replace('/^'.get_parent_class($this).'_/','',get_class($this));
|
||||
|
||||
$so = ORM::factory('ADSL_Supplier')
|
||||
$aso = ORM::factory('ADSL_Supplier')
|
||||
->where('name','=',$supplier)
|
||||
->find();
|
||||
|
||||
if (! $so->loaded())
|
||||
if (! $aso->loaded())
|
||||
throw new Kohana_Exception('Supplier :supplier not defined in the database',array(':supplier'=>$supplier));
|
||||
|
||||
$this->so = $so;
|
||||
$this->aso = $aso;
|
||||
$this->today = date('Y-m-d',strtotime('yesterday'));
|
||||
}
|
||||
|
||||
@@ -56,22 +56,14 @@ class Service_Traffic_Adsl {
|
||||
return new $sc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last date we obtained the stats.
|
||||
*/
|
||||
private function last_update() {
|
||||
return $this->so->stats_lastupdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traffic data from supplier
|
||||
*/
|
||||
public function update_traffic() {
|
||||
if (Minion_CLI::options('verbose'))
|
||||
echo ' - Last: '.date('Y-m-d',strtotime($this->last_update().'+1 day'))."\n";
|
||||
echo ' - Last: '.date('Y-m-d',strtotime($this->aso->stats_lastupdate.'+1 day'))."\n";
|
||||
|
||||
$alreadyrun = FALSE;
|
||||
for ($querydate=date('Y-m-d',strtotime($this->last_update().'+1 day'));
|
||||
for ($querydate=date('Y-m-d',strtotime($this->aso->stats_lastupdate.'+1 day'));
|
||||
$querydate<=$this->today;
|
||||
$querydate=date('Y-m-d',strtotime($querydate.'+1 day'))) {
|
||||
|
||||
@@ -96,7 +88,7 @@ class Service_Traffic_Adsl {
|
||||
$traffic = ORM::factory('Service_Plugin_Adsl_Traffic');
|
||||
foreach ($data as $item) {
|
||||
$traffic->values($item,array_keys($item));
|
||||
$traffic->supplier_id = $this->so->id;
|
||||
$traffic->supplier_id = $this->aso->id;
|
||||
|
||||
if ($traffic->check())
|
||||
$traffic->save();
|
||||
@@ -108,15 +100,17 @@ class Service_Traffic_Adsl {
|
||||
}
|
||||
}
|
||||
|
||||
$this->so->stats_lastupdate = $this->today;
|
||||
$this->so->save();
|
||||
if ($this->fetchresult) {
|
||||
$this->aso->stats_lastupdate = $this->today;
|
||||
$this->aso->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function charge_excess_traffic() {
|
||||
$date = strtotime('last month');
|
||||
|
||||
// @todo need a way to find out services that have traffic charges dynamically.
|
||||
foreach ($this->so->services() as $so) {
|
||||
foreach ($this->aso->services() as $so) {
|
||||
if ($charge = $so->plugin()->traffic_lastmonth_exceed(FALSE,$date)) {
|
||||
foreach ($charge as $metric => $details) {
|
||||
$co = ORM::factory('Charge');
|
||||
@@ -149,7 +143,7 @@ class Service_Traffic_Adsl {
|
||||
public function alert_traffic() {
|
||||
$et = Email_Template::instance('adsl_traffic_notice');
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
foreach ($this->aso->services() as $so) {
|
||||
if (! $so->plugin()->report_traffic())
|
||||
continue;
|
||||
|
||||
|
Reference in New Issue
Block a user