diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-08 08:22:40 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-08 08:22:40 -0700 |
commit | 47fbb56fa25fc98d4e0695ed08b7fbaec916c003 (patch) | |
tree | 6fbade23e908e16c452132f33a44e205ef9e2b73 | |
parent | 2852161ca31f1a5b90bfd16a14615dd1812bd78a (diff) |
Added task logging to the Rebuild Images task.
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 1152cda2..c673411d 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -45,50 +45,63 @@ class gallery_task_Core { * @param Task_Model the task */ static function rebuild_dirty_images($task) { - $result = graphics::find_dirty_images_query(); - $completed = $task->get("completed", 0); - $ignored = $task->get("ignored", array()); - $remaining = $result->count() - count($ignored); - - $i = 0; - foreach ($result as $row) { - if (array_key_exists($row->id, $ignored)) { - continue; - } + try { + $result = graphics::find_dirty_images_query(); + $completed = $task->get("completed", 0); + $ignored = $task->get("ignored", array()); + $remaining = $result->count() - count($ignored); + + $i = 0; + foreach ($result as $row) { + if (array_key_exists($row->id, $ignored)) { + continue; + } - $item = ORM::factory("item", $row->id); - if ($item->loaded) { - $success = graphics::generate($item); - if (!$success) { - $ignored[$item->id] = 1; + $item = ORM::factory("item", $row->id); + if ($item->loaded) { + $success = graphics::generate($item); + if (!$success) { + $ignored[$item->id] = 1; + $message = t("Unable to rebuild images for '%title'", + array("title" => p::purify($item->title))); + } else { + $message = t("Successfully rebuilt images for '%title'", + array("title" => p::purify($item->title))); + } + $task->log($message); } - } - $completed++; - $remaining--; + $completed++; + $remaining--; - if (++$i == 2) { - break; + if (++$i == 2) { + break; + } } - } - $task->status = t2("Updated: 1 image. Total: %total_count.", - "Updated: %count images. Total: %total_count.", - $completed, - array("total_count" => ($remaining + $completed))); + $task->status = t2("Updated: 1 image. Total: %total_count.", + "Updated: %count images. Total: %total_count.", + $completed, + array("total_count" => ($remaining + $completed))); - if ($completed + $remaining > 0) { - $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); - } else { - $task->percent_complete = 100; - } + if ($completed + $remaining > 0) { + $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + } else { + $task->percent_complete = 100; + } - $task->set("completed", $completed); - $task->set("ignored", $ignored); - if ($remaining == 0) { + $task->set("completed", $completed); + $task->set("ignored", $ignored); + if ($remaining == 0) { + $task->done = true; + $task->state = "success"; + site_status::clear("graphics_dirty"); + } + } catch (Exception $e) { $task->done = true; - $task->state = "success"; - site_status::clear("graphics_dirty"); + $task->state = "error"; + $task->status = $e->getMessage(); + $task->log($e->__toString()); } } |