silverstripe-framework/cli/CliController.php

41 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* 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.
2014-08-15 08:53:05 +02:00
*
* @package framework
* @subpackage cron
*/
abstract class CliController extends Controller {
2014-08-15 08:53:05 +02:00
private static $allowed_actions = array(
'index'
);
public function init() {
parent::init();
// Unless called from the command line, all CliControllers need ADMIN privileges
if(!Director::is_cli() && !Permission::check("ADMIN")) {
return Security::permissionFailure();
}
}
public function index() {
foreach(ClassInfo::subclassesFor($this->class) as $subclass) {
echo $subclass . "\n";
$task = new $subclass();
$task->init();
$task->process();
}
}
/**
* Overload this method to contain the task logic.
*/
public function process() {}
}