From 6bb44a644ad9a256f2cd154cfbdb7bdfede3fa6a Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 20 Jun 2012 12:39:54 -0400
Subject: [PATCH] Initialize rcube instance (with options); no caches without a valid user_id

---
 program/include/rcube.php      |    7 ++++---
 program/include/rcube_imap.php |    4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/program/include/rcube.php b/program/include/rcube.php
index 1bfe93d..3b16015 100644
--- a/program/include/rcube.php
+++ b/program/include/rcube.php
@@ -106,12 +106,14 @@
   /**
    * This implements the 'singleton' design pattern
    *
+   * @param integer Options to initialize with this instance. See rcube::INIT_WITH_* constants
    * @return rcube The one and only instance
    */
-  static function get_instance()
+  static function get_instance($mode = 0)
   {
     if (!self::$instance) {
       self::$instance = new rcube();
+      self::$instance->init($mode);
     }
 
     return self::$instance;
@@ -240,8 +242,7 @@
    */
   public function get_cache($name, $type='db', $ttl=0, $packed=true)
   {
-    if (!isset($this->caches[$name])) {
-      $userid = $this->get_user_id();
+    if (!isset($this->caches[$name]) && ($userid = $this->get_user_id())) {
       $this->caches[$name] = new rcube_cache($type, $userid, $name, $ttl, $packed);
     }
 
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 00a4158..57b85c3 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3742,9 +3742,9 @@
     {
         if ($this->messages_caching && !$this->mcache) {
             $rcube = rcube::get_instance();
-            if ($dbh = $rcube->get_dbh()) {
+            if (($dbh = $rcube->get_dbh()) && ($userid = $rcube->get_user_id())) {
                 $this->mcache = new rcube_imap_cache(
-                    $dbh, $this, $rcube->get_user_id(), $this->options['skip_deleted']);
+                    $dbh, $this, $userid, $this->options['skip_deleted']);
             }
         }
 

--
Gitblit v1.9.1