From: Michael J. Rubinsky Date: Thu, 16 Sep 2010 21:25:51 +0000 (-0400) Subject: Fix image cache clearing with new style code. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f9f124904165a010eeb62f0ad057a0e3b31b001d;p=horde.git Fix image cache clearing with new style code. Need to store all style hashes that the server knows about, so we can be sure to delete all cached thumbnails from the VFS. --- diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index 7c625f182..da77f7ca2 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -753,24 +753,13 @@ class Ansel_Image Implements Iterator } if ($view == 'all' || $view == 'prettythumb') { - - /* No need to try to delete a hash we already removed */ - $deleted = array(); - - /* Need to generate hashes for each possible style */ - // @TODO: Need to save the style hash to the share entry - // since we don't require the use of predefined - // style definitions now. $styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel'); - foreach ($styles as $style) + $hashes = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getHashes(); + foreach ($hashes as $hash) { - $hash = md5($style['thumbstyle'] . '.' . $style['background']); - if (empty($deleted[$hash])) - { - $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->deleteFile( - $this->getVFSPath($hash), $this->getVFSName($hash)); - $deleted[$hash] = true; - } + $GLOBALS['injector']->getInstance('Horde_Vfs') + ->getVfs('images') + ->deleteFile($this->getVFSPath($hash), $this->getVFSName($hash)); } } } catch (VFS_Exception $e) {} diff --git a/ansel/lib/Storage.php b/ansel/lib/Storage.php index e1da9d218..805302ea4 100644 --- a/ansel/lib/Storage.php +++ b/ansel/lib/Storage.php @@ -1145,4 +1145,37 @@ class Ansel_Storage return implode(', ', $fields); } + /** + * Ensure the style hash is recorded in the database. + * + * @param string $hash The hash to record. + * + * @return void + */ + public function ensureHash($hash) + { + $query = $this->_db->prepare('SELECT COUNT(*) FROM ansel_hashes WHERE style_hash = ?'); + $results = $query->execute($hash); + if ($results instanceof PEAR_Error) { + throw new Ansel_Exception($results->getMessage()); + } + if (!$results->fetchOne()) { + $query = $this->_db->prepare('INSERT INTO ansel_hashes (style_hash) VALUES(?)'); + $results = $query->execute($hash); + if ($results instanceof PEAR_Error) { + throw new Ansel_Exception($results->getMessage()); + } + } + } + + /** + * Get a list of all known styleHashes. + * + * @return array An array of style hashes. + */ + public function getHashes() + { + $hashes = $this->_db->query('SELECT style_hash FROM ansel_hashes;'); + } + } diff --git a/ansel/lib/View/GalleryProperties.php b/ansel/lib/View/GalleryProperties.php index 067f61df3..d94adabe7 100644 --- a/ansel/lib/View/GalleryProperties.php +++ b/ansel/lib/View/GalleryProperties.php @@ -364,6 +364,11 @@ class Ansel_View_GalleryProperties } + // Make sure that the style hash is recorded, ignoring non-styled thumbs + if ($style->thumbstyle != 'Thumb') { + $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->ensureHash($gallery->getViewHash('prettythumb')); + } + // Clear the OtherGalleries widget cache if ($GLOBALS['conf']['ansel_cache']['usecache']) { $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));