/**
* Removes an Ansel_Gallery.
*
* @param Ansel_Gallery $gallery The gallery to delete
*
* @throws Ansel_Exception
*/
public function removeGallery(Ansel_Gallery $gallery)
{
// Get any children and empty them
$children = $gallery->getChildren(null, null, true);
foreach ($children as $child) {
$this->emptyGallery($child);
$child->setTags(array());
}
// Now empty the selected gallery of images
$this->emptyGallery($gallery);
// Clear all the tags.
$gallery->setTags(array());
// Get the parent, if it exists, before we delete the gallery.
$parent = $gallery->getParent();
$id = $gallery->id;
// Delete the gallery from storage
try {
$this->_shares->removeShare($gallery->getShare());
} catch (Horde_Share_Exception $e) {
throw new Ansel_Exception($e);
} catch (Horde_Exception_NotFound $e) {
throw new Ansel_Exception($e);
}
// Expire the cache
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $id);
}
// See if we need to clear the has_subgalleries field
if ($parent instanceof Ansel_Gallery) {
if (!$parent->countChildren($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, false)) {
$parent->set('has_subgalleries', 0, true);
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $parent->id);
}
}
}
}