From f83ed5f8716663a45c9d8e8118bbcf0e2849c3fb Mon Sep 17 00:00:00 2001 From: shadlaws Date: Thu, 31 Jan 2013 17:18:39 +0100 Subject: [PATCH] #1982 - Add placeholder for albums with no album cover. - Added missing_album_cover.jpg placeholder image. - Modified the graphics helper to use it. Calling graphics::generate will copy it. - Modified item::remove_album_cover and gallery_event::item_created to run graphics::generate. - Added unit test to Graphics_Helper_Test. --- modules/gallery/helpers/gallery_event.php | 20 +++++++++--------- modules/gallery/helpers/graphics.php | 10 ++++++--- modules/gallery/helpers/item.php | 1 + .../gallery/images/missing_album_cover.jpg | Bin 0 -> 4453 bytes .../gallery/tests/Graphics_Helper_Test.php | 11 ++++++++++ 5 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 modules/gallery/images/missing_album_cover.jpg diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 4bbeccc2..aeb1c7eb 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -86,17 +86,17 @@ class gallery_event_Core { static function item_created($item) { access::add_item($item); - if ($item->is_photo() || $item->is_movie()) { - // Build our thumbnail/resizes. - try { - graphics::generate($item); - } catch (Exception $e) { - log::error("graphics", t("Couldn't create a thumbnail or resize for %item_title", - array("item_title" => $item->title)), - html::anchor($item->abs_url(), t("details"))); - Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); - } + // Build our thumbnail/resizes. + try { + graphics::generate($item); + } catch (Exception $e) { + log::error("graphics", t("Couldn't create a thumbnail or resize for %item_title", + array("item_title" => $item->title)), + html::anchor($item->abs_url(), t("details"))); + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + } + if ($item->is_photo() || $item->is_movie()) { // If the parent has no cover item, make this it. $parent = $item->parent(); if (access::can("edit", $parent) && $parent->album_cover_item_id == null) { diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 19ae1036..7c8e89d5 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -152,6 +152,7 @@ class graphics_Core { } catch (Exception $e) { // Didn't work, likely because of MISSING_FFMPEG - use placeholder graphics::_replace_image_with_placeholder($item, $target); + break; } } $working_file = $output_file; @@ -167,7 +168,7 @@ class graphics_Core { case "album": if (!$cover = $item->album_cover()) { - // This album has no cover; there's nothing to generate. Because of an old bug, it's + // This album has no cover; copy its placeholder image. Because of an old bug, it's // possible that there's an album cover item id that points to an invalid item. In that // case, just null out the album cover item id. It's not optimal to do that at this low // level, but it's not trivial to find these cases quickly in an upgrade script and if we @@ -179,7 +180,8 @@ class graphics_Core { $item->album_cover_item_id = null; $item->save(); } - return; + graphics::_replace_image_with_placeholder($item, $target); + break; } if ($cover->thumb_dirty) { graphics::generate($cover); @@ -238,7 +240,9 @@ class graphics_Core { } private static function _replace_image_with_placeholder($item, $target) { - if ($item->is_movie() || ($item->is_album() && $item->album_cover()->is_movie())) { + if ($item->is_album() && !$item->album_cover_item_id) { + $input_path = MODPATH . "gallery/images/missing_album_cover.jpg"; + } else if ($item->is_movie() || ($item->is_album() && $item->album_cover()->is_movie())) { $input_path = MODPATH . "gallery/images/missing_movie.jpg"; } else { $input_path = MODPATH . "gallery/images/missing_photo.jpg"; diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 975d46e5..9882a9c5 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -113,6 +113,7 @@ class item_Core { model_cache::clear(); $album->album_cover_item_id = null; $album->save(); + graphics::generate($album); } /** diff --git a/modules/gallery/images/missing_album_cover.jpg b/modules/gallery/images/missing_album_cover.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bdddeec5dbc5658862d4661e349814641fb330c8 GIT binary patch literal 4453 zcmd5;2~<;O7XDunHrYgi3Ra`IAu9V)DUcwtD#AmM#RU=Bx2hn5h9FgF@nDJwRumJA zXaKDut6EJvC+K0R%z79{mGIC-~LoXm9`kPEJ4@03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~2LhgLud#sWG6JfA)krNwK-r9Y zWMMl3>H^S}e`y_mGO{*d!xyFZ&V1Parkxz3D^cwq@p4?XGwrG0wID3IA??u|3x^M% zaS%rD&vOo4X|n$a+@}bL?%1Gassert_equal(0, $album->thumb_dirty); } + public function generate_album_cover_for_empty_album_test() { + $album = test::random_album(); + // Check that the album cover is the missing image placeholder + $this->assert_same(file_get_contents(MODPATH . "gallery/images/missing_album_cover.jpg"), + file_get_contents($album->thumb_path())); + // Check that the items table got updated with new metadata + $this->assert_equal(array(200, 200), array($album->thumb_width, $album->thumb_height)); + // Check that the image is *not* marked as dirty + $this->assert_equal(0, $album->thumb_dirty); + } + public function generate_bad_photo_test() { $photo = test::random_photo(); // At this point, the photo is valid and has a valid resize and thumb. Make it garble.