From cd240ebaada9ddff112a40a5f80201f23449337e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 24 Sep 2009 20:06:14 -0700 Subject: Refactored the rebuild_dirty_images handler to simplify the counting and end processing. It was getting all confused with trying to figure out the completed and remaining. Now on initiation it sets the total images that are dirty and then counts the completed until it equals the total, then exits. Fixes ticket #771 --- modules/gallery/helpers/gallery_task.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 1b56ab97..3d0476a8 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -48,9 +48,13 @@ class gallery_task_Core { $errors = array(); try { $result = graphics::find_dirty_images_query(); + $total_count = $task->get("total_count", -1); + if ($total_count < 0) { + $total_count = $result->count(); + $task->set("total_count", $total_count); + } $completed = $task->get("completed", 0); $ignored = $task->get("ignored", array()); - $remaining = $result->count() - count($ignored); $i = 0; foreach ($result as $row) { @@ -62,19 +66,18 @@ class gallery_task_Core { if ($item->loaded) { try { graphics::generate($item); - $ignored[$item->id] = 1; + $completed++; + $errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title))); } catch (Exception $e) { $errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title))); $errors[] = $e->__toString(); + $ignored[$item->id] = 1; } } - $completed++; - $remaining--; - if (++$i == 2) { break; } @@ -83,17 +86,17 @@ class gallery_task_Core { $task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, - array("total_count" => ($remaining + $completed))); + array("total_count" => $total_count)); - if ($completed + $remaining > 0) { - $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + 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); - if ($remaining == 0) { + if ($task->percent_complete == 100) { $task->done = true; $task->state = "success"; site_status::clear("graphics_dirty"); -- cgit v1.2.3 From ab5e680265dfe9c42bd4d6fb8d1d9fccd95eed7b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 27 Sep 2009 20:31:56 -0700 Subject: Clean up the task initialization for rebuild thumbs and resizes. --- modules/gallery/helpers/gallery_task.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3d0476a8..1ff26c35 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -48,11 +48,13 @@ class gallery_task_Core { $errors = array(); try { $result = graphics::find_dirty_images_query(); - $total_count = $task->get("total_count", -1); - if ($total_count < 0) { - $total_count = $result->count(); + $total_count = $task->get("total_count", $result->count()); + $mode = $task->get("mode", "init"); + if ($mode == "init") { $task->set("total_count", $total_count); + $task->get("mode", "process"); } + $completed = $task->get("completed", 0); $ignored = $task->get("ignored", array()); -- cgit v1.2.3 From ca372213373ac91c3099f049bbe9686eb9426acb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 26 Oct 2009 14:32:04 -0700 Subject: When rebuilding dirty images, start a batch on initialization and stop it when the task is complete. Fixes ticket #670 --- modules/gallery/helpers/gallery_task.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 1ff26c35..95216cf0 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -52,7 +52,8 @@ class gallery_task_Core { $mode = $task->get("mode", "init"); if ($mode == "init") { $task->set("total_count", $total_count); - $task->get("mode", "process"); + $task->set("mode", "process"); + batch::start(); } $completed = $task->get("completed", 0); @@ -101,6 +102,7 @@ class gallery_task_Core { if ($task->percent_complete == 100) { $task->done = true; $task->state = "success"; + batch::stop(); site_status::clear("graphics_dirty"); } } catch (Exception $e) { -- cgit v1.2.3