Galleries should only be able to adjust their own image counts.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 17 Jul 2010 21:05:46 +0000 (17:05 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 18 Jul 2010 16:20:53 +0000 (12:20 -0400)
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
ansel/lib/GalleryMode/Date.php
ansel/lib/View/Base.php

index ea360d9..674e4a6 100644 (file)
@@ -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;
index 109c44d..f6e7c31 100644 (file)
@@ -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 */
index 050ab79..8b49073 100644 (file)
@@ -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 <chuck@horde.org>
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Ansel