summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-09-02 15:29:00 -0700
committerBharat Mediratta <bharat@menalto.com>2009-09-02 15:29:00 -0700
commit9237ab9bc1e7b3286ceecd5bf6b03cdbfcfa98a5 (patch)
tree4781b85a4d7f8a46a8a4f1f657852326f247fba8
parentb842a9d9ca21d07241b5fa11c5263e18f830c88b (diff)
Change graphics::generate() API so that it doesn't return a boolean,
instead it throws an exception if there's a problem. The normal case for graphics::generate is that it's going to succeed. It'll only fail if something un-handleable went wrong, so just use the resulting exception.
-rw-r--r--modules/gallery/helpers/gallery_task.php11
-rw-r--r--modules/gallery/helpers/graphics.php10
-rw-r--r--modules/gallery/helpers/photo.php6
3 files changed, 14 insertions, 13 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index c9557324..1b56ab97 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -60,14 +60,15 @@ class gallery_task_Core {
$item = ORM::factory("item", $row->id);
if ($item->loaded) {
- $success = graphics::generate($item);
- if (!$success) {
+ try {
+ graphics::generate($item);
$ignored[$item->id] = 1;
- $errors[] = t("Unable to rebuild images for '%title'",
- array("title" => html::purify($item->title)));
- } else {
$errors[] = t("Successfully rebuilt images for '%title'",
array("title" => html::purify($item->title)));
+ } catch (Exception $e) {
+ $errors[] = t("Unable to rebuild images for '%title'",
+ array("title" => html::purify($item->title)));
+ $errors[] = $e->__toString();
}
}
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index 66182a68..78812794 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -102,12 +102,12 @@ class graphics_Core {
/**
* Rebuild the thumb and resize for the given item.
* @param Item_Model $item
- * @return true on successful generation
*/
static function generate($item) {
if ($item->is_album()) {
if (!$cover = $item->album_cover()) {
- return false;
+ // This album has no cover; there's nothing to generate.
+ return;
}
$input_file = $cover->file_path();
$input_item = $cover;
@@ -127,7 +127,7 @@ class graphics_Core {
$item->thumb_dirty = 0;
$item->resize_dirty = 0;
$item->save();
- return true;
+ return;
}
try {
@@ -176,10 +176,8 @@ class graphics_Core {
// @todo we should handle this better.
Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" .
$e->getMessage() . "\n" . $e->getTraceAsString());
- return false;
+ throw $e;
}
-
- return true;
}
/**
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index 96a66d29..40b645a2 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -111,9 +111,11 @@ class photo_Core {
// Build our thumbnail/resizes. If we fail to build thumbnail/resize we assume that the image
// is bad in some way and discard it.
- if (!graphics::generate($photo)) {
+ try {
+ graphics::generate($photo);
+ } catch (Exception $e) {
$photo->delete();
- throw new Exception("@todo BAD_IMAGE_FILE");
+ throw $e;
}
// If the parent has no cover item, make this it.