Fixes to OSB to work with KH 3.3
This commit is contained in:
@@ -22,7 +22,7 @@ class Controller_Admin_Task extends Controller_TemplateDefault_Admin {
|
||||
Block::add(array(
|
||||
'title'=>_('Task Log'),
|
||||
'body'=>Table::display(
|
||||
ORM::factory('task_log')->order_by('id','DESC')->find_all(),
|
||||
ORM::factory('Task_Log')->order_by('id','DESC')->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'admin/task/view/'),
|
@@ -19,7 +19,7 @@ class Model_Task extends ORM_OSB {
|
||||
|
||||
public function run() {
|
||||
$r = rand(0,9999);
|
||||
$tlo = ORM::factory('task_log');
|
||||
$tlo = ORM::factory('Task_Log');
|
||||
$tlo->task_id = $this->id;
|
||||
|
||||
if (! $this->loaded())
|
36
modules/task/classes/Task/Task/ListActive.php
Normal file
36
modules/task/classes/Task/Task/ListActive.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* List all Active Tasks defined in the DB
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Task
|
||||
* @category Task/Task
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Task_ListActive extends Task {
|
||||
protected function _execute(array $params) {
|
||||
$output = '';
|
||||
|
||||
$output .= sprintf('%2s %30s %21s %21s %40s',
|
||||
'ID','Command','Last Run','Next Run','Description');
|
||||
$output .= "\n";
|
||||
|
||||
foreach (ORM::factory('Task')->list_active() as $t) {
|
||||
$output .= sprintf('%2s %30s %21s %21s %40s',
|
||||
$t['task']->id,
|
||||
$t['task']->command,
|
||||
$t['task']->display('date_run'),
|
||||
Config::datetime($t['next']),
|
||||
$t['task']->display('description')
|
||||
);
|
||||
|
||||
$output .= "\n";
|
||||
};
|
||||
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
?>
|
47
modules/task/classes/Task/Task/Run.php
Normal file
47
modules/task/classes/Task/Task/Run.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Run active tasks according to their CRON schedule
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Task
|
||||
* @category Task/Task
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Task_Run extends Task {
|
||||
protected function _execute(array $params) {
|
||||
if (isset($params['id'])) {
|
||||
$to = ORM::factory('Task',$params['id']);
|
||||
|
||||
if ($to->loaded()) {
|
||||
if (! $to->status)
|
||||
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();
|
||||
else
|
||||
printf('Would Run task: (%s) %s',$params['id'],$to->name);
|
||||
|
||||
echo "\n";
|
||||
|
||||
} else
|
||||
throw new Minion_Exception_InvalidTask('Unknown task :task',array(':task'=>$params['id']));
|
||||
|
||||
} else {
|
||||
$tlo = ORM::factory('Task');
|
||||
$t = time();
|
||||
|
||||
foreach ($tlo->list_active() as $to)
|
||||
if ($to['next'] < $t) {
|
||||
if (! Kohana::$config->load('debug')->task_sim)
|
||||
$to['task']->run();
|
||||
else
|
||||
printf('Would Run task: (%s) %s',$to['task']->id,$to['task']->name);
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,15 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides task management
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page/Task
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Task extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
@@ -1,59 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB task running capabilities.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Task
|
||||
* @category Controllers/Admin
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Task_Task extends Controller_Task {
|
||||
/**
|
||||
* List all tasks
|
||||
*/
|
||||
public function action_list() {
|
||||
$output = '';
|
||||
$to = ORM::factory('task');
|
||||
$tm = 'list_'.$this->request->param('id');
|
||||
|
||||
if (! method_exists($to,$tm))
|
||||
throw new Kohana_Exception('Unknown Task List command :command',array(':command'=>$tm));
|
||||
|
||||
$output .= sprintf('%2s %30s %21s %21s %40s',
|
||||
'ID','Command','Last Run','Next Run','Description');
|
||||
$output .= "\n";
|
||||
|
||||
foreach ($to->$tm() as $t) {
|
||||
$output .= sprintf('%2s %30s %21s %21s %40s',
|
||||
$t['task']->id,
|
||||
$t['task']->command,
|
||||
$t['task']->display('date_run'),
|
||||
Config::datetime($t['next']),
|
||||
$t['task']->display('description')
|
||||
);
|
||||
|
||||
$output .= "\n";
|
||||
};
|
||||
|
||||
$this->response->body($output);
|
||||
}
|
||||
|
||||
public function action_run() {
|
||||
if ($id = $this->request->param('id')) {
|
||||
$to = ORM::factory('task',$id);
|
||||
$to->run();
|
||||
|
||||
} else {
|
||||
$tlo = ORM::factory('task');
|
||||
$t = time();
|
||||
|
||||
foreach ($tlo->list_active() as $to)
|
||||
if ($to['next'] < $t)
|
||||
$to['task']->run();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user