From 5342578e6d24c59db74747024e1bdc5bcf41ae2d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 10 Mar 2009 13:53:59 +0000 Subject: Minor change to the task api with the addition of two optional parameters. The first allows the specification of a task name. Non-maintenance tasks are not defined as part of availabl_tasks so we can't get the name from the task definitions. The 2nd allows the specification of a context when the task is completed. --- core/helpers/task.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'core/helpers/task.php') diff --git a/core/helpers/task.php b/core/helpers/task.php index d9eeecfa..75151796 100644 --- a/core/helpers/task.php +++ b/core/helpers/task.php @@ -35,17 +35,23 @@ class task_Core { return $tasks; } - static function create($task_callback) { - $task_definitions = self::get_definitions(); - + static function create($task_callback, $task_name=null, $context=array()) { $task = ORM::factory("task"); $task->callback = $task_callback; - $task->name = $task_definitions[$task_callback]->name; + 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->percent_complete = 0; $task->status = ""; $task->state = "started"; $task->owner_id = user::active()->id; - $task->context = serialize(array()); + $task->context = serialize($context); $task->save(); return $task; -- cgit v1.2.3