static function item_created($item) { // Whenever a new non-album item is created, check it for GPS coordinates. if (!$item->is_album()) { exif_gps::extract($item); } }
static function update_gps_index($task) { $start = microtime(true); // Figure out the total number of photos in the database. // If this is the first run, also set last_id and completed to 0. $total = $task->get("total"); if (empty($total)) { $task->set("total", $total = count(ORM::factory("item")->where("type", "=", "photo")->find_all())); $task->set("last_id", 0); $task->set("completed", 0); } $last_id = $task->get("last_id"); $completed = $task->get("completed"); // Generate an array of the next 100 photos to check. $all_photos = ORM::factory("item")->where("id", ">", $last_id)->where("type", "=", "photo")->find_all(100); // Check each photo in the array to see if it already has exif gps data associated with it. // If it doesn't, attempt to extract gps coordinates. foreach (ORM::factory("item")->where("id", ">", $last_id)->where("type", "=", "photo")->find_all(100) as $item) { $record = ORM::factory("exif_coordinate")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { exif_gps::extract($item); } $last_id = $item->id; $completed++; if ($completed == $total || microtime(true) - $start > 1.5) { break; } } $task->set("completed", $completed); $task->set("last_id", $last_id); if ($total == $completed) { $task->done = true; $task->state = "success"; $task->percent_complete = 100; } else { $task->percent_complete = round(100 * $completed / $total); } $task->status = t2("One photo scanned", "%count / %total photos scanned", $completed, array("total" => $total)); }