From 9affa8ebbd539396d71f19003b91af577a8a183e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 10 May 2010 22:11:59 -0700 Subject: Pick a new album cover when the photo that's the current cover is deleted. Fixes ticket #1083. --- modules/gallery/helpers/gallery_event.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index d723cc1b..2416f2e5 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -97,6 +97,17 @@ class gallery_event_Core { static function item_deleted($item) { access::delete_item($item); + + $parent = $item->parent(); + if (!$parent->album_cover_item_id) { + // Assume we deleted the album cover and pick a new one. Choosing the first photo in the + // album is logical, but it's not the most efficient in the case where we're deleting all + // the photos in the album one at a time since we'll probably delete them in order which + // means that we'll be resetting the album cover each time. + if ($child = $parent->children(1)->current()) { + item::make_album_cover($child); + } + } } static function item_moved($item, $old_parent) { -- cgit v1.2.3