I want to add a new task to maintenance. I try this function:
static function my_task($task) {
$result=ORM::factory("item")->where('relative_path_cache', 'IS', NULL)->find_all();
$total_count = $task->get("total_count", $result->count());
$mode = $task->get("mode", "init");
if ($mode == "init") {
$task->set("total_count", $total_count);
$task->set("mode", "process");
batch::start();
}
$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());
foreach ($result as $item)
{
MY STUFF
$completed++;
$task->status = t2("One operation complete", "%count / %total operations complete", $completed, array("total_count" => $total));
if ($completed < $total_count) {
$task->percent_complete = (int)(100 * ($completed + count($ignored)) / $total_count);
} else {
$task->percent_complete = 100;
}
$task->set("completed", $completed);
$task->set("ignored", $ignored);
}
$task->done = true;
$task->state = "success";
batch::stop();
}
The task works (MY STUFF is done), but the status is not updated. What is wrong?
Thank you,
Lucian