mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-27 04:56:02 +02:00
Conflicts: .travis.yml README.md admin/code/LeftAndMain.php admin/css/screen.css admin/scss/screen.scss api/RestfulService.php conf/ConfigureFromEnv.php control/injector/ServiceConfigurationLocator.php control/injector/SilverStripeServiceConfigurationLocator.php core/ClassInfo.php core/Object.php css/AssetUploadField.css css/ComplexTableField_popup.css dev/CSSContentParser.php dev/DevelopmentAdmin.php docs/en/changelogs/index.md docs/en/misc/contributing/code.md docs/en/reference/execution-pipeline.md filesystem/GD.php filesystem/ImagickBackend.php filesystem/Upload.php forms/Form.php forms/FormField.php forms/HtmlEditorConfig.php forms/gridfield/GridFieldDetailForm.php forms/gridfield/GridFieldSortableHeader.php lang/en.yml model/Aggregate.php model/DataList.php model/DataObject.php model/DataQuery.php model/Image.php model/MySQLDatabase.php model/SQLQuery.php model/fieldtypes/HTMLText.php model/fieldtypes/Text.php scss/AssetUploadField.scss search/filters/SearchFilter.php security/Authenticator.php security/LoginForm.php security/Member.php security/MemberAuthenticator.php security/MemberLoginForm.php security/Security.php tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php tests/control/HTTPTest.php tests/control/RequestHandlingTest.php tests/filesystem/UploadTest.php tests/forms/FormTest.php tests/forms/NumericFieldTest.php tests/model/DataListTest.php tests/model/DataObjectTest.php tests/model/TextTest.php tests/security/MemberAuthenticatorTest.php tests/security/SecurityDefaultAdminTest.php tests/view/SSViewerCacheBlockTest.php tests/view/SSViewerTest.php
122 lines
3.0 KiB
PHP
122 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* @package framework
|
|
* @subpackage dev
|
|
*/
|
|
class TaskRunner extends Controller {
|
|
|
|
private static $url_handlers = array(
|
|
'' => 'index',
|
|
'$TaskName' => 'runTask'
|
|
);
|
|
|
|
private static $allowed_actions = array(
|
|
'index',
|
|
'runTask',
|
|
);
|
|
|
|
public 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);
|
|
}
|
|
|
|
public function index() {
|
|
$tasks = $this->getTasks();
|
|
|
|
// Web mode
|
|
if(!Director::is_cli()) {
|
|
$renderer = new DebugView();
|
|
$renderer->writeHeader();
|
|
$renderer->writeInfo("SilverStripe Development Tools: Tasks", Director::absoluteBaseURL());
|
|
$base = Director::absoluteBaseURL();
|
|
|
|
echo "<div class=\"options\">";
|
|
echo "<ul>";
|
|
foreach($tasks as $task) {
|
|
echo "<li><p>";
|
|
echo "<a href=\"{$base}dev/tasks/" . $task['segment'] . "\">" . $task['title'] . "</a><br />";
|
|
echo "<span class=\"description\">" . $task['description'] . "</span>";
|
|
echo "</p></li>\n";
|
|
}
|
|
echo "</ul></div>";
|
|
|
|
$renderer->writeFooter();
|
|
// CLI mode
|
|
} else {
|
|
echo "SILVERSTRIPE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
|
|
foreach($tasks as $task) {
|
|
echo " * $task[title]: sake dev/tasks/" . $task['segment'] . "\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
public function runTask($request) {
|
|
$name = $request->param('TaskName');
|
|
$tasks = $this->getTasks();
|
|
|
|
$title = function ($content) {
|
|
printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
|
|
};
|
|
|
|
$message = function ($content) {
|
|
printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
|
|
};
|
|
|
|
foreach ($tasks as $task) {
|
|
if ($task['segment'] == $name) {
|
|
$inst = Injector::inst()->create($task['class']);
|
|
$title(sprintf('Running Task %s', $inst->getTitle()));
|
|
|
|
if (!$inst->isEnabled()) {
|
|
$message('The task is disabled');
|
|
return;
|
|
}
|
|
|
|
$inst->run($request);
|
|
return;
|
|
}
|
|
}
|
|
|
|
$message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name)));
|
|
}
|
|
|
|
/**
|
|
* @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(),
|
|
'segment' => str_replace('\\', '-', $class),
|
|
'description' => $desc,
|
|
);
|
|
}
|
|
|
|
return $availableTasks;
|
|
}
|
|
|
|
}
|
|
|
|
|