[Tickets #3855] NEW: lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist

bugs@bugs.horde.org bugs at bugs.horde.org
Fri Apr 28 14:18:12 PDT 2006


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/?id=3855
-----------------------------------------------------------------------
 Ticket             | 3855
 Created By         | dorm at dorm.org
 Summary            | lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist
 Queue              | Ansel
 State              | Unconfirmed
 Priority           | 2. Medium
 Type               | Bug
 Owners             | 
-----------------------------------------------------------------------


dorm at dorm.org (2006-04-28 14:18) wrote:

If (1) the gallery specified in the layout config for the Ansel block
doesn't exist, or, (2) the Ansel block is configured for a random gallery,
and no galleries exist, then the Ansel block causes a fatal error because
$this->_gallery is NULL.

The following patch checks for this condition, and also generates better
output for the block in that case.  E.g. it still generates a link to Ansel
and displays a "there was an error loading the gallery" message.

There may be a more correct way to do this, but these changes are working
well for me.


--- gallery.php 2006-04-28 15:11:38.584419272 -0600
+++ gallery.php 2006-04-28 15:03:55.581806368 -0600
@@ -43,7 +43,7 @@
     {
         $gallery = &$this->_getGallery();
         if (is_a($gallery, 'PEAR_Error')) {
-            return _("Gallery");
+            return Horde::link(Horde::applicationUrl()) . _("Gallery") .
'</a>';
         }
 
         // Build the gallery name.
@@ -62,7 +62,7 @@
     {
         $gallery = &$this->_getGallery();
         if (is_a($gallery, 'PEAR_Error')) {
-            return $gallery;
+            return Horde::link(Horde::applicationUrl()) . '<i>' . _("There
was an error loading the gallery.") . '</i></a>';
         }
 
         $viewurl = Horde::applicationUrl(Util::addParameter('view.php',
'gallery', $gallery->getId()));
@@ -96,11 +96,17 @@
             $this->_gallery = &Ansel::getRandomGallery();
         }
 
-        // Make sure we got a gallery, not just an error.
-        if (is_a($this->_gallery, 'PEAR_Error') ||
!$this->_gallery->hasPermission(Auth::getAuth(), PERMS_READ)) {
+       if(($this->_gallery == NULL) || ($this->_gallery->name == NULL)) {
+               // We did not select a gallery because the specified one
doesn't exist,
+               // or we're using the Random Gallery and there are no
galleries
+               $this->_gallery = NULL;
+               return PEAR::raiseError(_("Gallery does not exist."));
+       } else if (is_a($this->_gallery, 'PEAR_Error') ||
!$this->_gallery->hasPermission(Auth::getAuth(), PERMS_READ)) {
+               // Make sure we got a gallery, not just an error.
             return PEAR::raiseError(_("You do not have permission to view
this gallery."));
         }
 
+
         // Return a reference to the gallery.
         return $this->_gallery;
     }




More information about the bugs mailing list