Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Dev;
|
|
|
|
|
2020-08-26 01:11:13 +02:00
|
|
|
use ReflectionClass;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\Director;
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\ClassInfo;
|
2020-08-26 01:11:13 +02:00
|
|
|
use SilverStripe\Core\Config\Configurable;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2020-08-26 01:11:13 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-06-23 01:37:22 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2020-08-26 01:11:13 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
|
|
|
use SilverStripe\View\ViewableData;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
class TaskRunner extends Controller
|
|
|
|
{
|
|
|
|
|
2020-08-26 01:11:13 +02:00
|
|
|
use Configurable;
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $url_handlers = [
|
2016-11-29 00:31:16 +01:00
|
|
|
'' => 'index',
|
|
|
|
'$TaskName' => 'runTask'
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
private static $allowed_actions = [
|
2016-11-29 00:31:16 +01:00
|
|
|
'index',
|
|
|
|
'runTask',
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2020-08-26 01:11:13 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $css = [
|
|
|
|
'silverstripe/framework:client/styles/task-runner.css',
|
|
|
|
];
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
$allowAllCLI = DevelopmentAdmin::config()->get('allow_all_cli');
|
2016-11-29 00:31:16 +01:00
|
|
|
$canAccess = (
|
|
|
|
Director::isDev()
|
|
|
|
// We need to ensure that DevelopmentAdminTest can simulate permission failures when running
|
|
|
|
// "dev/tasks" from CLI.
|
2017-06-22 12:50:45 +02:00
|
|
|
|| (Director::is_cli() && $allowAllCLI)
|
2016-11-29 00:31:16 +01:00
|
|
|
|| Permission::check("ADMIN")
|
|
|
|
);
|
|
|
|
if (!$canAccess) {
|
|
|
|
Security::permissionFailure($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2020-08-26 01:11:13 +02:00
|
|
|
$baseUrl = Director::absoluteBaseURL();
|
2016-11-29 00:31:16 +01:00
|
|
|
$tasks = $this->getTasks();
|
|
|
|
|
2020-08-26 01:11:13 +02:00
|
|
|
if (Director::is_cli()) {
|
|
|
|
// CLI mode
|
|
|
|
$output = 'SILVERSTRIPE DEVELOPMENT TOOLS: Tasks' . PHP_EOL . '--------------------------' . PHP_EOL . PHP_EOL;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
foreach ($tasks as $task) {
|
2020-08-26 01:11:13 +02:00
|
|
|
$output .= sprintf(' * %s: sake dev/tasks/%s%s', $task['title'], $task['segment'], PHP_EOL);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2020-08-26 01:11:13 +02:00
|
|
|
return $output;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2020-08-26 01:11:13 +02:00
|
|
|
|
|
|
|
$list = ArrayList::create();
|
|
|
|
|
|
|
|
foreach ($tasks as $task) {
|
|
|
|
$list->push(ArrayData::create([
|
|
|
|
'TaskLink' => $baseUrl . 'dev/tasks/' . $task['segment'],
|
|
|
|
'Title' => $task['title'],
|
|
|
|
'Description' => $task['description'],
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$renderer = DebugView::create();
|
|
|
|
$header = $renderer->renderHeader();
|
|
|
|
$header = $this->addCssToHeader($header);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'Tasks' => $list,
|
|
|
|
'Header' => $header,
|
|
|
|
'Footer' => $renderer->renderFooter(),
|
|
|
|
'Info' => $renderer->renderInfo('SilverStripe Development Tools: Tasks', $baseUrl),
|
|
|
|
];
|
|
|
|
|
|
|
|
return ViewableData::create()->renderWith(static::class, $data);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-15 13:20:29 +01:00
|
|
|
* Runs a BuildTask
|
2016-11-29 00:31:16 +01:00
|
|
|
* @param HTTPRequest $request
|
|
|
|
*/
|
|
|
|
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) {
|
2016-12-15 13:20:29 +01:00
|
|
|
/** @var BuildTask $inst */
|
2016-11-29 00:31:16 +01:00
|
|
|
$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()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
$availableTasks = [];
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-09-19 06:55:39 +02:00
|
|
|
$taskClasses = ClassInfo::subclassesFor(BuildTask::class);
|
2016-11-29 00:31:16 +01:00
|
|
|
// remove the base class
|
|
|
|
array_shift($taskClasses);
|
|
|
|
|
|
|
|
foreach ($taskClasses as $class) {
|
|
|
|
if (!$this->taskEnabled($class)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$singleton = BuildTask::singleton($class);
|
2020-08-26 01:11:13 +02:00
|
|
|
$description = $singleton->getDescription();
|
|
|
|
$description = trim($description);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
|
|
|
$desc = (Director::is_cli())
|
2020-08-26 01:11:13 +02:00
|
|
|
? Convert::html2raw($description)
|
|
|
|
: $description;
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
$availableTasks[] = [
|
2016-11-29 00:31:16 +01:00
|
|
|
'class' => $class,
|
|
|
|
'title' => $singleton->getTitle(),
|
|
|
|
'segment' => $singleton->config()->segment ?: str_replace('\\', '-', $class),
|
|
|
|
'description' => $desc,
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $availableTasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $class
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
protected function taskEnabled($class)
|
|
|
|
{
|
|
|
|
$reflectionClass = new ReflectionClass($class);
|
|
|
|
if ($reflectionClass->isAbstract()) {
|
|
|
|
return false;
|
|
|
|
} elseif (!singleton($class)->isEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-26 01:11:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inject task runner CSS into the heaader
|
|
|
|
|
|
|
|
* @param string $header
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function addCssToHeader($header)
|
|
|
|
{
|
|
|
|
$css = (array) $this->config()->get('css');
|
|
|
|
|
|
|
|
if (!$css) {
|
|
|
|
return $header;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($css as $include) {
|
|
|
|
$path = ModuleResourceLoader::singleton()->resolveURL($include);
|
|
|
|
|
|
|
|
// inject CSS into the heaader
|
|
|
|
$element = sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $path);
|
|
|
|
$header = str_replace('</head>', $element . '</head>', $header);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $header;
|
|
|
|
}
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
}
|