1 | <?php |
||
2 | |||
3 | namespace SilverStripe\Control; |
||
4 | |||
5 | use SilverStripe\Core\ClassInfo; |
||
6 | use SilverStripe\Core\Injector\Injector; |
||
7 | use SilverStripe\Security\Permission; |
||
8 | use SilverStripe\Security\Security; |
||
9 | |||
10 | /** |
||
11 | * Base class invoked from CLI rather than the webserver (Cron jobs, handling email bounces). |
||
12 | * You can call subclasses of CliController directly, which will trigger a |
||
13 | * call to {@link process()} on every sub-subclass. For instance, calling |
||
14 | * "sake DailyTask" from the commandline will call {@link process()} on every subclass |
||
15 | * of DailyTask. |
||
16 | */ |
||
17 | abstract class CliController extends Controller |
||
18 | { |
||
19 | |||
20 | private static $allowed_actions = array( |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
21 | 'index' |
||
22 | ); |
||
23 | |||
24 | protected function init() |
||
25 | { |
||
26 | parent::init(); |
||
27 | // Unless called from the command line, all CliControllers need ADMIN privileges |
||
28 | if (!Director::is_cli() && !Permission::check("ADMIN")) { |
||
29 | Security::permissionFailure(); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | public function index() |
||
34 | { |
||
35 | foreach (ClassInfo::subclassesFor(static::class) as $subclass) { |
||
36 | echo $subclass . "\n"; |
||
37 | /** @var CliController $task */ |
||
38 | $task = Injector::inst()->create($subclass); |
||
39 | $task->doInit(); |
||
40 | $task->process(); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Overload this method to contain the task logic. |
||
46 | */ |
||
47 | public function process() |
||
48 | { |
||
49 | } |
||
50 | } |
||
51 |