From 80f9d4a48125528b296d75e294946328314189d3 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 1 Oct 2009 16:43:29 -0400 Subject: [PATCH] More refactoring to use exceptions Fixes issue in Bug: 8623 as well. --- ansel/faces/image.php | 9 ++++-- ansel/img/mini.php | 7 +++-- ansel/img/prettythumb.php | 7 +++-- ansel/img/screen.php | 5 ++-- ansel/img/thumb.php | 5 ++-- ansel/lib/Ansel.php | 9 ++++-- ansel/lib/Api.php | 3 -- ansel/lib/Faces/Base.php | 4 +-- ansel/lib/Image.php | 52 +++++++++++++++++++---------------- ansel/lib/ImageView/plainstack.php | 3 -- ansel/lib/ImageView/polaroidstack.php | 5 +--- ansel/lib/ImageView/roundedstack.php | 3 -- 12 files changed, 59 insertions(+), 53 deletions(-) diff --git a/ansel/faces/image.php b/ansel/faces/image.php index 41628de84..693b9e907 100644 --- a/ansel/faces/image.php +++ b/ansel/faces/image.php @@ -23,8 +23,13 @@ $result = $faces->getImageFacesData($image_id); // or if we were asked to explicitly try again. if (($reload || empty($result))) { $image = &$ansel_storage->getImage($image_id); - $image->createView('screen'); - $result = $faces->getFromPicture($image_id, $autocreate); + try { + $image->createView('screen'); + $result = $faces->getFromPicture($image_id, $autocreate); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); + $result = null; + } } if (!empty($result)) { diff --git a/ansel/img/mini.php b/ansel/img/mini.php index b90aedb54..0c14a039e 100644 --- a/ansel/img/mini.php +++ b/ansel/img/mini.php @@ -26,9 +26,10 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ - $result = $image->createView('mini', 'ansel_default'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + try { + $image->createView('mini', 'ansel_default'); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); exit; } $filename = $ansel_vfs->readFile($image->getVFSPath('mini'), $image->getVFSName('mini')); diff --git a/ansel/img/prettythumb.php b/ansel/img/prettythumb.php index 22dbbd3b0..6c3cbd3a7 100644 --- a/ansel/img/prettythumb.php +++ b/ansel/img/prettythumb.php @@ -27,9 +27,10 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ - $result = $image->createView('prettythumb', $style); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + try { + $image->createView('prettythumb', $style); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); exit; } $filename = $ansel_vfs->readFile($image->getVFSPath('prettythumb', $style), $image->getVFSName('prettythumb')); diff --git a/ansel/img/screen.php b/ansel/img/screen.php index 2ee835b19..d7ec53612 100644 --- a/ansel/img/screen.php +++ b/ansel/img/screen.php @@ -26,8 +26,9 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ - $result = $image->createView('screen', 'ansel_default'); - if (is_a($result, 'PEAR_Error')) { + try { + $image->createView('screen', 'ansel_default'); + } catch (Horde_Exception $e) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); exit; } diff --git a/ansel/img/thumb.php b/ansel/img/thumb.php index 33a655358..4c4700eab 100644 --- a/ansel/img/thumb.php +++ b/ansel/img/thumb.php @@ -26,8 +26,9 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) { /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */ if ($conf['vfs']['src'] == 'sendfile') { /* Need to ensure the file exists */ - $result = $image->createView('thumb', 'ansel_default'); - if (is_a($result, 'PEAR_Error')) { + try { + $image->createView('thumb', 'ansel_default'); + } catch (Horde_Exception $e) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); exit; } diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index 830a19f52..725c5dc6c 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -474,10 +474,15 @@ class Ansel ($viewHash = Ansel_Image::viewExists($imageId, $view, $style)) === false) { // We have to make sure the image exists first, since we won't // be going through img/*.php to auto-create it. - if (is_a($image = $ansel_storage->getImage($imageId), 'PEAR_Error')) { + try { + $image = $ansel_storage->getImage($imageId); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); return Ansel::getErrorImage($view); } - if (is_a($result = $image->createView($view, $style, false), 'PEAR_Error')) { + try { + $image->createView($view, $style, false); + } catch (Horde_Exception $e) { return Ansel::getErrorImage($view); } $viewHash = $image->getViewHash($view, $style) . '/' diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index 1c947393c..32d2c7ab6 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -680,9 +680,6 @@ class Ansel_Api extends Horde_Registry_Api } else { // Load View $result = $image->load($view, $style); - if (is_a($result, 'PEAR_Error')) { - return $result; - } // Return image content $data = $image->_image->raw(); diff --git a/ansel/lib/Faces/Base.php b/ansel/lib/Faces/Base.php index 639a2395c..6f27327e5 100644 --- a/ansel/lib/Faces/Base.php +++ b/ansel/lib/Faces/Base.php @@ -340,7 +340,7 @@ class Ansel_Faces_Base $image = &$GLOBALS['ansel_storage']->getImage($image_id); // Actually create the image. - $result = $this->createView( + $this->createView( $face_id, $image, $data['face_x1'], @@ -449,7 +449,7 @@ class Ansel_Faces_Base $image->load('screen'); // Process the image - $result = $this->createView($face_id, + $this->createView($face_id, $image, $x1, $y1, diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index a2dcf54ce..9b51397fe 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -175,7 +175,8 @@ class Ansel_Image * @param string $view Which view to load. * @param string $style The named gallery style. * - * @return mixed True || PEAR_Error + * @return boolean + * @throws Horde_Exception */ function load($view = 'full', $style = null) { @@ -193,11 +194,7 @@ class Ansel_Image if (!empty($this->_loaded[$viewHash])) { return true; } - - $result = $this->createView($view, $style); - if (is_a($result, 'PEAR_Error')) { - return $result; - } + $this->createView($view, $style); /* If createView() had to resize the full image, we've already * loaded the data, so return now. */ @@ -210,15 +207,12 @@ class Ansel_Image /* Get the VFS info. */ $vfspath = $this->getVFSPath($view, $style); - if (is_a($vfspath, 'PEAR_Error')) { - return $vfspath; - } /* Read in the requested view. */ $data = $GLOBALS['ansel_vfs']->read($vfspath, $this->getVFSName($view)); if (is_a($data, 'PEAR_Error')) { Horde::logMessage($date, __FILE__, __LINE__, PEAR_LOG_ERR); - return $data; + throw new Horde_Exception($data->getMessage()); } $this->_data[$viewHash] = $data; @@ -272,6 +266,9 @@ class Ansel_Image * * @param string $view Which view to create. * @param string $style A named gallery style + * + * @return boolean + * @throws Horde_Exception */ function createView($view, $style = null) { @@ -295,7 +292,7 @@ class Ansel_Image $this->getVFSName('full')); if (is_a($data, 'PEAR_Error')) { Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR); - return $data; + throw new Horde_Exception($data->getMessage()); } $this->_image->loadString($this->getVFSPath('full') . '/' . $this->id, $data); $styleDef = Ansel::getStyleDefinition($style); @@ -328,7 +325,11 @@ class Ansel_Image $view = $this->getViewHash($view, $style); - $this->_data[$view] = $this->_image->raw(); + try { + $this->_data[$view] = $this->_image->raw(); + } catch (Horde_Image_Exception $e) { + throw new Horde_Exception($e); + } $this->_image->loadString($vfspath . '/' . $this->id, $this->_data[$view]); $this->_loaded[$view] = true; @@ -777,13 +778,12 @@ class Ansel_Image echo $data; return; } - - if (is_a($result = $this->load($view, $style), 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - return $result; + try { + $this->load($view, $style); + $this->_image->display(); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); } - - $this->_image->display(); } /** @@ -793,10 +793,12 @@ class Ansel_Image */ function toFile($view = 'full') { - if (is_a(($result = $this->load($view)), 'PEAR_Error')) { - return $result; + try { + $this->load($view); + return $this->_image->toFile($this->_dirty ? false : $this->_data[$view]); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); } - return $this->_image->toFile($this->_dirty ? false : $this->_data[$view]); } /** @@ -806,10 +808,12 @@ class Ansel_Image */ function getDimensions($view = 'full') { - if (is_a(($result = $this->load($view)), 'PEAR_Error')) { - return $result; + try { + $this->load($view); + return $this->_image->getDimensions(); + } catch (Horde_Exception $e) { + Horde::logMessage($e->getMessage(), __FILE__, __LINE__); } - return $this->_image->getDimensions(); } /** diff --git a/ansel/lib/ImageView/plainstack.php b/ansel/lib/ImageView/plainstack.php index ab261984e..ce1a05b85 100644 --- a/ansel/lib/ImageView/plainstack.php +++ b/ansel/lib/ImageView/plainstack.php @@ -16,9 +16,6 @@ class Ansel_ImageView_plainstack extends Ansel_ImageView { $style = $this->_params['style']; foreach ($images as $image) { $result = $image->load('screen'); - if (is_a($result, 'PEAR_Error')) { - return $result; - } $imgobjs[] = $image->_image; } diff --git a/ansel/lib/ImageView/polaroidstack.php b/ansel/lib/ImageView/polaroidstack.php index 697f66e9a..c80330b6a 100644 --- a/ansel/lib/ImageView/polaroidstack.php +++ b/ansel/lib/ImageView/polaroidstack.php @@ -15,10 +15,7 @@ class Ansel_ImageView_polaroidstack extends Ansel_ImageView { $images = $this->_getStackImages(); $style = $this->_params['style']; foreach ($images as $image) { - $result = $image->load('screen'); - if (is_a($result, 'PEAR_Error')) { - return $result; - } + $image->load('screen'); $imgobjs[] = $image->_image; } diff --git a/ansel/lib/ImageView/roundedstack.php b/ansel/lib/ImageView/roundedstack.php index a646c301a..f8744455f 100644 --- a/ansel/lib/ImageView/roundedstack.php +++ b/ansel/lib/ImageView/roundedstack.php @@ -17,9 +17,6 @@ class Ansel_ImageView_roundedstack extends Ansel_ImageView { $style = $this->_params['style']; foreach ($images as $image) { $result = $image->load('screen'); - if (is_a($result, 'PEAR_Error')) { - return $result; - } $imgobjs[] = $image->_image; } -- 2.11.0