summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorshadlaws <shad@shadlaws.com>2013-01-31 17:18:39 +0100
committershadlaws <shad@shadlaws.com>2013-01-31 17:18:39 +0100
commitf83ed5f8716663a45c9d8e8118bbcf0e2849c3fb (patch)
treeb4182b14160868ae1e6043ee1302d3ccf0bcdf68 /modules/gallery
parente17c39386b9d322f9bafd8b548ec6b94a7c5f7b5 (diff)
#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.
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/helpers/gallery_event.php20
-rw-r--r--modules/gallery/helpers/graphics.php10
-rw-r--r--modules/gallery/helpers/item.php1
-rw-r--r--modules/gallery/images/missing_album_cover.jpgbin0 -> 4453 bytes
-rw-r--r--modules/gallery/tests/Graphics_Helper_Test.php11
5 files changed, 29 insertions, 13 deletions
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 00000000..bdddeec5
--- /dev/null
+++ b/modules/gallery/images/missing_album_cover.jpg
Binary files differ
diff --git a/modules/gallery/tests/Graphics_Helper_Test.php b/modules/gallery/tests/Graphics_Helper_Test.php
index a68822b0..2cf5caa7 100644
--- a/modules/gallery/tests/Graphics_Helper_Test.php
+++ b/modules/gallery/tests/Graphics_Helper_Test.php
@@ -77,6 +77,17 @@ class Graphics_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_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.