throw exception from Ansel_View#getGallery
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 10 Nov 2009 20:52:17 +0000 (15:52 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 10 Nov 2009 20:56:07 +0000 (15:56 -0500)
Bug: 8699

ansel/lib/View/Base.php
ansel/lib/View/EmbeddedRenderer/GalleryLink.php
ansel/lib/View/EmbeddedRenderer/Mini.php
ansel/lib/View/Gallery.php

index 43596c1..df8ec70 100644 (file)
@@ -49,6 +49,15 @@ abstract class Ansel_View_Base
         //throw new Horde_Exception(sprintf("The property %s of Ansel_View not found.", $property));
     }
 
+    /**
+     *
+     *
+     * @param integer $galleryId  The gallery id
+     * @param string $slug        The gallery slug
+     *
+     * @return Ansel_Gallery  The requested Ansel_Gallery object
+     * @throws Horde_Exception
+     */
     public function &getGallery($galleryId = null, $slug = '')
     {
         if (is_null($galleryId) && empty($slug)) {
@@ -57,7 +66,7 @@ abstract class Ansel_View_Base
         }
 
         if (empty($galleryId) && empty($slug)) {
-            return PEAR::raiseError(_("No gallery specified"));
+            throw new Horde_Exception(_("No gallery specified"));
         }
 
         // If we have a slug, use it.
@@ -67,9 +76,9 @@ abstract class Ansel_View_Base
             $gallery = &$GLOBALS['ansel_storage']->getGallery($galleryId);
         }
         if (is_a($gallery, 'PEAR_Error')) {
-            return $gallery;
+            throw new Horde_Exception($gallery->getMessage());
         } elseif (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
-            return PEAR::raiseError(sprintf(_("Access denied to gallery \"%s\"."), $gallery->get('name')));
+            throw new Horde_Exception(sprintf(_("Access denied to gallery \"%s\"."), $gallery->get('name')));
         }
 
         /* Set any date info we might have */
index 973354e..13b1198 100644 (file)
@@ -52,13 +52,14 @@ class Ansel_View_EmbeddedRenderer_GalleryLink extends Ansel_View_Gallery
             $this->_params['thumbsize'];
 
         foreach ($galleries as $identifier) {
-            if ($haveSlugs) {
-                $gallery = $this->getGallery(null, $identifier);
-            } else {
-                $gallery = $this->getGallery($identifier);
-            }
-            if (is_a($gallery, 'PEAR_Error')) {
-                Horde::logMessage($gallery, __FILE__, __LINE__, PEAR_LOG_ERR);
+            try {
+                if ($haveSlugs) {
+                    $gallery = $this->getGallery(null, $identifier);
+                } else {
+                    $gallery = $this->getGallery($identifier);
+                }
+            } catch (Horde_Exception $e) {
+                Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
                 exit;
             }
             if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
index b24b211..a243862 100644 (file)
@@ -48,9 +48,10 @@ class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery
             // galleries.
             $images = explode(':', $images);
         } else {
-            $this->gallery = $this->getGallery($gallery_id, $gallery_slug);
-            if (is_a($this->gallery, 'PEAR_Error')) {
-                Horde::logMessage($this->gallery, __FILE__, __LINE__, PEAR_LOG_ERR);
+            try {
+                $this->gallery = $this->getGallery($gallery_id, $gallery_slug);
+            } catch (Horde_Exception $e) {
+                Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
                 exit;
             }
 
index c798af8..0b0ef84 100644 (file)
@@ -81,9 +81,6 @@ class Ansel_View_Gallery extends Ansel_View_Base
         } else {
             $this->gallery = $this->getGallery();
         }
-        if (is_a($this->gallery, 'PEAR_Error')) {
-            throw new Horde_Exception($this->gallery);
-        }
 
         // Check user age
         if (!$this->gallery->isOldEnough()) {