6.0.0-beta1
9/24/25

[#3855] lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist
Summary lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist
Queue Ansel
Type Bug
State Resolved
Priority 2. Medium
Owners
Requester dorm (at) dorm (dot) org
Created 04/28/2006 (7089 days ago)
Due
Updated 05/09/2006 (7078 days ago)
Assigned
Resolved 04/29/2006 (7088 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
05/09/2006 04:38:13 AM dorm (at) dorm (dot) org Comment #7 Reply to this comment
Ahh, nope, that would be it.  I'm on Horde 3.1.1, not HEAD.  Sorry for 
the confusion.
05/08/2006 11:30:30 PM Jan Schneider Comment #6 Reply to this comment
It does now, but the required change is in Horde, not Ansel. Did you 
update the framework?
05/08/2006 10:41:28 PM dorm (at) dorm (dot) org Comment #5 Reply to this comment
Unfortunately, that still doesn't solve the problem.  We don't event 
get to line 65, because in line 64 $gallery is a Gallery object, not a 
PEAR_Error.



This is where I'm confused, because I don't understand how _getGallery 
doesn't return PEAR_Error when the requested gallery doesn't exist.
05/04/2006 11:34:09 PM Jan Schneider Comment #4 Reply to this comment
Fixed.
05/04/2006 05:16:26 PM dorm (at) dorm (dot) org Comment #3 Reply to this comment
This fixed the random gallery side of things, but it still dies if the 
block is explicitly configured for a particular gallery, and that 
gallery doesn't exist.  (e.g. the block was configured for a gallery 
and then later the gallery was deleted.)



This seems to be the result of 
&$GLOBALS['ansel_shares']->getGallery(..) not returning NULL when the 
gallery doesn't exist.  Instead it still returns a gallery object, 
with it's name parameter as NULL.


04/29/2006 05:45:29 PM Jan Schneider Comment #2
State ⇒ Resolved
Reply to this comment
Tweaked and committed, thanks.
04/28/2006 09:18:11 PM dorm (at) dorm (dot) org Comment #1
State ⇒ Unconfirmed
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist
Queue ⇒ Ansel
Reply to this comment
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;

      }

Saved Queries