More thorough checks for when we need to reset/remove a key image.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 9 Sep 2010 14:27:26 +0000 (10:27 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 9 Sep 2010 14:27:26 +0000 (10:27 -0400)
ansel/gallery/delete.php
ansel/lib/Gallery.php
ansel/lib/View/GalleryRenderer/Gallery.php

index 9befd25..778b2e5 100644 (file)
@@ -32,9 +32,7 @@ if ($galleryId) {
         } else {
             try {
                 $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->removeGallery($gallery);
-                $notification->push(sprintf(
-                    _("Successfully deleted %s."),
-                    $gallery->get('name')), 'horde.success');
+                $notification->push(sprintf(_("Successfully deleted %s."), $gallery->get('name')), 'horde.success');
             } catch (Ansel_Exception $e) {
                 $notification->push(sprintf(
                     _("There was a problem deleting %s: %s"),
index 99225fb..5e4da3b 100644 (file)
@@ -165,6 +165,11 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             throw Ansel_Exception($e);
         }
 
+        /* Make sure we get rid of key image/stacks if no more images */
+        if (!$this->data['attribute_images']) {
+            $this->resetKeyImage();
+        }
+
         /* Need to expire the cache for the gallery that was changed */
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
@@ -334,6 +339,19 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
     }
 
     /**
+     * Reset the gallery's key image. This will force Ansel to attempt to fetch
+     * a new key image the next time one is requested.
+     *
+     */
+    public function resetKeyImage()
+    {
+        $this->clearStacks();
+        $this->set('default', 0);
+        $this->set('default_type', 'auto');
+        $this->save();
+    }
+
+    /**
      * Move images from this gallery to a new gallery.
      *
      * @param array $images          An array of image ids.
@@ -835,6 +853,9 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             if ($cnt == 1) {
                 /* Count is 1, and we are about to delete it */
                 $reset_has_subgalleries = true;
+                if (!$old->countImages()) {
+                    $old->resetKeyImage();
+                }
             }
         }
 
index 8ab7e05..db63dd9 100644 (file)
@@ -91,10 +91,6 @@ class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer_Base
 
         $pager = new Horde_Core_Ui_Pager('page', $vars, $params);
 
-        // Note that we can't use Horde_Util::bufferOutput() here since the
-        // include file would be included inside that method's scope, and not
-        // this one.
-        //ob_start();
         Horde::startBuffer();
         if (!empty($this->view->api)) {
             $includes = $GLOBALS['injector']->createInstance('Horde_Script_Files');