summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/gallery_task.php
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
committerAndy Staudacher <andy.st@gmail.com>2009-11-15 19:44:47 -0800
commit0733dc37fda27a5ba35f9020edf3c66aa41a95a0 (patch)
tree6877946232f1b01b1c8709054c689f6658cef34f /modules/gallery/helpers/gallery_task.php
parent218493c50be9362d4abed6900a816308fee5d978 (diff)
parent9379308f91a476f790fb8d444536719535c584e4 (diff)
Merge commit 'upstream/master'
Conflicts: modules/gallery/tests/xss_data.txt
Diffstat (limited to 'modules/gallery/helpers/gallery_task.php')
-rw-r--r--modules/gallery/helpers/gallery_task.php25
1 files changed, 16 insertions, 9 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 1b56ab97..95216cf0 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -48,9 +48,16 @@ class gallery_task_Core {
$errors = array();
try {
$result = graphics::find_dirty_images_query();
+ $total_count = $task->get("total_count", $result->count());
+ $mode = $task->get("mode", "init");
+ if ($mode == "init") {
+ $task->set("total_count", $total_count);
+ $task->set("mode", "process");
+ batch::start();
+ }
+
$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());
- $remaining = $result->count() - count($ignored);
$i = 0;
foreach ($result as $row) {
@@ -62,19 +69,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,19 +89,20 @@ 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";
+ batch::stop();
site_status::clear("graphics_dirty");
}
} catch (Exception $e) {