Ejemplo n.º 1
0
 /**
  * @param Task_Model the task
  */
 static function date_tag_all($task)
 {
     $errors = array();
     try {
         $start = microtime(true);
         $last_item_id = $task->get("last_item_id", null);
         $current = 0;
         $total = 0;
         switch ($task->get("mode", "init")) {
             case "init":
                 $task->set("total", ORM::factory("item")->where("type", "=", "photo")->count_all());
                 $task->set("mode", "date_tag_all");
                 $task->set("completed", 0);
                 $task->set("last_item_id", 0);
             case "date_tag_all":
                 $completed = $task->get("completed");
                 $total = $task->get("total");
                 $last_item_id = $task->get("last_item_id");
                 $items = ORM::factory("item")->where("id", ">", $last_item_id)->and_where("type", "=", "photo")->find_all(5);
                 /* TODO: should we fetch more at a time? Less? */
                 while ($current < $total && microtime(true) - $start < 1 && ($item = $items->current())) {
                     $last_tem_id = $item->id;
                     $task->log("Looking at item {$item->name} (id: {$item->id})");
                     date_tag::tag_item($item);
                     $completed++;
                     $items->next();
                     $task->percent_complete = $completed / $total * 100;
                     $task->set("completed", $completed);
                     $task->set("last_item_id", $item->id);
                     $task->status = t2("Examined %count items", "Examined %count items", $completed);
                     if ($completed == $total) {
                         $task->done = true;
                         $task->state = "success";
                         $task->percent_complete = 100;
                     }
                 }
         }
     } catch (Exception $e) {
         Kohana_Log::add("error", (string) $e);
         $task->done = true;
         $task->state = "error";
         $task->status = $e->getMessage();
         $errors[] = (string) $e;
     }
     if ($errors) {
         $task->log($errors);
     }
 }
Ejemplo n.º 2
0
 static function item_related_update($item)
 {
     date_tag::tag_item($item);
 }