Refine the task api but removing the optional parameters on the

task::create method call
This commit is contained in:
Tim Almdal
2009-03-11 03:14:52 +00:00
parent 47756db856
commit 8da729cfa1
3 changed files with 12 additions and 16 deletions
+3 -1
View File
@@ -56,7 +56,9 @@ class Admin_Maintenance_Controller extends Admin_Controller {
public function start($task_callback) {
access::verify_csrf();
$task = task::create($task_callback);
$tasks = task::get_definitions();
$task = task::create($tasks[$task_callback], array());
$view = new View("admin_maintenance_task.html");
$view->csrf = access::csrf_token();
+3 -11
View File
@@ -35,18 +35,10 @@ class task_Core {
return $tasks;
}
static function create($task_callback, $task_name=null, $context=array()) {
static function create($task_definitions, $context) {
$task = ORM::factory("task");
$task->callback = $task_callback;
if (empty($task_name)) {
$task_definitions = self::get_definitions();
$task->name = $task_definitions[$task_callback]->name;
} else {
$task->name = $task_name;
}
if (empty($task->name)) {
$task_name = $task_callback;
}
$task->callback = $task_definitions->callback;
$task->name = $task_definitions->name;
$task->percent_complete = 0;
$task->status = "";
$task->state = "started";
@@ -82,10 +82,12 @@ class Server_Add_Controller extends Controller {
}
}
$task = task::create("server_add_task::add_from_server", t("Add from server"),
array("item_id" => $id,
"next" => 0,
"paths" => $files));
$task_def = Task_Definition::factory()
->callback("server_add_task::add_from_server")
->description(t("Add photos or movies from the local server"))
->name(t("Add from server"));
$task = task::create($task_def, array("item_id" => $id, "next" => 0, "paths" => $files));
batch::start();
print json_encode(array("result" => "started",
"url" => url::site("server_add/add_photo/{$task->id}?csrf=" .