diff options
author | Bharat Mediratta <bharat@menalto.com> | 2013-01-30 21:08:36 -0500 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2013-01-30 21:08:36 -0500 |
commit | cff1e76e8da2055f9faf7449222b43a686014b1c (patch) | |
tree | b09a035090df9cc5d32e9d77b461ba0d2a7d95f3 /modules/gallery/helpers/item.php | |
parent | 12ea6ad642c0e84fe67f1324f8fa00c9534e7aa5 (diff) |
When changing the album cover, find and retarget any other albums which were using the old item as their album cover. Fixes #1978.
Diffstat (limited to 'modules/gallery/helpers/item.php')
-rw-r--r-- | modules/gallery/helpers/item.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 093feb2d..8d3b4354 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -76,16 +76,35 @@ class item_Core { access::required("view", $parent); access::required("edit", $parent); + $old_album_cover_id = $parent->album_cover_item_id; + model_cache::clear(); $parent->album_cover_item_id = $item->is_album() ? $item->album_cover_item_id : $item->id; $parent->save(); graphics::generate($parent); + // Walk up the parent hierarchy and set album covers if necessary $grand_parent = $parent->parent(); if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) { item::make_album_cover($parent); } + + // 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. + 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); + } + } + } } static function remove_album_cover($album) { |