callback("rescue_task::fix_internet_addresses") ->name(t("Fix internet addresses")) ->description(t("Fix internet addresses broken when upgrading to Beta 3")) ->severity(log::SUCCESS), ); } static function fix_internet_addresses($task) { $start = microtime(true); $total = $task->get("total"); if (empty($total)) { $task->set("total", $total = db::build()->count_records("items")); $task->set("last_id", 0); $task->set("completed", 0); } $last_id = $task->get("last_id"); $completed = $task->get("completed"); foreach (ORM::factory("item") ->where("id", ">", $last_id) ->find_all(100) as $item) { $item->slug = item::convert_filename_to_slug($item->slug); $item->save(); $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; db::build() ->update("items") ->set("relative_path_cache", null) ->set("relative_url_cache", null) ->execute(); } else { $task->percent_complete = round(100 * $completed / $total); } $task->status = t2("One row updated", "%count / %total rows updated", $completed, array("total" => $total)); } }