catch error when searching
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 20:37:06 +0000 (15:37 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 20:38:14 +0000 (15:38 -0500)
ansel/lib/Search/Tag.php
ansel/lib/View/Results.php
ansel/xppublish.php

index 66c4b46..78b13b6 100644 (file)
@@ -93,9 +93,6 @@ class Ansel_Search_Tag
     /**
      * Fetch the matching resources that should appear on the current page
      *
-     * @TODO: Implement an Interface that Ansel_Gallery and Ansel_Image should
-     *        implement that the client search code will use.
-     *
      * @return Array of Ansel_Images and Ansel_Galleries
      */
     public function getSlice($page, $perpage)
@@ -121,7 +118,11 @@ class Ansel_Search_Tag
         $count = $perpage - count($galleries);
         if ($count > 0) {
             $iresults = array_slice($this->_results['images'], $istart, $count);
-            $images = count($iresults) ? array_values($GLOBALS['injector']->getInstance('Ansel_Storage')->getImages(array('ids' => $iresults))) : array();
+            try {
+                $images = count($iresults) ? array_values($GLOBALS['injector']->getInstance('Ansel_Storage')->getImages(array('ids' => $iresults))) : array();
+            } catch (Horde_Exception_NotFound $e) {
+                throw new Ansel_Exception($e);
+            }
             if (($conf['comments']['allow'] == 'all' || ($conf['comments']['allow'] == 'authenticated' && $GLOBALS['registry']->getAuth())) &&
                 $registry->hasMethod('forums/numMessagesBatch')) {
 
index bb68224..903179c 100644 (file)
@@ -229,7 +229,12 @@ class Ansel_View_Results extends Ansel_View_Base
         $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
 
         // Get the slice of galleries/images to view on this page.
-        $results = $this->_search->getSlice($this->_page, $this->_perPage);
+        try {
+            $results = $this->_search->getSlice($this->_page, $this->_perPage);
+        } catch (Ansel_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            return _("An error has occured retrieving the image. Details have been logged.");
+        }
         $total = $this->_search->count();
         $total = $total['galleries'] + $total['images'];
 
index a190ebf..465aa79 100644 (file)
@@ -177,7 +177,7 @@ if ($cmd == 'add') {
                 $error = false;
             }
         } catch (Ansel_Exception $e) {
-            $error = _("There was an error accessing the gallery");
+            $error = _("There was an error accessing the gallery.");
         }
     }
     if (!$name || $error) {