diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-12-02 00:34:34 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-12-02 00:34:34 -0800 |
commit | d2cb217e20d44d7928a0910ac0375740de163bb3 (patch) | |
tree | 8b7a45adb4457cbd7ed291b8151cf330a13fbf10 /modules | |
parent | c803cb29091d3b069077d7711a2485f75f274835 (diff) |
Convert more database calls over to the new format
- admin/maintenance page loads, the rebuild thumbs/resizes task works
- Fixed up some conversion bugs in the Cache driver
Diffstat (limited to 'modules')
-rw-r--r-- | modules/exif/helpers/exif.php | 6 | ||||
-rw-r--r-- | modules/exif/helpers/exif_task.php | 9 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_maintenance.php | 22 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/graphics.php | 33 | ||||
-rw-r--r-- | modules/gallery/libraries/drivers/Cache/Database.php | 46 | ||||
-rw-r--r-- | modules/search/helpers/search.php | 4 | ||||
-rw-r--r-- | modules/search/helpers/search_task.php | 8 |
8 files changed, 77 insertions, 55 deletions
diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index d3a8c103..3177e7eb 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -139,7 +139,7 @@ class exif_Core { } static function stats() { - $missing_exif = Database::instance() + $missing_exif = db::build() ->select("items.id") ->from("items") ->join("exif_records", "items.id", "exif_records.item_id", "left") @@ -148,10 +148,10 @@ class exif_Core { ->where("exif_records.item_id", "=", null) ->or_where("exif_records.dirty", "=", 1) ->close() - ->get() + ->execute() ->count(); - $total_items = ORM::factory("item")->where("type", "photo")->count_all(); + $total_items = ORM::factory("item")->where("type", "=", "photo")->count_all(); if (!$total_items) { return array(0, 0, 0); } diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index 66f69790..e25e2405 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -20,10 +20,11 @@ class exif_task_Core { static function available_tasks() { // Delete extra exif_records - Database::instance()->query( - "DELETE FROM {exif_records} " . - "WHERE {exif_records}.`item_id` NOT IN " . - "(SELECT `id` FROM {items} WHERE {items}.`type` = 'photo')"); + db::build() + ->delete("exif_records") + ->where("item_id", "NOT IN", + db::build()->select("id")->from("items")->where("type", "=", "photo")) + ->execute(); list ($remaining, $total, $percent) = exif::stats(); return array(Task_Definition::factory() diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 6377f40f..213e4fe2 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -22,11 +22,13 @@ class Admin_Maintenance_Controller extends Admin_Controller { * Show a list of all available, running and finished tasks. */ public function index() { - $query = Database::instance()->query( - "UPDATE {tasks} SET `state` = 'stalled' " . - "WHERE done = 0 " . - "AND state <> 'stalled' " . - "AND unix_timestamp(now()) - updated > 15"); + $query = db::build() + ->update("tasks") + ->set("state", "stalled") + ->where("done", "=", 0) + ->where("state", "<>", "stalled") + ->where(new Database_Expression("UNIX_TIMESTAMP(NOW()) - `updated` > 15")) + ->execute(); $stalled_count = $query->count(); if ($stalled_count) { log::warning("tasks", @@ -138,10 +140,12 @@ class Admin_Maintenance_Controller extends Admin_Controller { public function cancel_running_tasks() { access::verify_csrf(); - Database::instance()->update( - "tasks", - array("done" => 1, "state" => "cancelled"), - array("done" => 0)); + db::build() + ->update("tasks") + ->set("done", 1) + ->set("state", "cancelled") + ->where("done", "=", 0) + ->execute(); message::success(t("All running tasks cancelled")); url::redirect("admin/maintenance"); } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 4d6de3ba..3a705027 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -19,7 +19,7 @@ */ class gallery_task_Core { static function available_tasks() { - $dirty_count = graphics::find_dirty_images_query()->count(); + $dirty_count = graphics::find_dirty_images_query()->count_records(); $tasks = array(); $tasks[] = Task_Definition::factory() ->callback("gallery_task::rebuild_dirty_images") @@ -47,7 +47,7 @@ class gallery_task_Core { static function rebuild_dirty_images($task) { $errors = array(); try { - $result = graphics::find_dirty_images_query(); + $result = graphics::find_dirty_images_query()->select("id")->execute(); $total_count = $task->get("total_count", $result->count()); $mode = $task->get("mode", "init"); if ($mode == "init") { diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index c93cc304..6fab0b54 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -197,11 +197,22 @@ class graphics_Core { * @return Database_Result Query result */ static function find_dirty_images_query() { - return Database::instance()->query( - "SELECT `id` FROM {items} " . - "WHERE ((`thumb_dirty` = 1 AND (`type` <> 'album' OR `album_cover_item_id` IS NOT NULL))" . - " OR (`resize_dirty` = 1 AND `type` = 'photo')) " . - " AND `id` != 1"); + return db::build() + ->from("items") + ->and_open() + ->and_open() + ->where("thumb_dirty", "=", 1) + ->and_open() + ->where("type", "<>", "album") + ->or_where("album_cover_item_id", "IS NOT", null) + ->close() + ->or_open() + ->where("resize_dirty", "=", 1) + ->where("type", "=", "photo") + ->close() + ->close() + ->where("id", "<>", 1) + ->close(); } /** @@ -209,18 +220,18 @@ class graphics_Core { */ static function mark_dirty($thumbs, $resizes) { if ($thumbs || $resizes) { - $db = Database::instance(); - $fields = array(); + $db = db::build() + ->update("items"); if ($thumbs) { - $fields["thumb_dirty"] = 1; + $db->set("thumb_dirty", 1); } if ($resizes) { - $fields["resize_dirty"] = 1; + $db->set("resize_dirty", 1); } - $db->update("items", $fields, true); + $db->execute(); } - $count = self::find_dirty_images_query()->count(); + $count = self::find_dirty_images_query()->count_records(); if ($count) { site_status::warning( t2("One of your photos is out of date. <a %attrs>Click here to fix it</a>", diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php index a317798e..5fa2a72a 100644 --- a/modules/gallery/libraries/drivers/Cache/Database.php +++ b/modules/gallery/libraries/drivers/Cache/Database.php @@ -33,7 +33,7 @@ class Cache_Database_Driver extends Cache_Driver { public function exists($id) { $count = db::build() ->where("key", "=", $id) - ->where("expiration", ">=", "time()") + ->where("expiration", ">=", time()) ->count_records("caches"); return $count > 0; } @@ -61,16 +61,18 @@ class Cache_Database_Driver extends Cache_Driver { foreach ($items as $id => $data) { if ($this->exists($id)) { - $status = db::build()->update( - "caches", - array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), - array("key", "=", $id)) + $status = db::build() + ->update("caches") + ->set("tags", $tags) + ->set("expiration", $lifetime) + ->set("cache", serialize($data)) + ->where("key", "=", $id) ->execute(); } else { - $status = db::build()->insert( - "caches", - array("key" => $id, "tags" => $tags, - "expiration" => $lifetime, "cache" => serialize($data))) + $status = db::build() + ->insert("caches") + ->columns("key", "tags", "expiration", "cache") + ->values($id, $tags, $lifetime, serialize($data)) ->execute(); } } @@ -84,11 +86,13 @@ class Cache_Database_Driver extends Cache_Driver { * @return array cached data */ public function get_tag($tags) { - $db = db::build()->from("caches"); + $db = db::build() + ->select("*") + ->from("caches"); foreach ($tags as $tag) { $db->where("tags", "LIKE", "<$tag>"); } - $db_result = $db->execute()->as_array(); + $db_result = $db->execute(); // An array will always be returned $result = array(); @@ -116,9 +120,9 @@ class Cache_Database_Driver extends Cache_Driver { public function get($keys, $single=false) { $data = null; $result = db::build() + ->select("*") ->from("caches") ->where("key", "IN", $keys) - ->select() ->execute(); if (count($result) > 0) { @@ -150,17 +154,18 @@ class Cache_Database_Driver extends Cache_Driver { * @return bool */ public function delete($id, $tag = false) { - $this->db->from("caches"); + $db = db::build() + ->delete("caches"); if ($id === true) { // Delete all caches - $this->db->where("1", "=", "1"); + $db->where("1", "=", "1"); } else if ($tag === true) { - $this->db->like("tags", "<$id>"); + $db->where("tags", "LIKE", "<$id>"); } else { - $this->db->where("key", "=", $id); + $db->where("key", "=", $id); } - $status = $this->db->delete(); + $status = $db->execute(); return count($status) > 0; } @@ -177,10 +182,11 @@ class Cache_Database_Driver extends Cache_Driver { */ public function delete_expired() { // Delete all expired caches - $status = $this->db->from("caches") + $status = db::build() + ->delete("caches") ->where("expiration", "<>", 0) ->where("expiration", "<=", time()) - ->delete(); + ->execute(); return count($status) > 0; } @@ -189,6 +195,6 @@ class Cache_Database_Driver extends Cache_Driver { * Empty the cache */ public function delete_all() { - db::build()->query("TRUNCATE {caches}")->execute(); + Database::instance()->query("TRUNCATE {caches}"); } }
\ No newline at end of file diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 1fd5175f..9123df09 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -72,7 +72,7 @@ class search_Core { } static function stats() { - $remaining = Database::instance() + $remaining = db::build() ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") @@ -80,7 +80,7 @@ class search_Core { ->where("search_records.item_id", "=", null) ->or_where("search_records.dirty", "=", 1) ->close() - ->get() + ->execute() ->count(); $total = ORM::factory("item")->count_all(); diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 6b35cabc..6aa4a0d1 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -20,10 +20,10 @@ class search_task_Core { static function available_tasks() { // Delete extra search_records - Database::instance()->query( - "DELETE FROM {search_records} " . - "WHERE {search_records}.`item_id` NOT IN " . - "(SELECT `id` FROM {items})"); + db::build() + ->delete("search_records") + ->where("item_id", "NOT IN", db::build()->select("id")->from("items")) + ->execute(); list ($remaining, $total, $percent) = search::stats(); return array(Task_Definition::factory() |