From 9d0a8aeab9018d7aa374ce7d903a59a98fa79a6a Mon Sep 17 00:00:00 2001
From: Frank Febbraro <frank@phase2technology.com>
Date: Sat, 12 Mar 2011 19:59:20 -0500
Subject: [PATCH] Issue #1090682 by febbraro: view:load does not clear the cache correctly when reset

---
 includes/view.inc |   63 +++++++++++++++++++++++++---------------------------
 1 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/includes/view.inc b/includes/view.inc
index 9e0f44f..3596551 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -1305,42 +1305,39 @@ class view extends views_db_object {
         ->fields('v')
         ->condition(is_numeric($arg) ? 'vid' : 'name', $arg)
         ->execute();
-      foreach ($result as $data) {
-        if (empty($data)) {
-          $cache[$arg] = NULL;
-        }
-        else {
-          $view = new view();
-          $view->load_row($data);
-          $view->type = t('Normal');
-          // Load all of our subtables.
-          foreach ($view->db_objects() as $key) {
-            $object_name = "views_$key";
-            $result = db_select($object_name, 'v')
-              ->fields('v')
-              ->condition('vid', $view->vid)
-              ->orderBy('position')
-              ->execute();
-            foreach ($result as $data) {
-              $object = new $object_name(FALSE);
-              $object->load_row($data);
-
-              // Because it can get complicated with this much indirection,
-              // make a shortcut reference.
-              $location = &$view->$key;
-
-              // If we have a basic id field, load the item onto the view based on
-              // this ID, otherwise push it on.
-              if (!empty($object->id)) {
-                $location[$object->id] = $object;
-              }
-              else {
-                $location[] = $object;
-              }
+      if ($result->rowCount() == 0) {
+        $cache[$arg] = NULL;
+      }
+      else {
+        $view = new view();
+        $view->load_row($result->fetchObject());
+        $view->type = t('Normal');
+        // Load all of our subtables.
+        foreach ($view->db_objects() as $key) {
+          $object_name = "views_$key";
+          $result = db_select($object_name, 'v')
+            ->fields('v')
+            ->condition('vid', $view->vid)
+            ->orderBy('position')
+            ->execute();
+          foreach ($result as $data) {
+            $object = new $object_name(FALSE);
+            $object->load_row($data);
+
+            // Because it can get complicated with this much indirection,
+            // make a shortcut reference.
+            $location = &$view->$key;
+
+            // If we have a basic id field, load the item onto the view based on
+            // this ID, otherwise push it on.
+            if (!empty($object->id)) {
+              $location[$object->id] = $object;
+            }
+            else {
+              $location[] = $object;
             }
           }
         }
-
         $view->loaded = TRUE;
         $cache[$arg] = $view;
       }
-- 
1.7.3.2

