break;
case 'owner':
- $num_groups = $ansel_storage->shares->countOwners(Horde_Perms::SHOW, null,
- false);
- if (is_a($num_groups, 'PEAR_Error')) {
- $notification->push($num_groups);
+ try {
+ if ($num_groups = $ansel_storage->shares->countOwners(Horde_Perms::SHOW, null, false)) {
+
+ $groups = $ansel_storage->shares->listOwners(Horde_Perms::SHOW,
+ null,
+ false,
+ $gbpage * $groups_perpage,
+ $groups_perpage);
+ } else {
+ $groups = array();
+ }
+ } catch (Horde_Share_Exception $e) {
+ $notification->push($e->getMessage());
$num_groups = 0;
$groups = array();
- } elseif ($num_groups) {
- $groups = $ansel_storage->shares->listOwners(Horde_Perms::SHOW, null,
- false,
- $gbpage * $groups_perpage,
- $groups_perpage);
- } else {
- $groups = array();
}
break;
/**
* Delete faces from VFS and DB storage.
*
+ * @TODO: Move SQL queries to Ansel_Storage::
+ *
* @param Ansel_Image $image Image object to delete faces for
* @param integer $face Face id
* @static
}
/* Bulk update the images to their new gallery_id */
- $result = $this->_gallery->_shareOb->_write_db->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
+ $result = $this->_gallery->_shareOb->getWriteDb()->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
if (is_a($result, 'PEAR_Error')) {
return $result;
}
} catch (VFS_Exception $e) {}
/* Delete from SQL. */
- $this->_gallery->_shareOb->_write_db->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
+ $this->_gallery->_shareOb->getWriteDb()->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
/* Remove any attributes */
- $this->_gallery->_shareOb->_write_db->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
+ $this->_gallery->_shareOb->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
if (!$isStack) {
$this->_gallery->updateImageCount(1, false, $image_gallery);
}
}
- $result = $this->_gallery->_shareOb->_write_db->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
+ $result = $this->_gallery->_shareOb->getWriteDb()->exec('UPDATE ansel_images SET gallery_id = ' . $gallery->id . ' WHERE image_id IN (' . implode(',', $ids) . ')');
if ($result instanceof PEAR_Error) {
throw new Ansel_Exception($result->getMessage());
}
} catch (VFS_Exception $e) {}
/* Delete from SQL. */
- $this->_gallery->_shareOb->_write_db->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
+ $this->_gallery->_shareOb->getWriteDb()->exec('DELETE FROM ansel_images WHERE image_id = ' . (int)$image->id);
/* Remove any attributes */
- $this->_gallery->_shareOb->_write_db->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
+ $this->_gallery->_shareOb->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id);
if (!$isStack) {
$this->_gallery->updateImageCount(1, false);
}
/* Create the gallery */
- $gallery = $this->_shares->newShare('');
- if ($gallery instanceof PEAR_Error) {
- Horde::logMessage($gallery, 'ERR');
- throw new Horde_Exception($gallery->getMessage());
+ try {
+ $gallery = $this->_shares->newShare('');
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage, 'ERR');
+ throw new Ansel_Exception($e);
}
Horde::logMessage('New Ansel_Gallery object instantiated', 'DEBUG');
}
/* Save it to storage */
- $result = $this->_shares->addShare($gallery);
- if ($result instanceof PEAR_Error) {
+ try {
+ $result = $this->_shares->addShare($gallery);
+ } catch (Horde_Share_Exception $e) {
$error = sprintf(_("The gallery \"%s\" could not be created: %s"),
- $attributes['name'], $result->getMessage());
+ $attributes['name'], $e->getMessage());
Horde::logMessage($error, 'ERR');
throw new Ansel_Exception($error);
}
return $this->_galleries[$gallery_id];
}
- $result = &$this->_shares->getShareById($gallery_id);
- if ($result instanceof PEAR_Error) {
- throw new Ansel_Exception($result);
+ try {
+ $result = $this->_shares->getShareById($gallery_id);
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
}
- $this->_galleries[$gallery_id] = &$result;
+ $this->_galleries[$gallery_id] = $result;
// Don't cache if we have overridden anything
if (!count($overrides)) {
$id = $gallery->id;
/* Delete the gallery from storage */
- $result = $this->_shares->removeShare($gallery);
- if ($result instanceof PEAR_Error) {
- throw new Ansel_Exception($result);
+ try {
+ $this->_shares->removeShare($gallery);
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
}
/* Expire the cache */
return $counts[$key];
}
- $count = $this->_shares->countShares($userid, $perm, $attributes,
- $parent, $allLevels);
-
- if ($count instanceof PEAR_Error) {
- throw new Ansel_Exception($count);
+ try {
+ $count = $this->_shares->countShares($userid, $perm, $attributes,
+ $parent, $allLevels);
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
}
$counts[$key] = $count;
$sort_by = null,
$direction = 0)
{
- $shares = $this->_shares->listShares(Horde_Auth::getAuth(), $perm, $attributes,
- $from, $count, $sort_by, $direction,
- $parent, $allLevels);
+ try {
+ $shares = $this->_shares->listShares(Horde_Auth::getAuth(), $perm, $attributes,
+ $from, $count, $sort_by, $direction,
+ $parent, $allLevels);
- if ($shares instanceof PEAR_Error) {
- throw new Ansel_Exception($shares);
+ } catch (Horde_Share_Exception $e) {
+ throw new Ansel_Exception($e);
}
return $shares;
$actionID = Horde_Util::getFormData('actionID', 'edit');
switch ($actionID) {
case 'edit':
- $share = &$ansel_storage->getGallery(Horde_Util::getFormData('cid'));
- if (!is_a($share, 'PEAR_Error')) {
+ try {
+ $share = $ansel_storage->getGallery(Horde_Util::getFormData('cid'));
$form = 'edit.inc';
$perm = &$share->getPermission();
- } elseif (($share_name = Horde_Util::getFormData('share')) !== null) {
- $share = &$ansel_storage->shares->getShare($share_name);
- if (!is_a($share, 'PEAR_Error')) {
- $form = 'edit.inc';
- $perm = &$share->getPermission();
+ } catch (Horde_Share_Exception $e) {
+ if (($share_name = Horde_Util::getFormData('share')) !== null) {
+ try {
+ $share = $ansel_storage->shares->getShare($share_name);
+ $form = 'edit.inc';
+ $perm = $share->getPermission();
+ } catch (Horde_Share_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
+ }
}
}
- if (is_a($share, 'PEAR_Error')) {
- $notification->push($share, 'horde.error');
- } elseif (!Horde_Auth::getAuth() ||
- (isset($share) && Horde_Auth::getAuth() != $share->get('owner'))) {
+ if (!Horde_Auth::getAuth() ||
+ (isset($share) && Horde_Auth::getAuth() != $share->get('owner'))) {
exit('permission denied');
}
break;
case 'editform':
case 'editforminherit':
- $share = &$ansel_storage->getGallery(Horde_Util::getFormData('cid'));
- if (is_a($share, 'PEAR_Error')) {
+ try {
+ $share = &$ansel_storage->getGallery(Horde_Util::getFormData('cid'));
+ } catch (Horde_Share_Exception $e) {
$notification->push(_("Attempt to edit a non-existent share."), 'horde.error');
- } else {
+ }
+
+ if (!empty($share)) {
if (!Horde_Auth::getAuth() ||
Horde_Auth::getAuth() != $share->get('owner')) {
exit('permission denied');
}
- $perm = &$share->getPermission();
+ $perm = $share->getPermission();
// Process owner and owner permissions.
$old_owner = $share->get('owner');
break;
}
-if (is_a($share, 'PEAR_Error')) {
+if (empty($share)) {
$title = _("Edit Permissions");
} else {
- $children = $GLOBALS['ansel_storage']->listGalleries(Horde_Perms::READ, false,
- $share);
+ $children = $GLOBALS['ansel_storage']->listGalleries(Horde_Perms::READ, false, $share);
$title = sprintf(_("Edit Permissions for %s"), $share->get('name'));
}
$groupList = $groups->listGroups();
asort($groupList);
-if (is_a($groupList, 'PEAR_Error')) {
+if ($groupList instanceof PEAR_Error) {
Horde::logMessage($groupList, 'NOTICE');
$groupList = array();
}
// Determine what we are requesting
switch ($stream_type) {
case 'all':
- $images = $ansel_storage->getRecentImages();
- if (is_a($images, 'PEAR_Error') || !count($images)) {
+ try {
+ $images = $ansel_storage->getRecentImages();
+ } catch (Ansel_Exception $e) {
$images = array();
- } else {
- // Eventually would like the link to link to a search
- // results page containing the same images present in this
- // feed. For now, just link to the List view until some of
- // the search code can be refactored.
- $params = array('last_modified' => $images[0]->uploaded,
- 'name' => sprintf(_("Recently added photos on %s"),
- $conf['server']['name']),
- 'link' => Ansel::getUrlFor('view',
- array('view' => 'List'),
- true),
- 'desc' => sprintf(_("Recently added photos on %s"),
- $conf['server']['name']),
- 'image_url' => Ansel::getImageUrl($images[0]->id,
- 'thumb', true),
- 'image_alt' => $images[0]->caption,
- 'image_link' => Ansel::getUrlFor(
- 'view', array('image' => $images[0]->id,
- 'view' => 'Image',
- 'gallery' => $images[0]->gallery),
- true));
}
+
+ // Eventually would like the link to link to a search
+ // results page containing the same images present in this
+ // feed. For now, just link to the List view until some of
+ // the search code can be refactored.
+ $params = array('last_modified' => $images[0]->uploaded,
+ 'name' => sprintf(_("Recently added photos on %s"),
+ $conf['server']['name']),
+ 'link' => Ansel::getUrlFor('view',
+ array('view' => 'List'),
+ true),
+ 'desc' => sprintf(_("Recently added photos on %s"),
+ $conf['server']['name']),
+ 'image_url' => Ansel::getImageUrl($images[0]->id,
+ 'thumb', true),
+ 'image_alt' => $images[0]->caption,
+ 'image_link' => Ansel::getUrlFor(
+ 'view', array('image' => $images[0]->id,
+ 'view' => 'Image',
+ 'gallery' => $images[0]->gallery),
+ true));
+
break;
case 'gallery':
} elseif (is_numeric($id)) {
$gallery = $ansel_storage->getGallery($id);
}
- if (!is_a($gallery, 'PEAR_Error') &&
- $gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) &&
+ if ($gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW) &&
!$gallery->hasPasswd() && $gallery->isOldEnough()) {
+
if (!$gallery->countImages() && $gallery->hasSubGalleries()) {
$subgalleries = $ansel_storage->listGalleries(Horde_Perms::SHOW,
null,
}
}
- if (!isset($images) || is_a($images, 'PEAR_Error') || !count($images)) {
+ if (!count($images)) {
$images = array();
} else {
$style = $gallery->getStyle();
'gallery' => $id),
true);
$img = &$ansel_storage->getImage($gallery->getDefaultImage('ansel_default'));
- if (is_a($img, 'PEAR_Error')) {
- break;
- }
$params = array('last_modified' => $gallery->get('last_modified'),
'name' => sprintf(_("%s on %s"),
$gallery->get('name'),
break;
case 'user':
- $shares = $ansel_storage->listGalleries(Horde_Perms::SHOW, $id);
- if (!is_a($shares, 'PEAR_Error')) {
- $galleries = array();
+ $galleries = array();
+ try {
+ $shares = $ansel_storage->listGalleries(Horde_Perms::SHOW, $id);
foreach ($shares as $gallery) {
if ($gallery->isOldEnough() && !$gallery->hasPasswd()) {
$galleries[] = $gallery->id;
}
}
+ } catch (Horde_Share_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
}
$images = array();
if (isset($galleries) && count($galleries)) {
- $images = $ansel_storage->getRecentImages($galleries);
- if (!is_a($images, 'PEAR_Error') && count($images)) {
+ try {
+ $images = $ansel_storage->getRecentImages($galleries);
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ }
+ if (count($images)) {
$owner = $injector->getInstance('Horde_Prefs_Identity')->getIdentity($id);
$name = $owner->getValue('fullname');
$author = $owner->getValue('from_addr');
$tag_id = array_values(Ansel_Tags::getTagIds(array($id)));
$images = Ansel_Tags::searchTagsById($tag_id, 10, 0, 'images');
$tag_id = array_pop($tag_id);
- $images = $ansel_storage->getImages(array('ids' => $images['images']));
- if (!is_a($images, 'PEAR_Error') && count($images)) {
+ try {
+ $images = $ansel_storage->getImages(array('ids' => $images['images']));
+ } catch (Ansel_Exception $e) {
+ Horde::logMessage($e->getMessage(), 'ERR');
+ $images = array();
+ }
+ if (count($images)) {
$tag_id = $tag_id[0];
$images = array_values($images);
$params = array('last_modified' => $images[0]->uploaded,
for ($i = 0; $i < $cnt; ++$i) {
$gallery_id = $images[$i]->gallery;
if (empty($galleries[$gallery_id])) {
- $galleries[$gallery_id]['gallery'] = $GLOBALS['ansel_storage']->getGallery($gallery_id);
- if (is_a($galleries[$gallery_id]['gallery'], 'PEAR_Error')) {
- continue;
- }
+ try {
+ $galleries[$gallery_id]['gallery'] = $GLOBALS['ansel_storage']->getGallery($gallery_id);
+ } catch (Ansel_Exception $e) {}
}
if (!isset($galleries[$gallery_id]['perm'])) {
$galleries[$gallery_id]['perm'] =