Skip to content
Browse files

When changing the album cover, find and retarget any other albums whi…

…ch were using the old item as their album cover. Fixes #1978.
  • Loading branch information...
1 parent 12ea6ad commit cff1e76e8da2055f9faf7449222b43a686014b1c @bharat bharat committed
Showing with 19 additions and 0 deletions.
  1. +19 −0 modules/gallery/helpers/item.php
View
19 modules/gallery/helpers/item.php
@@ -76,16 +76,35 @@ static function make_album_cover($item) {
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) {

0 comments on commit cff1e76

Please sign in to comment.
Something went wrong with that request. Please try again.