summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin_maintenance.php22
-rw-r--r--modules/gallery/helpers/gallery_task.php4
-rw-r--r--modules/gallery/helpers/graphics.php33
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php46
4 files changed, 63 insertions, 42 deletions
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