'index', '$TaskName' => 'runTask' ); static $allowed_actions = array( 'index', 'runTask', ); function init() { parent::init(); $isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test()); $canAccess = ( Director::isDev() // We need to ensure that DevelopmentAdminTest can simulate permission failures when running // "dev/tasks" from CLI. || (Director::is_cli() && !$isRunningTests) || Permission::check("ADMIN") ); if(!$canAccess) return Security::permissionFailure($this); } function index() { $tasks = $this->getTasks(); // Web mode if(!Director::is_cli()) { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Sapphire Development Tools: Tasks", Director::absoluteBaseURL()); $base = Director::absoluteBaseURL(); echo "
{$title} is disabled
"; } else { echo "Build task '$taskName' not found."; if(class_exists($taskName)) echo " It isn't a subclass of BuildTask."; echo "\n"; } } /** * @return array Array of associative arrays for each task (Keys: 'class', 'title', 'description') */ protected function getTasks() { $availableTasks = array(); $taskClasses = ClassInfo::subclassesFor('BuildTask'); // remove the base class array_shift($taskClasses); if($taskClasses) foreach($taskClasses as $class) { if(!singleton($class)->isEnabled()) continue; $desc = (Director::is_cli()) ? Convert::html2raw(singleton($class)->getDescription()) : singleton($class)->getDescription(); $availableTasks[] = array( 'class' => $class, 'title' => singleton($class)->getTitle(), 'description' => $desc, ); } return $availableTasks; } } ?>