From d186405c0090772d1c26788dad9ea973f0421390 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 08 Jun 2013 14:14:33 -0400
Subject: [PATCH] Simplified db connection initialisation code

---
 program/lib/Roundcube/rcube_db.php |   48 +++++++++---------------------------------------
 1 files changed, 9 insertions(+), 39 deletions(-)

diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index 597fa75..fe5ed39 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -100,27 +100,15 @@
 
         $this->db_dsnw_array = self::parse_dsn($db_dsnw);
         $this->db_dsnr_array = self::parse_dsn($db_dsnr);
-
-        // Initialize driver class
-        $this->init();
-    }
-
-    /**
-     * Initialization of the object with driver specific code
-     */
-    protected function init()
-    {
-        // To be used by driver classes
     }
 
     /**
      * Connect to specific database
      *
-     * @param array $dsn DSN for DB connections
-     *
-     * @return PDO database handle
+     * @param array  $dsn  DSN for DB connections
+     * @param string $mode Connection mode (r|w)
      */
-    protected function dsn_connect($dsn)
+    protected function dsn_connect($dsn, $mode)
     {
         $this->db_error     = false;
         $this->db_error_msg = null;
@@ -158,9 +146,10 @@
             return null;
         }
 
+        $this->dbh          = $dbh;
+        $this->db_mode      = $mode;
+        $this->db_connected = true;
         $this->conn_configure($dsn, $dbh);
-
-        return $dbh;
     }
 
     /**
@@ -180,16 +169,6 @@
      */
     protected function conn_configure($dsn, $dbh)
     {
-    }
-
-    /**
-     * Driver-specific database character set setting
-     *
-     * @param string $charset Character set name
-     */
-    protected function set_charset($charset)
-    {
-        $this->query("SET NAMES 'utf8'");
     }
 
     /**
@@ -219,23 +198,14 @@
 
         $dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array;
 
-        $this->dbh          = $this->dsn_connect($dsn);
-        $this->db_connected = is_object($this->dbh);
+        $this->dsn_connect($dsn, $mode);
 
         // use write-master when read-only fails
         if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) {
-            $mode = 'w';
-            $this->dbh          = $this->dsn_connect($this->db_dsnw_array);
-            $this->db_connected = is_object($this->dbh);
+            $this->dsn_connect($this->db_dsnw_array, 'w');
         }
 
-        if ($this->db_connected) {
-            $this->db_mode = $mode;
-            $this->set_charset('utf8');
-        }
-        else {
-            $this->conn_failure = true;
-        }
+        $this->conn_failure = !$this->db_connected;
     }
 
     /**

--
Gitblit v1.9.1