summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/data_rest.php8
-rw-r--r--modules/gallery/helpers/gallery_installer.php10
-rw-r--r--modules/gallery/helpers/gallery_task.php56
-rw-r--r--modules/gallery/helpers/items_rest.php2
4 files changed, 65 insertions, 11 deletions
diff --git a/modules/gallery/helpers/data_rest.php b/modules/gallery/helpers/data_rest.php
index 3cd2f59a..98c98894 100644
--- a/modules/gallery/helpers/data_rest.php
+++ b/modules/gallery/helpers/data_rest.php
@@ -57,9 +57,17 @@ class data_rest_Core {
// We don't need to save the session for this request
Session::instance()->abort_save();
+ if ($item->is_album() && !$item->album_cover_item_id) {
+ // No thumbnail. Return nothing.
+ // @todo: what should we do here?
+ return;
+ }
+
// Dump out the image. If the item is a movie, then its thumbnail will be a JPG.
if ($item->is_movie() && $p->size == "thumb") {
header("Content-Type: image/jpeg");
+ } else if ($item->is_album()) {
+ header("Content-Type: " . $item->album_cover()->mime_type);
} else {
header("Content-Type: {$item->mime_type}");
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 21c47ad5..569c5118 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -23,7 +23,8 @@ class gallery_installer {
$db->query("CREATE TABLE {access_caches} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
- PRIMARY KEY (`id`))
+ PRIMARY KEY (`id`),
+ KEY (`item_id`))
DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {access_intents} (
@@ -299,7 +300,7 @@ class gallery_installer {
module::set_var("gallery", "simultaneous_upload_limit", 5);
module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_var("gallery", "maintenance_mode", 0);
- module::set_version("gallery", 33);
+ module::set_version("gallery", 34);
}
static function upgrade($version) {
@@ -578,6 +579,11 @@ class gallery_installer {
$db->query("ALTER TABLE {items} ADD KEY (`left_ptr`)");
module::set_version("gallery", $version = 33);
}
+
+ if ($version == 33) {
+ $db->query("ALTER TABLE {access_caches} ADD KEY (`item_id`)");
+ module::set_version("gallery", $version = 34);
+ }
}
static function uninstall() {
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index bf1355b8..6a1fc28a 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -26,7 +26,9 @@ class gallery_task_Core {
const FIX_STATE_RUN_DUPE_SLUGS = 5;
const FIX_STATE_START_DUPE_NAMES = 6;
const FIX_STATE_RUN_DUPE_NAMES = 7;
- const FIX_STATE_DONE = 8;
+ const FIX_STATE_START_MISSING_ACCESS_CACHES = 8;
+ const FIX_STATE_RUN_MISSING_ACCESS_CACHES = 9;
+ const FIX_STATE_DONE = 10;
static function available_tasks() {
$dirty_count = graphics::find_dirty_images_query()->count_records();
@@ -323,15 +325,14 @@ class gallery_task_Core {
$total = $task->get("total");
if (empty($total)) {
// mptt: 2 operations for every item
- // album audit (permissions and bogus album covers): 1 operation for every album
- // dupe slugs: 1 operation for each unique conflicted slug
$total = 2 * db::build()->count_records("items");
+ // album audit (permissions and bogus album covers): 1 operation for every album
$total += db::build()->where("type", "=", "album")->count_records("items");
- foreach (self::find_dupe_slugs() as $row) {
- $total++;
- }
- foreach (self::find_dupe_names() as $row) {
- $total++;
+ // one operation for each missing slug, name and access cache
+ foreach (array("find_dupe_slugs", "find_dupe_names", "find_missing_access_caches") as $func) {
+ foreach (self::$func() as $row) {
+ $total++;
+ }
}
$task->set("total", $total);
@@ -542,6 +543,36 @@ class gallery_task_Core {
$completed++;
if (empty($stack)) {
+ $state = self::FIX_STATE_START_MISSING_ACCESS_CACHES;
+ }
+ break;
+
+ case self::FIX_STATE_START_MISSING_ACCESS_CACHES:
+ $stack = array();
+ foreach (self::find_missing_access_caches() as $row) {
+ $stack[] = $row->id;
+ }
+ if ($stack) {
+ $task->set("stack", implode(" ", $stack));
+ $state = self::FIX_STATE_RUN_MISSING_ACCESS_CACHES;
+ } else {
+ $state = self::FIX_STATE_DONE;
+ }
+ break;
+
+ case self::FIX_STATE_RUN_MISSING_ACCESS_CACHES:
+ $stack = explode(" ", $task->get("stack"));
+ $id = array_pop($stack);
+ $access_cache = ORM::factory("access_cache");
+ $access_cache->item_id = $id;
+ $access_cache->save();
+ $task->set("stack", implode(" ", $stack));
+ $completed++;
+ if (empty($stack)) {
+ // The new cache rows are there, but they're incorrectly populated so we have to fix
+ // them. If this turns out to be too slow, we'll have to refactor
+ // access::recalculate_permissions to allow us to do it in slices.
+ access::recalculate_permissions(item::root());
$state = self::FIX_STATE_DONE;
}
break;
@@ -587,4 +618,13 @@ class gallery_task_Core {
->group_by("parent_name")
->execute();
}
+
+ static function find_missing_access_caches() {
+ return db::build()
+ ->select("items.id")
+ ->from("items")
+ ->join("access_caches", "items.id", "access_caches.item_id", "left")
+ ->where("access_caches.id", "is", null)
+ ->execute();
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php
index 9cca9a54..f0b68d63 100644
--- a/modules/gallery/helpers/items_rest.php
+++ b/modules/gallery/helpers/items_rest.php
@@ -80,7 +80,7 @@ class items_rest_Core {
"relationships" => rest::relationships("item", $item));
if ($item->type == "album") {
$members = array();
- foreach ($item->children() as $child) {
+ foreach ($item->viewable()->children() as $child) {
$members[] = rest::url("item", $child);
}
$item_rest["members"] = $members;