Version: current

     1 <?php
     2 /**
     3  * Base class invoked from CLI rather than the webserver (Cron jobs, handling email bounces).
     4  * You can call subclasses of CliController directly, which will trigger a
     5  * call to {@link process()} on every sub-subclass. For instance, calling
     6  * "sake DailyTask" from the commandline will call {@link process()} on every subclass
     7  * of DailyTask.
     8  *
     9  * @package sapphire
    10  * @subpackage cron
    11  */
    12 abstract class CliController extends Controller {
    13
    14     function init() {
    15         parent::init();
    16         // Unless called from the command line, all CliControllers need ADMIN privileges
    17         if(!Director::is_cli() && !Permission::check("ADMIN")) {
    18             return Security::permissionFailure();
    19         }
    20     }
    21
    22     function index() {
    23         foreach(ClassInfo::subclassesFor($this->class) as $subclass) {
    24             echo $subclass . "\n";
    25             $task = new $subclass();
    26             $task->init();
    27             $task->process();
    28         }
    29     }
    30
    31     /**
    32      * Overload this method to contain the task logic.
    33      */
    34     function process() {}
    35
    36 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -