delete("iptc_records") ->where("item_id", "NOT IN", db::build()->select("id")->from("items")->where("type", "=", "photo")) ->execute(); list ($remaining, $total, $percent) = iptc::stats(); return array(Task_Definition::factory() ->callback("iptc_task::update_index") ->name(t("Extract Iptc data")) ->description($remaining ? t2("1 photo needs to be scanned", "%count (%percent%) of your photos need to be scanned", $remaining, array("percent" => (100 - $percent))) : t("IPTC data is up-to-date")) ->severity($remaining ? log::WARNING : log::SUCCESS)); } static function update_index($task) { try { $completed = $task->get("completed", 0); $start = microtime(true); foreach (ORM::factory("item") ->join("iptc_records", "items.id", "iptc_records.item_id", "left") ->where("type", "=", "photo") ->and_open() ->where("iptc_records.item_id", "IS", null) ->or_where("iptc_records.dirty", "=", 1) ->close() ->find_all() as $item) { // The query above can take a long time, so start the timer after its done // to give ourselves a little time to actually process rows. if (!isset($start)) { $start = microtime(true); } iptc::extract($item); $completed++; if (microtime(true) - $start > 1.5) { break; } } list ($remaining, $total, $percent) = iptc::stats(); $task->set("completed", $completed); if ($remaining == 0 || !($remaining + $completed)) { $task->done = true; $task->state = "success"; site_status::clear("iptc_index_out_of_date"); $task->percent_complete = 100; } else { $task->percent_complete = round(100 * $completed / ($remaining + $completed)); } $task->status = t2("one record updated, index is %percent% up-to-date", "%count records updated, index is %percent% up-to-date", $completed, array("percent" => $percent)); } catch (Exception $e) { $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); $task->log((string)$e); } } }