2007-07-19 10:40:28 +00:00
|
|
|
<?php
|
2016-06-23 11:37:22 +12:00
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\Control;
|
|
|
|
|
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2016-06-23 11:37:22 +12:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2008-02-25 02:10:37 +00:00
|
|
|
/**
|
2008-12-01 01:15:27 +00: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 02:10:37 +00:00
|
|
|
*/
|
2007-07-19 10:40:28 +00:00
|
|
|
abstract class CliController extends Controller {
|
2014-08-15 18:53:05 +12:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $allowed_actions = array(
|
2011-02-14 11:14:51 +13:00
|
|
|
'index'
|
|
|
|
);
|
2010-05-25 02:58:59 +00:00
|
|
|
|
2015-02-23 13:46:00 +00:00
|
|
|
protected function init() {
|
2009-02-01 23:49:53 +00:00
|
|
|
parent::init();
|
|
|
|
// Unless called from the command line, all CliControllers need ADMIN privileges
|
2010-05-25 02:58:59 +00:00
|
|
|
if(!Director::is_cli() && !Permission::check("ADMIN")) {
|
2016-08-19 10:51:35 +12:00
|
|
|
Security::permissionFailure();
|
2010-05-25 02:58:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function index() {
|
2010-05-25 02:58:59 +00:00
|
|
|
foreach(ClassInfo::subclassesFor($this->class) as $subclass) {
|
|
|
|
echo $subclass . "\n";
|
2016-08-19 10:51:35 +12:00
|
|
|
/** @var CliController $task */
|
|
|
|
$task = Injector::inst()->create($subclass);
|
2015-02-23 13:46:00 +00:00
|
|
|
$task->doInit();
|
2010-05-25 02:58:59 +00:00
|
|
|
$task->process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 01:15:27 +00:00
|
|
|
/**
|
|
|
|
* Overload this method to contain the task logic.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function process() {}
|
2009-02-01 23:49:53 +00:00
|
|
|
|
2012-03-24 16:04:52 +13:00
|
|
|
}
|