mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Support running namespaced build tasks.
This commit is contained in:
parent
d4b7763cab
commit
889e39cf55
@ -43,7 +43,7 @@ class TaskRunner extends Controller {
|
|||||||
echo "<ul>";
|
echo "<ul>";
|
||||||
foreach($tasks as $task) {
|
foreach($tasks as $task) {
|
||||||
echo "<li><p>";
|
echo "<li><p>";
|
||||||
echo "<a href=\"{$base}dev/tasks/" . $task['class'] . "\">" . $task['title'] . "</a><br />";
|
echo "<a href=\"{$base}dev/tasks/" . $task['segment'] . "\">" . $task['title'] . "</a><br />";
|
||||||
echo "<span class=\"description\">" . $task['description'] . "</span>";
|
echo "<span class=\"description\">" . $task['description'] . "</span>";
|
||||||
echo "</p></li>\n";
|
echo "</p></li>\n";
|
||||||
}
|
}
|
||||||
@ -54,26 +54,39 @@ class TaskRunner extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
echo "SILVERSTRIPE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
|
echo "SILVERSTRIPE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
|
||||||
foreach($tasks as $task) {
|
foreach($tasks as $task) {
|
||||||
echo " * $task[title]: sake dev/tasks/" . $task['class'] . "\n";
|
echo " * $task[title]: sake dev/tasks/" . $task['segment'] . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runTask($request) {
|
public function runTask($request) {
|
||||||
$taskName = $request->param('TaskName');
|
$name = $request->param('TaskName');
|
||||||
if (class_exists($taskName) && is_subclass_of($taskName, 'BuildTask')) {
|
$tasks = $this->getTasks();
|
||||||
$title = singleton($taskName)->getTitle();
|
|
||||||
if(Director::is_cli()) echo "Running task '$title'...\n\n";
|
|
||||||
elseif(!Director::is_ajax()) echo "<h1>Running task '$title'...</h1>\n";
|
|
||||||
|
|
||||||
$task = Injector::inst()->create($taskName);
|
$title = function ($content) {
|
||||||
if ($task->isEnabled()) $task->run($request);
|
printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
|
||||||
else echo "<p>{$title} is disabled</p>";
|
};
|
||||||
} else {
|
|
||||||
echo "Build task '$taskName' not found.";
|
$message = function ($content) {
|
||||||
if(class_exists($taskName)) echo " It isn't a subclass of BuildTask.";
|
printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
|
||||||
echo "\n";
|
};
|
||||||
|
|
||||||
|
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', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,6 +108,7 @@ class TaskRunner extends Controller {
|
|||||||
$availableTasks[] = array(
|
$availableTasks[] = array(
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
'title' => singleton($class)->getTitle(),
|
'title' => singleton($class)->getTitle(),
|
||||||
|
'segment' => str_replace('\\', '-', $class),
|
||||||
'description' => $desc,
|
'description' => $desc,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user