2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Control;
|
|
|
|
|
|
|
|
use SilverStripe\Core\ClassInfo;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2016-06-23 01:37:22 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
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
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
abstract class CliController extends Controller
|
|
|
|
{
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $allowed_actions = [
|
2016-11-29 00:31:16 +01:00
|
|
|
'index'
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
// Unless called from the command line, all CliControllers need ADMIN privileges
|
|
|
|
if (!Director::is_cli() && !Permission::check("ADMIN")) {
|
|
|
|
Security::permissionFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2017-05-17 07:40:13 +02:00
|
|
|
foreach (ClassInfo::subclassesFor(static::class) as $subclass) {
|
2016-11-29 00:31:16 +01:00
|
|
|
echo $subclass . "\n";
|
|
|
|
/** @var CliController $task */
|
|
|
|
$task = Injector::inst()->create($subclass);
|
|
|
|
$task->doInit();
|
|
|
|
$task->process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overload this method to contain the task logic.
|
|
|
|
*/
|
|
|
|
public function process()
|
|
|
|
{
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|