2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2008-12-01 02:15:27 +01:00
|
|
|
* Base class invoked from CLI rather than the webserver (Cron jobs, handling email bounces).
|
|
|
|
* You can call subclasses of CliController directly, which will trigger a
|
|
|
|
* call to {@link process()} on every sub-subclass. For instance, calling
|
|
|
|
* "sake DailyTask" from the commandline will call {@link process()} on every subclass
|
|
|
|
* of DailyTask.
|
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage cron
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
abstract class CliController extends Controller {
|
|
|
|
function init() {
|
2009-02-02 00:49:53 +01:00
|
|
|
parent::init();
|
|
|
|
// Unless called from the command line, all CliControllers need ADMIN privileges
|
|
|
|
if(!Director::is_cli() && !Permission::check("ADMIN")) return Security::permissionFailure();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function index() {
|
|
|
|
foreach( ClassInfo::subclassesFor( $this->class ) as $subclass ) {
|
2008-12-01 02:15:27 +01:00
|
|
|
echo $subclass . "\n";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$task = new $subclass();
|
2008-12-01 02:15:27 +01:00
|
|
|
$task->init();
|
2007-07-19 12:40:28 +02:00
|
|
|
$task->process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 02:15:27 +01:00
|
|
|
/**
|
|
|
|
* Overload this method to contain the task logic.
|
|
|
|
*/
|
|
|
|
function process() {}
|
2009-02-02 00:49:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|