mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Improved TaskRunner and BuildTask metadata and styling
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64446 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f1f76b22b7
commit
5b91ea9d0a
@ -11,12 +11,44 @@
|
||||
* @package sapphire
|
||||
* @subpackage dev
|
||||
*/
|
||||
abstract class BuildTask {
|
||||
abstract class BuildTask extends Object {
|
||||
|
||||
/**
|
||||
* @var bool $enabled If set to FALSE, keep it from showing in the list
|
||||
* and from being executable through URL or CLI.
|
||||
*/
|
||||
protected $enabled = true;
|
||||
|
||||
/**
|
||||
* @var string $title Shown in the overview on the {@link TaskRunner}
|
||||
* HTML or CLI interface. Should be short and concise, no HTML allowed.
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* @var string $description Describe the implications the task has,
|
||||
* and the changes it makes. Accepts HTML formatting.
|
||||
*/
|
||||
protected $description = 'No description available';
|
||||
|
||||
abstract function run($request);
|
||||
|
||||
public function isDisabled() {
|
||||
return (property_exists($this, 'Disabled')) ? true : false;
|
||||
public function isEnabled() {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ($this->title) ? $this->title : $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string HTML formatted description
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,11 @@
|
||||
* @package sapphire
|
||||
* @subpackage dev
|
||||
*/
|
||||
abstract class MigrationTask extends BuildTask {
|
||||
class MigrationTask extends BuildTask {
|
||||
|
||||
protected $title = "Database Migrations";
|
||||
|
||||
protected $description = "Provide atomic database changes (not implemented yet)";
|
||||
|
||||
function run($request) {
|
||||
if ($request->param('Direction') == 'down') {
|
||||
@ -17,9 +21,9 @@ abstract class MigrationTask extends BuildTask {
|
||||
}
|
||||
}
|
||||
|
||||
abstract function up();
|
||||
function up() {}
|
||||
|
||||
abstract function down();
|
||||
function down() {}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,35 +11,73 @@ class TaskRunner extends Controller {
|
||||
);
|
||||
|
||||
function index() {
|
||||
$tasks = ClassInfo::subclassesFor('BuildTask');
|
||||
if(Director::is_cli()) {
|
||||
echo "Tasks available:\n\n";
|
||||
foreach($tasks as $task) echo " * $task: sake dev/tasks/$task\n";
|
||||
} else {
|
||||
echo "<h1>Tasks available</h1>\n";
|
||||
$tasks = $this->getTasks();
|
||||
|
||||
// Web mode
|
||||
if(!Director::is_cli()) {
|
||||
$renderer = new DebugView();
|
||||
$renderer->writeHeader();
|
||||
$renderer->writeInfo("Sapphire Development Tools: Tasks", Director::absoluteBaseURL());
|
||||
$base = Director::baseURL();
|
||||
|
||||
echo "<ul>";
|
||||
foreach($tasks as $task) {
|
||||
echo "<li><a href=\"$task\">$task</a></li>\n";
|
||||
echo "<li>";
|
||||
echo "<a href=\"" . $task['class'] . "\">" . $task['title'] . "</a><br />";
|
||||
echo "<span class=\"description\">" . $task['description'] . "</span>";
|
||||
echo "</li>\n";
|
||||
}
|
||||
echo "</ul>";
|
||||
|
||||
$renderer->writeFooter();
|
||||
// CLI mode
|
||||
} else {
|
||||
echo "SAPPHIRE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
|
||||
foreach($tasks as $task) {
|
||||
echo " * $task: sake dev/tasks/" . $task['class'] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runTask($request) {
|
||||
$TaskName = $request->param('TaskName');
|
||||
if (class_exists($TaskName) && is_subclass_of($TaskName, 'BuildTask')) {
|
||||
if(Director::is_cli()) echo "Running task '$TaskName'...\n\n";
|
||||
else echo "<h1>Running task '$TaskName'...</h1>\n";
|
||||
$taskName = $request->param('TaskName');
|
||||
if (class_exists($taskName) && is_subclass_of($taskName, 'BuildTask')) {
|
||||
$title = singleton($taskName)->getTitle();
|
||||
if(Director::is_cli()) echo "Running task '$title'...\n\n";
|
||||
else echo "<h1>Running task '$title'...</h1>\n";
|
||||
|
||||
$task = new $TaskName();
|
||||
if (!$task->isDisabled()) $task->run($request);
|
||||
$task = new $taskName();
|
||||
if ($task->isEnabled()) $task->run($request);
|
||||
} else {
|
||||
echo "Build task '$TaskName' not found.";
|
||||
if(class_exists($TaskName)) echo " It isn't a subclass of BuildTask.";
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user