summaryrefslogtreecommitdiff
path: root/core/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-28 10:12:41 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-28 10:12:41 +0000
commit74d4e7d50585db230cfe07464a1a4b662c04b409 (patch)
treee96d01ea10f6b1cdcd8744651149fcc8416b7570 /core/helpers
parentaff2af5e1f23d713255ab03820656fa936230550 (diff)
First round of a task framework. Tasks are job definitions stored in
the database. They're started with admin/maintenance/start/[task_name] which sends down some JS/HTML which regularly pings the task at admin/maintenance/start/[task_id] until its done. The UI is still very rough. It works, though!
Diffstat (limited to 'core/helpers')
-rw-r--r--core/helpers/core_installer.php14
-rw-r--r--core/helpers/core_menu.php2
-rw-r--r--core/helpers/graphics.php64
3 files changed, 71 insertions, 9 deletions
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index d3147a02..46eb24c6 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -67,11 +67,11 @@ class core_installer {
`parent_id` int(9) NOT NULL,
`resize_height` int(9) default NULL,
`resize_width` int(9) default NULL,
- `resize_dirty` BOOLEAN default 1,
+ `resize_dirty` boolean default 1,
`right` int(9) NOT NULL,
`thumb_height` int(9) default NULL,
`thumb_width` int(9) default NULL,
- `thumb_dirty` BOOLEAN default 1,
+ `thumb_dirty` boolean default 1,
`title` varchar(255) default NULL,
`type` varchar(32) NOT NULL,
`updated` int(9) default NULL,
@@ -127,6 +127,16 @@ class core_installer {
PRIMARY KEY (`session_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ $db->query("CREATE TABLE `tasks` (
+ `context` text NOT NULL,
+ `done` boolean DEFAULT 0,
+ `id` int(9) NOT NULL auto_increment,
+ `name` varchar(255) default NULL,
+ `percent_complete` int(9) default 0,
+ `status` varchar(255) default NULL,
+ PRIMARY KEY (`id`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+
$db->query("CREATE TABLE `vars` (
`id` int(9) NOT NULL auto_increment,
`module_name` varchar(255) NOT NULL,
diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php
index 0a28f21f..d6f7bc56 100644
--- a/core/helpers/core_menu.php
+++ b/core/helpers/core_menu.php
@@ -101,7 +101,7 @@ class core_menu_Core {
->append(Menu::factory("link")
->id("maintenance")
->label(_("Maintenance"))
- ->url("#"))
+ ->url(url::site("admin/maintenance")))
->append(Menu::factory("link")
->id("statistics")
->label(_("Statistics"))
diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php
index ee8e91ac..68aacaca 100644
--- a/core/helpers/graphics.php
+++ b/core/helpers/graphics.php
@@ -129,6 +129,17 @@ class graphics_Core {
}
/**
+ * Return a query result that locates all items with dirty images.
+ * @return Database_Result Query result
+ */
+ private static function _find_dirty_images_query() {
+ return Database::instance()->query(
+ "SELECT `id` FROM `items` " .
+ "WHERE (`thumb_dirty` = 1 AND (`type` <> 'album' OR `right` - `left` > 1))" .
+ " OR (`resize_dirty` = 1 AND `type` = 'photo')");
+ }
+
+ /**
* Mark all thumbnails and resizes as dirty. They will have to be rebuilt.
*
*/
@@ -136,16 +147,57 @@ class graphics_Core {
$db = Database::instance();
$db->query("UPDATE `items` SET `thumb_dirty` = 1, `resize_dirty` = 1");
- $count = $db->query("SELECT COUNT(*) AS C FROM `items` " .
- "WHERE `thumb_dirty` = 1 " .
- " OR (`resize_dirty` = 1 AND `type` = 'photo')")
- ->current()
- ->C;
+ $count = self::_find_dirty_images_query()->count();
if ($count) {
message::warning(
sprintf(_("%d of your photos are out of date. %sClick here to fix them%s"),
- $count, "<a href=\"#\">", "</a>"),
+ $count, "<a href=\"" .
+ url::site("admin/maintenance/start/rebuild_images") .
+ "\" class=\"gDialogLink\">", "</a>"),
"graphics_dirty");
}
}
+
+ /**
+ * Task that rebuilds all dirty images.
+ * @param Task_Model the task
+ */
+ public static function rebuild_dirty_images($task) {
+ $db = Database::instance();
+
+ $result = self::_find_dirty_images_query();
+ $remaining = $result->count();
+ $completed = $task->get("completed", 0);
+
+ $i = 0;
+ foreach ($result as $row) {
+ $item = ORM::factory("item", $row->id);
+ if ($item->loaded) {
+ self::generate($item);
+ }
+
+ $completed++;
+ $remaining--;
+
+ if ($i++ == 3) {
+ break;
+ }
+ }
+
+ $task->status = sprintf(
+ _("Updated %d out of %d images"), $completed, $remaining + $completed);
+
+ if ($completed + $remaining > 0) {
+ $task->percent_complete = (int)(100 * $completed / ($completed + $remaining));
+ } else {
+ $task->percent_complete = 100;
+ }
+
+ $task->set("completed", $completed);
+ $task->done = ($remaining == 0);
+
+ if ($task->done) {
+ message::clear_permanent("graphics_dirty");
+ }
+ }
}