summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2013-01-30 21:42:47 -0500
committerBharat Mediratta <bharat@menalto.com>2013-01-30 21:42:47 -0500
commit8d15e5cb2eed56bbd894ff5578d081deee8ca255 (patch)
treeb65c5eef6b6af858a8358d7924c8778acc2b769d /modules/gallery/helpers
parent71cf911649811666919d040e2fc319f485b99966 (diff)
Follow-in to cff1e76e8da2055f9faf7449222b43a686014b1c for #1978
Restrict which album cover ids we swap over to the hierarchy of the current album, otherwise we can wind up in sticky situations with hierarchical album cover chains. Eg, you have a hierarchy like this: root -> A1 -> A2 --> A3 -> P1 A4 -> P2 P1 is the album cover for its entire hierarchy. But then you swap A2's album cover for A3 making this: root -> A1 -> A2 + A3 -> P1 \-> A4 -> P2 Since A1, A2 and A3 all had P1 as their album cover item id. Now we're swapping it over to P2 but we want to leave P1 as A3's album cover item id. So only look at A4's hierarchy and ignore its peers.
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/item.php17
1 files changed, 8 insertions, 9 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 8d3b4354..975d46e5 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -92,16 +92,15 @@ class item_Core {
// When albums are album covers themselves, we hotlink directly to the target item. This
// means that when we change an album cover, the grandparent may have a deep link to the old
- // album cover. So find any albums that had the old item as their album cover and switch them
- // over to the new item.
+ // album cover. So find any parent albums that had the old item as their album cover and
+ // switch them over to the new item.
if ($old_album_cover_id) {
- foreach (ORM::factory("item")
- ->where("album_cover_item_id", "=", $old_album_cover_id)
- ->find_all() as $other_album) {
- if (access::can("edit", $other_album)) {
- $other_album->album_cover_item_id = $parent->album_cover_item_id;
- $other_album->save();
- graphics::generate($other_album);
+ foreach ($item->parents(array(array("album_cover_item_id", "=", $old_album_cover_id)))
+ as $ancestor) {
+ if (access::can("edit", $ancestor)) {
+ $ancestor->album_cover_item_id = $parent->album_cover_item_id;
+ $ancestor->save();
+ graphics::generate($ancestor);
}
}
}