From 4ade7a3815a52c12068fb5d91ebea676ac2edbb8 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 17 Jul 2010 17:05:46 -0400 Subject: [PATCH] Galleries should only be able to adjust their own image counts. Not sure why this was done this way originally. We have to instantiate the "other" gallery anyway, so just do it the proper way and call updateImageCount() on the "other" gallery directly. --- ansel/lib/Gallery.php | 43 ++++++++++++------------------------------ ansel/lib/GalleryMode/Date.php | 9 ++++++--- ansel/lib/View/Base.php | 5 +++++ 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index ea360d9b4..674e4a6d3 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -147,47 +147,28 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical * * @param integer $images Number of images in action * @param boolean $add True if adding, false if removing - * @param integer $gallery_id Gallery id to update images for, if not self * * @return boolean true on success * @throws Ansel_Exception */ - public function updateImageCount($images, $add = true, $gallery_id = null) + public function updateImageCount($images, $add = true) { - if (is_null($gallery_id) || $gallery_id === $this->id) { - /* Updating self */ - if ($add) { - $this->data['attribute_images'] += $images; - } else { - $this->data['attribute_images'] -= $images; - } - try { - $this->save(); - } catch (Horde_Share_Exception $e) { - Horde::logMessage($e->getMessage, 'ERR'); - throw Ansel_Exception($e); - } + /* Updating self */ + if ($add) { + $this->data['attribute_images'] += $images; } else { - /* Updating other gallery */ - $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id); - $count = $g->get('images'); - if ($add) { - $count += $images; - } else { - $count['attribute_images'] -= $images; - } - try { - $g->save(); - } catch (Horde_Share_Exception $e) { - Horde::logMessage($e->getMessage, 'ERR'); - throw Ansel_Exception($e); - } + $this->data['attribute_images'] -= $images; + } + try { + $this->save(); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage, 'ERR'); + throw Ansel_Exception($e); } /* Need to expire the cache for the gallery that was changed */ if ($GLOBALS['conf']['ansel_cache']['usecache']) { - $id = (is_null($gallery_id) ? $this->id : $gallery_id); - $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $id); + $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id); } return true; diff --git a/ansel/lib/GalleryMode/Date.php b/ansel/lib/GalleryMode/Date.php index 109c44d6b..f6e7c317f 100644 --- a/ansel/lib/GalleryMode/Date.php +++ b/ansel/lib/GalleryMode/Date.php @@ -455,12 +455,13 @@ class Ansel_GalleryMode_Date /* Update the gallery counts for each affected gallery */ if ($this->_gallery->get('has_subgalleries')) { foreach ($gallery_ids as $id => $count) { - $this->_gallery->updateImageCount($count, false, $id); + $g = $GLOBALS['injector']->getInstance('Ansel_Storage')-getScope()->getGallery($id); + $g->updateImageCount($count, false); } } else { $this->_gallery->updateImageCount(count($ids), false); } - $this->_gallery->updateImageCount(count($ids), true, $gallery->id); + $gallery->updateImageCount(count($ids), true); /* Expire the cache since we have no reason to save() the gallery */ if ($GLOBALS['conf']['ansel_cache']['usecache']) { @@ -522,7 +523,9 @@ class Ansel_GalleryMode_Date $this->_gallery->getShareOb()->getWriteDb()->exec('DELETE FROM ansel_image_attributes WHERE image_id = ' . (int)$image->id); if (!$isStack) { - $this->_gallery->updateImageCount(1, false, $image_gallery); + $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope() + ->getGallery($image_gallery) + ->updateImageCount(1, false); } /* Update the modified flag if we are not a stack image */ diff --git a/ansel/lib/View/Base.php b/ansel/lib/View/Base.php index 050ab7905..8b49073eb 100644 --- a/ansel/lib/View/Base.php +++ b/ansel/lib/View/Base.php @@ -2,6 +2,11 @@ /** * The Ansel_View_Abstract:: Parent class for the various Ansel_View classes * + * Copyright 2008-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * * @author Chuck Hagenbuch * @author Michael J. Rubinsky * @package Ansel -- 2.11.0