From e48f8945b32ab5b67f1cdeb53a37d3d196e31e4d Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 20 May 2016 05:19:01 -0400
Subject: [PATCH] Fix bug where message list columns could be in wrong order after column drag-n-drop and list sorting

---
 program/lib/Roundcube/rcube_cache_shared.php |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/program/lib/Roundcube/rcube_cache_shared.php b/program/lib/Roundcube/rcube_cache_shared.php
index fa29b54..32ce4e8 100644
--- a/program/lib/Roundcube/rcube_cache_shared.php
+++ b/program/lib/Roundcube/rcube_cache_shared.php
@@ -161,7 +161,7 @@
         // Remove all keys
         if ($key === null) {
             $this->cache         = array();
-            $this->cache_changed = false;
+            $this->cache_changed = true;
             $this->cache_changes = array();
             $this->cache_sums    = array();
         }
@@ -237,6 +237,9 @@
         }
 
         $this->write_index();
+
+        // reset internal cache index, thanks to this we can force index reload
+        $this->index = null;
     }
 
 
@@ -338,7 +341,15 @@
         }
 
         if ($this->type == 'memcache' || $this->type == 'apc') {
-            return $this->add_record($this->ckey($key), $data);
+            $result = $this->add_record($this->ckey($key), $data);
+
+            // make sure index will be updated
+            if ($result && !array_key_exists($key, $this->cache_sums)) {
+                $this->cache_changed    = true;
+                $this->cache_sums[$key] = true;
+            }
+
+            return $result;
         }
 
         $key_exists = array_key_exists($key, $this->cache_sums);
@@ -496,10 +507,15 @@
 
         // Make sure index contains new keys
         foreach ($this->cache as $key => $value) {
-            if ($value !== null) {
-                if (array_search($key, $this->index) === false) {
-                    $this->index[] = $key;
-                }
+            if ($value !== null && !in_array($key, $this->index)) {
+                $this->index[] = $key;
+            }
+        }
+
+        // new keys added using self::write()
+        foreach ($this->cache_sums as $key => $value) {
+            if ($value === true && !in_array($key, $this->index)) {
+                $this->index[] = $key;
             }
         }
 

--
Gitblit v1.9.1