From 77b5d7ee304a688a2eb115ce04b460b43c0dd700 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 22 May 2016 08:43:54 -0400
Subject: [PATCH] Fix priority icon(s) position

---
 program/lib/Roundcube/rcube_session_memcache.php |   83 ++++++++++++++++++++++++++++++-----------
 1 files changed, 61 insertions(+), 22 deletions(-)

diff --git a/program/lib/Roundcube/rcube_session_memcache.php b/program/lib/Roundcube/rcube_session_memcache.php
index 85a4aa6..96fa529 100644
--- a/program/lib/Roundcube/rcube_session_memcache.php
+++ b/program/lib/Roundcube/rcube_session_memcache.php
@@ -1,6 +1,6 @@
 <?php
 
-/*
+/**
  +-----------------------------------------------------------------------+
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2005-2014, The Roundcube Dev Team                       |
@@ -15,7 +15,7 @@
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  | Author: Aleksander Machniak <alec@alec.pl>                            |
- | Author: Cor Bosman <cor@roundcu.be>                                   |
+ | Author: Cor Bosman <cor@roundcu.bet>                                  |
  +-----------------------------------------------------------------------+
 */
 
@@ -31,21 +31,28 @@
 class rcube_session_memcache extends rcube_session
 {
     private $memcache;
+    private $debug;
 
-    public function __construct()
+    /**
+     * @param Object $config
+     */
+    public function __construct($config)
     {
-        $this->memcache = rcube::get_instance()->get_memcache();
+        parent::__construct($config);
 
-        if(! $this->memcache) {
-            rcube::raise_error(array('code' => 604, 'type' => 'db',
-                                   'line' => __LINE__, 'file' => __FILE__,
-                                   'message' => "Failed to connect to memcached. Please check configuration"),
-                               true, true);
+        $this->memcache = rcube::get_instance()->get_memcache();
+        $this->debug    = $config->get('memcache_debug');
+
+        if (!$this->memcache) {
+            rcube::raise_error(array(
+                    'code' => 604, 'type' => 'db',
+                    'line' => __LINE__, 'file' => __FILE__,
+                    'message' => "Failed to connect to memcached. Please check configuration"),
+                true, true);
         }
 
         // register sessions handler
         $this->register_session_handler();
-
     }
 
     /**
@@ -76,12 +83,15 @@
     {
         if ($key) {
             // #1488592: use 2nd argument
-            $this->memcache->delete($key, 0);
+            $result = $this->memcache->delete($key, 0);
+
+            if ($this->debug) {
+                $this->debug('delete', $key, null, $result);
+            }
         }
 
         return true;
     }
-
 
     /**
      * Read session data from memcache
@@ -97,32 +107,42 @@
             $this->ip      = $arr['ip'];
             $this->vars    = $arr['vars'];
             $this->key     = $key;
-
-            return !empty($this->vars) ? (string) $this->vars : '';
         }
 
-        return null;
+        if ($this->debug) {
+            $this->debug('get', $key, $value);
+        }
+
+        return $this->vars ?: '';
     }
 
     /**
-     * write data to memcache storage
+     * Write data to memcache storage
      *
      * @param $key
      * @param $vars
+     *
      * @return bool
      */
     public function write($key, $vars)
     {
-        return $this->memcache->set($key, serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars)),
-                                    MEMCACHE_COMPRESSED, $this->lifetime + 60);
+        $data   = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars));
+        $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60);
+
+        if ($this->debug) {
+            $this->debug('set', $key, $data, $result);
+        }
+
+        return $result;
     }
 
     /**
-     * update memcache session data
+     * Update memcache session data
      *
      * @param $key
      * @param $newvars
      * @param $oldvars
+     *
      * @return bool
      */
     public function update($key, $newvars, $oldvars)
@@ -130,11 +150,30 @@
         $ts = microtime(true);
 
         if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 3) {
-            return $this->memcache->set($key, serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)),
-                                        MEMCACHE_COMPRESSED, $this->lifetime + 60);
+            $data   = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars));
+            $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60);
+
+            if ($this->debug) {
+                $this->debug('set', $key, $data, $result);
+            }
+
+            return $result;
         }
 
         return true;
     }
 
-}
\ No newline at end of file
+    /**
+     * Write memcache debug info to the log
+     */
+    protected function debug($type, $key, $data = null, $result = null)
+    {
+        $line = strtoupper($type) . ' ' . $key;
+
+        if ($data !== null) {
+            $line .= ' ' . $data;
+        }
+
+        rcube::debug($this->type, $line, $result);
+    }
+}

--
Gitblit v1.9.1