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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2016-06-23 01:37:22 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Security;
|
2016-08-19 00:51:35 +02:00
|
|
|
use ReflectionClass;
|
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
class TaskRunner extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
private static $url_handlers = array(
|
|
|
|
'' => 'index',
|
|
|
|
'$TaskName' => 'runTask'
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'index',
|
|
|
|
'runTask',
|
|
|
|
);
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
$tasks = $this->getTasks();
|
|
|
|
|
|
|
|
// Web mode
|
|
|
|
if (!Director::is_cli()) {
|
|
|
|
$renderer = new DebugView();
|
|
|
|
echo $renderer->renderHeader();
|
|
|
|
echo $renderer->renderInfo("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>";
|
|
|
|
|
|
|
|
echo $renderer->renderFooter();
|
|
|
|
// CLI mode
|
|
|
|
} else {
|
|
|
|
echo "SILVERSTRIPE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
|
|
|
|
foreach ($tasks as $task) {
|
|
|
|
echo " * $task[title]: sake dev/tasks/" . $task['segment'] . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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()
|
|
|
|
{
|
|
|
|
$availableTasks = array();
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$desc = (Director::is_cli())
|
|
|
|
? Convert::html2raw($singleton->getDescription())
|
|
|
|
: $singleton->getDescription();
|
|
|
|
|
|
|
|
$availableTasks[] = array(
|
|
|
|
'class' => $class,
|
|
|
|
'title' => $singleton->getTitle(),
|
|
|
|
'segment' => $singleton->config()->segment ?: str_replace('\\', '-', $class),
|
|
|
|
'description' => $desc,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
}
|