}
// Check for slug uniqueness
- $slugGalleryId = $GLOBALS['injector']->getInstance('Ansel_Storage')->slugExists($this->data['attribute_slug']);
+ $slugGalleryId = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryIdFromSlug($this->data['attribute_slug']);
if ($slugGalleryId > 0 && $slugGalleryId <> $this->id) {
throw InvalidArgumentException(
sprintf(_("Could not save gallery, the slug, \"%s\", already exists."),
/* Check for slug uniqueness */
if (!empty($attributes['slug']) &&
- $this->slugExists($attributes['slug'])) {
+ $this->galleryExists(null, $attributes['slug'])) {
throw new Horde_Exception(sprintf(_("The slug \"%s\" already exists."), $attributes['slug']));
}
*
* @return integer The share_id the slug represents, or 0 if not found.
*/
- public function slugExists($slug)
+ public function getGalleryIdFromSlug($slug)
{
// An empty slug should never match.
if (!strlen($slug)) {
*/
public function getGalleryBySlug($slug, $overrides = array())
{
- $id = $this->slugExists($slug);
+ $id = $this->getGalleryIdFromSlug($slug);
if ($id) {
return $this->getGallery($id, $overrides);
} else {
}
/**
- * Check if a gallery exists. Need to do this here instead of Horde_Share
- * since Horde_Share_Base::exists() takes a share_name, not a share_id. We
- * might also be checking by gallery_slug and this is more efficient than
- * a listShares() call for one gallery.
+ * Check if a gallery exists. Need to do this here so we can also check by
+ * gallery slug.
*
* @param integer $gallery_id The gallery id
* @param string $slug The gallery slug
* @return boolean
* @throws Ansel_Exception
*/
- public function galleryExists($gallery_id, $slug = null)
+ public function galleryExists($gallery_id = null, $slug = null)
{
if (empty($slug)) {
- $results = $this->_db->queryOne(
- 'SELECT COUNT(share_id) FROM ' . $this->_shares->getTable()
- . ' WHERE share_id = ' . (int)$gallery_id);
- if ($results instanceof PEAR_Error) {
- throw new Ansel_Exception($results);
- }
-
- return (bool)$results;
+ $results = $this->_shares->exists($gallery_id);
} else {
-
- return (bool)$this->slugExists($slug);
+ $results = $this->_shares->countShares($GLOBALS['registry']->getAuth(), Horde_Perms::READ, array('slug' => $slug));
}
+
+ return (bool)$results;
}
/**