/**
* Empties a gallery of all images.
*
* @param Ansel_Gallery $gallery The ansel gallery to empty.
*
* @throws Ansel_Exception
*/
public function emptyGallery(Ansel_Gallery $gallery)
{
$gallery->clearStacks();
$images = $gallery->listImages();
foreach ($images as $image) {
// Pretend we are a stack so we don't update the images count
// for every image deletion, since we know the end result will
// be zero.
try {
$gallery->removeImage($image, true);
} catch (Horde_Exception_NotFound $e) {
// Don't worry about missing images since we are deleting them
// anyway.
Horde::log($e->getMessage(), 'ERR');
}
}
$gallery->set('images', 0, true);
// Clear the OtherGalleries widget cache
if ($GLOBALS['conf']['ansel_cache']['usecache']) {
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
$GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
}
}