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 |
the confusion.
update the framework?
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.
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.
State ⇒ Resolved
State ⇒ Unconfirmed
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ lib/Block/gallery.php dies with fatal error if specified gallery doesn't exist
Queue ⇒ Ansel
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;
}