summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/gallery_task.php
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-07-08 08:22:40 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-07-08 08:22:40 -0700
commit47fbb56fa25fc98d4e0695ed08b7fbaec916c003 (patch)
tree6fbade23e908e16c452132f33a44e205ef9e2b73 /modules/gallery/helpers/gallery_task.php
parent2852161ca31f1a5b90bfd16a14615dd1812bd78a (diff)
Added task logging to the Rebuild Images task.
Diffstat (limited to 'modules/gallery/helpers/gallery_task.php')
-rw-r--r--modules/gallery/helpers/gallery_task.php83
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());
}
}