From 18a26b2cd852691e97feea60f81b3aacbc4a25b6 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 30 Dec 2010 14:16:26 -0500 Subject: [PATCH] Fix deleting cached images --- ansel/lib/Gallery.php | 8 +++---- ansel/lib/Image.php | 63 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 001e4a38e..44583c624 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -325,7 +325,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria } /** - * Removes all generated and cached 'prettythumb' thumbnails for this + * Removes all generated and cached thumbnails for this * gallery * * @return void @@ -335,7 +335,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria $images = $this->listImages(); foreach ($images as $id) { $image = $this->getImage($id); - $image->deleteCache('prettythumb'); + $image->deleteCache('thumb'); } } @@ -716,7 +716,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria /** * Return the style definition for this gallery. * - * @return array The style definition array. + * @return Ansel_Style The style definition array. */ public function getStyle() { @@ -742,7 +742,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria ($GLOBALS['browser']->hasQuirk('png_transparency') || $GLOBALS['conf']['image']['type'] != 'png')) { - return Ansel::getStyleDefinition('ansel_default'); + $style = Ansel::getStyleDefinition('ansel_default'); } return $style; diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index c20810cf8..d10d673b0 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -226,21 +226,34 @@ class Ansel_Image Implements Iterator * Return the vfs path for this image. * * @param string $view The view we want. - * @param Ansel_Style $style A named gallery style. + * @param Ansel_Style $style A gallery style. * * @return string The vfs path for this image. */ - public function getVFSPath($view = 'full', $style = null) + public function getVFSPath($view = 'full', Ansel_Style $style = null) { - $view = $this->getViewHash($view, $style); - return '.horde/ansel/' + return $this->getVFSPathFromHash($this->getViewHash($view, $style)); + } + + /** + * Generate a path on the VFS given a known style hash. + * + * @param string $hash The sytle hash + * + * @return string the VFS path to the directory for the provided hash + */ + public function getVFSPathFromHash($hash) + { + return '.horde/ansel/' . substr(str_pad($this->id, 2, 0, STR_PAD_LEFT), -2) - . '/' . $view; + . '/' . $hash; } /** * Returns the file name of this image as used in the VFS backend. * + * @param string $view The image view (full, screen, thumb, mini). + * * @return string This image's VFS file name. */ public function getVFSName($view) @@ -278,6 +291,7 @@ class Ansel_Image Implements Iterator if ($view == 'full' && !empty($this->_data['full'])) { $this->_image->loadString($this->_data['full']); $this->_loaded['full'] = true; + return true; } $viewHash = $this->getViewHash($view, $style); @@ -738,37 +752,36 @@ class Ansel_Image Implements Iterator */ public function deleteCache($view = 'all') { - /* Catch exceptions from VFS */ - try { - /* Delete cached screen image. (We don't care if the file is not found) */ - if ($view == 'all' || $view == 'screen') { - $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile( - $this->getVFSPath('screen'), $this->getVFSName('screen')); - } - /* Delete cached thumbnail. */ - if ($view == 'all' || $view == 'thumb') { + /* Delete cached screen image. (We don't care if the file is not found) */ + if ($view == 'all' || $view == 'screen') { + try { $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile( - $this->getVFSPath('thumb'), $this->getVFSName('thumb')); + $this->getVFSPath('screen'), $this->getVFSName('screen')); + } catch (VFS_Exception $e) { } + } - /* Delete cached mini image. */ - if ($view == 'all' || $view == 'mini') { + /* Delete cached mini image. */ + if ($view == 'all' || $view == 'mini') { + try { $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile( $this->getVFSPath('mini'), $this->getVFSName('mini')); + } catch (VFS_Exception $e) { } - - if ($view == 'all' || $view == 'prettythumb') { - $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); - $hashes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getHashes(); - foreach ($hashes as $hash) - { + } + if ($view == 'all' || $view == 'thumb') { + $hashes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getHashes(); + foreach ($hashes as $hash) + { + try { $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs') ->create('images') - ->deleteFile($this->getVFSPath($hash), $this->getVFSName($hash)); + ->deleteFile($this->getVFSPathFromHash($hash), $this->getVFSName('thumb')); + } catch (VFS_Exception $e) { } } - } catch (VFS_Exception $e) {} + } } /** -- 2.11.0