Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit d2cb217e20d44d7928a0910ac0375740de163bb3 1 parent c803cb2
Bharat Mediratta bharat authored
6 modules/exif/helpers/exif.php
View
@@ -139,7 +139,7 @@ private static function _keys() {
}
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 @@ static function stats() {
->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);
}
9 modules/exif/helpers/exif_task.php
View
@@ -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()
22 modules/gallery/controllers/admin_maintenance.php
View
@@ -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 @@ public function cancel($task_id) {
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");
}
4 modules/gallery/helpers/gallery_task.php
View
@@ -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 @@ static function available_tasks() {
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") {
33 modules/gallery/helpers/graphics.php
View
@@ -197,11 +197,22 @@ private static function _get_rules($target) {
* @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 @@ static function find_dirty_images_query() {
*/
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>",
46 modules/gallery/libraries/drivers/Cache/Database.php
View
@@ -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 @@ public function set($items, $tags=null, $lifetime=null) {
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 @@ public function set($items, $tags=null, $lifetime=null) {
* @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 @@ public function get_tag($tags) {
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 @@ public function get($keys, $single=false) {
* @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 @@ public function delete_tag($tags) {
*/
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 @@ public function delete_expired() {
* Empty the cache
*/
public function delete_all() {
- db::build()->query("TRUNCATE {caches}")->execute();
+ Database::instance()->query("TRUNCATE {caches}");
}
}
4 modules/search/helpers/search.php
View
@@ -72,7 +72,7 @@ static function update($item) {
}
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 @@ static function stats() {
->where("search_records.item_id", "=", null)
->or_where("search_records.dirty", "=", 1)
->close()
- ->get()
+ ->execute()
->count();
$total = ORM::factory("item")->count_all();
8 modules/search/helpers/search_task.php
View
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.