Use Horde_Db_Pear injector as much as possible
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 12 Aug 2010 19:26:34 +0000 (13:26 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 12 Aug 2010 19:48:20 +0000 (13:48 -0600)
35 files changed:
beatnik/lib/Driver/pdnsgsql.php
beatnik/lib/Driver/sql.php
crumb/lib/Driver/sql.php
fima/lib/Driver/sql.php
folks/lib/Driver/sql.php
folks/lib/Friends/sql.php
framework/Core/lib/Horde/Core/Factory/DbPear.php
framework/Core/lib/Horde/Core/Factory/Vfs.php
framework/DataTree/DataTree/sql.php
framework/Form/Form/Type.php
framework/Model/lib/Horde/Form.php
framework/VFS/lib/VFS/sql.php
framework/VFS/lib/VFS/sql_file.php
hermes/lib/Driver/sql.php
hylax/lib/Storage/sql.php
ingo/lib/Storage/Sql.php
jonah/lib/Driver/Sql.php
jonah/lib/News/sql.php
kronolith/lib/Driver/Sql.php
kronolith/lib/Geo/Sql.php
kronolith/lib/Storage/sql.php
luxor/lib/Driver/sql.php
mnemo/lib/Driver/sql.php
news/lib/Driver/sql.php
operator/lib/Driver/asterisksql.php
pastie/lib/Driver/Sql.php
shout/lib/Driver/Sql.php
skoli/lib/Driver/sql.php
turba/scripts/import_squirrelmail_sql_abook.php
turba/scripts/upgrades/2.1_to_2.2_sql_schema.php
vilma/lib/Driver/qmailldap.php
vilma/lib/Driver/sql.php
whups/lib/Driver/sql.php
whups/scripts/bugzilla-import.php
wicked/lib/Driver/sql.php

index 6129164..62b3a99 100644 (file)
@@ -417,7 +417,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      *
      * @access private
      *
-     * @return boolean  True on success; exits (Horde::fatal()) on error.
+     * @return boolean  True on success.
      */
     function _connect()
     {
@@ -425,54 +425,8 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
             return true;
         }
 
-        try {
-            $result = Horde::assertDriverConfig($this->_params, 'pdnsqsql', array('phptype'), 'PowerDNS Generic SQL');
-        } catch (Exception $e) {
-            Horde::logMessage($e, 'ERR');
-            throw $e;
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
-
-        $this->_connected = true;
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage');
 
         return true;
     }
index 395f8a1..b75c0ba 100644 (file)
@@ -214,7 +214,7 @@ class Beatnik_Driver_sql extends Beatnik_Driver
      *
      * @access private
      *
-     * @return boolean  True on success; exits (Horde::fatal()) on error.
+     * @return boolean  True on success.
      */
     function _connect()
     {
@@ -222,60 +222,8 @@ class Beatnik_Driver_sql extends Beatnik_Driver
             return true;
         }
 
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
-
-        $this->_connected = true;
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'beatnik', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'beatnik', 'storage');
 
         return true;
     }
index 9ebd329..d12dbd1 100644 (file)
@@ -102,60 +102,8 @@ class Crumb_Driver_sql extends Crumb_Driver {
             return true;
         }
 
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset', 'table'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            throw new Horde_Exception_Prior($this->_write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                throw new Horde_Exception_Prior($this->_write_db);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
-
-        $this->_connected = true;
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'crumb', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'crumb', 'storage');
 
         return true;
     }
index 23dc94f..af87652 100644 (file)
@@ -1052,38 +1052,12 @@ class Fima_Driver_sql extends Fima_Driver {
      */
     function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        /* Set DB portability options. */
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'fima', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
-        $this->_connected = true;
-
         return true;
     }
 
index 6777d50..3872fad 100644 (file)
@@ -567,61 +567,12 @@ class Folks_Driver_sql extends Folks_Driver {
      * Attempts to open a persistent connection to the SQL server.
      *
      * @return boolean  True on success.
+     * @throws Horde_Exception
      */
     private function _connect()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset', 'table'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Horde_Exception_Prior($this->_write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Horde_Exception_Prior($this->_db);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage');
 
         return true;
     }
index 8bd989d..e3c6f00 100644 (file)
@@ -197,66 +197,17 @@ class Folks_Friends_sql extends Folks_Friends {
      * Attempts to open a persistent connection to the SQL server.
      *
      * @return boolean  True on success.
+     * @throws Horde_Exception
      */
     protected function _connect()
     {
-        $this->_params = Horde::getDriverConfig('storage', 'sql');
+        $this->_params = array_merge(array(
+            'blacklist' => 'folks_blacklist',
+            'friends' => 'folks_friends'
+        ), $this->_params);
 
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['friends'])) {
-            $this->_params['friends'] = 'folks_friends';
-        }
-        if (!isset($this->_params['blacklist'])) {
-            $this->_params['blacklist'] = 'folks_blacklist';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Horde_Exception_Prior($this->_write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Horde_Exception_Prior($this->_db);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'folks', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'folks', 'storage');
 
         return true;
     }
index 7a72fbb..166cad9 100644 (file)
@@ -55,35 +55,56 @@ class Horde_Core_Factory_DbPear
      * Return the DB instance.
      *
      * @param string $type  Either 'read' or 'rw'.
+     * @param string $app   The application.
+     * @param mixed $type   The type. If this is an array, this is used as
+     *                      the configuration array.
      *
      * @return DB  The singleton DB instance.
      * @throws Horde_Exception
      */
-    public function getDb($type = 'rw')
+    public function getDb($type = 'rw', $app = 'horde', $type = null)
     {
-        if (isset($this->_instances[$type])) {
-            return $this->_instances[$type];
+        global $registry;
+
+        $sig = hash('md5', serialize($type . '|' . $app . '|' . $type));
+
+        if (isset($this->_instances[$sig])) {
+            return $this->_instances[$sig];
+        }
+
+        $pushed = ($app == 'horde')
+            ? false
+            : $registry->pushApp($app);
+
+        $config = is_array($type)
+            ? $type
+            : $this->getConfig($type);
+
+        /* Determine if we we are not using splitread or if we are using the
+         * base SQL config. */
+        if ((($type == 'read') && empty($config['splitread'])) ||
+            (isset($config['driverconfig']) &&
+             ($config['driverconfig'] == 'horde'))) {
+            $this->_instances[$sig] = $this->getDb($type);
+            return $this->_instances[$sig];
         }
 
-        $params = array_merge(array(
-            'database' => '',
-            'hostspec' => '',
-            'password' => '',
-            'username' => ''
-        ), $GLOBALS['conf']['sql']);
         if ($type == 'read') {
-            $params = array_merge($params, $params['read']);
+            $config = array_merge($config, $config['read']);
         }
 
-        Horde::assertDriverConfig($params, 'sql', array('charset', 'phptype'), 'SQL');
+        Horde::assertDriverConfig($config, 'sql', array('charset', 'phptype'));
 
         /* Connect to the SQL server using the supplied parameters. */
-        $db = DB::connect($params, array(
-            'persistent' => !empty($params['persistent']),
-            'ssl' => !empty($params['ssl'])
+        $db = DB::connect($config, array(
+            'persistent' => !empty($config['persistent']),
+            'ssl' => !empty($config['ssl'])
         ));
 
         if ($db instanceof PEAR_Error) {
+            if ($pushed) {
+                $registry->popApp();
+            }
             throw new Horde_Exception($db);
         }
 
@@ -98,9 +119,20 @@ class Horde_Core_Factory_DbPear
             break;
         }
 
-        $this->_instances[$type] = $db;
+        if ($pushed) {
+            $registry->popApp();
+        }
+
+        $this->_instances[$sig] = $db;
 
         return $db;
     }
 
+    /**
+     */
+    public function getConfig($type)
+    {
+        return Horde::getDriverConfig($type, 'sql');
+    }
+
 }
index 64e310d..c1b2b47 100644 (file)
@@ -85,8 +85,19 @@ class Horde_Core_Factory_Vfs
             ? $conf['vfs']
             : $conf[$name];
 
-        if ($vfs['type'] == 'sql') {
-            $vfs['params'] = Horde::getDriverConfig($name, 'sql');
+        switch ($vfs['type']) {
+        case 'sql':
+            $db_pear = $this->_injector->getInstance('Horde_Db_Pear');
+            $vfs['db'] = $db_pear->getDb('read', 'horde', 'vfs');
+            $vfs['writedb'] = $db_pear->getDb('rw', 'horde', 'vfs');
+            $vfs['params'] = $db_pear->getConfig('vfs');
+            break;
+
+        case 'sql_file':
+            $db_pear = $this->_injector->getInstance('Horde_Db_Pear');
+            $vfs['db'] = $db_pear->getDb('rw', 'horde', 'vfs');
+            $vfs['params'] = $db_pear->getConfig('vfs');
+            break;
         }
 
         return $vfs;
index d0e5162..6c3820b 100644 (file)
@@ -1848,61 +1848,21 @@ class DataTree_sql extends DataTree {
     /**
      * Attempts to open a connection to the SQL server.
      *
-     * @return boolean  True.
+     * @return mixed  True or PEAR_Error.
      */
     function _init()
     {
-        Horde::assertDriverConfig($this->_params, 'sql',
-            array('phptype', 'charset'),
-            'DataTree SQL');
-
-        $default = array(
-            'database' => '',
-            'username' => '',
-            'password' => '',
-            'hostspec' => '',
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'datatree');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'datatree');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
+
+        $this->_params = array_merge(array(
             'table' => 'horde_datatree',
             'table_attributes' => 'horde_datatree_attributes',
-        );
-        $this->_params = array_merge($default, $this->_params);
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = DB::connect($this->_params,
-                                       array('persistent' => !empty($this->_params['persistent']),
-                                             'ssl' => !empty($this->_params['ssl'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            return $this->_write_db;
-        }
-
-        // Set DB portability options.
-        $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS;
-        if ($this->_write_db->phptype == 'mssql') {
-            $portability |= DB_PORTABILITY_RTRIM;
-        }
-        $this->_write_db->setOption('portability', $portability);
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                     array('persistent' => !empty($params['persistent']),
-                                           'ssl' => !empty($params['ssl'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                return $this->_db;
-            }
-
-            // Set DB portability options
-            $portability = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS;
-            if ($this->_db->phptype == 'mssql') {
-                $portability |= DB_PORTABILITY_RTRIM;
-            }
-            $this->_db->setOption('portability', $portability);
-        } else {
-            /* Default to the same DB handle for reads. */
-            $this->_db = $this->_write_db;
-        }
+        ), $this->_params);
 
         return true;
     }
index 713413c..98e06d4 100644 (file)
@@ -3592,21 +3592,21 @@ class Horde_Form_Type_dblookup extends Horde_Form_Type_enum {
 
     function init($dsn, $sql, $prompt = null)
     {
-        require_once 'DB.php';
         $values = array();
         $db = DB::connect($dsn);
-        if (!is_a($db, 'PEAR_Error')) {
+        if (!($db instanceof PEAR_Error)) {
             // Set DB portability options.
             switch ($db->phptype) {
             case 'mssql':
                 $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
                 break;
+
             default:
                 $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
             }
 
             $col = $db->getCol($sql);
-            if (!is_a($col, 'PEAR_Error')) {
+            if (!($col instanceof PEAR_Error)) {
                 $values = array_combine($col, $col);
             }
         }
index 6eec231..89f8d21 100644 (file)
@@ -3029,18 +3029,20 @@ class Horde_Form_Type_dblookup extends Horde_Form_Type_enum {
     {
         $values = array();
         $db = DB::connect($dsn);
-        if (!is_a($db, 'PEAR_Error')) {
+        if (!($db instanceof PEAR_Error)) {
             // Set DB portability options.
             switch ($db->phptype) {
             case 'mssql':
                 $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
                 break;
+
             default:
                 $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+                break;
             }
 
             $col = $db->getCol($sql);
-            if (!is_a($col, 'PEAR_Error')) {
+            if (!($col instanceof PEAR_Error)) {
                 $values = array_combine($col, $col);
             }
         }
index fdb374f..1c11634 100644 (file)
@@ -3,28 +3,18 @@
  * VFS implementation for PHP's PEAR database abstraction layer.
  *
  * Required values for $params:<pre>
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).</pre>
+ * db - (DB) A DB object.
+ * </pre>
  *
  * Optional values:<pre>
  * table - (string) The name of the vfs table in 'database'. Defaults to
- *         'horde_vfs'.</pre>
- *
- * Required by some database implementations:<pre>
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.</pre>
+ *         'horde_vfs'.
+ * </pre>
  *
  * Optional values when using separate reading and writing servers, for example
  * in replication settings:<pre>
- * splitread - (boolean) Whether to implement the separation or not.
- * read - (array) Parameters which are different for the read database
- *                connection, currently supported only 'hostspec' and 'port'
- *                parameters.</pre>
+ * writedb - (DB) A writable DB object
+ * </pre>
  *
  * The table structure for the VFS can be found in data/vfs.sql.
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package VFS
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package  VFS
  */
 class VFS_sql extends VFS
 {
@@ -701,82 +693,21 @@ class VFS_sql extends VFS
     protected function _connect()
     {
         if ($this->_connected) {
-            return true;
+            return;
         }
 
-        if (!is_array($this->_params)) {
-            throw new VFS_Exception('No configuration information specified for SQL VFS.');
-        }
-
-        $required = array('phptype');
-        foreach ($required as $val) {
-            if (!isset($this->_params[$val])) {
-                throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val));
-            }
+        if (!isset($this->_params['db'])) {
+            throw new VFS_Exception('Required "db" not specified in VFS configuration.');
         }
 
         $this->_params = array_merge(array(
-            'database' => '',
-            'hostspec' => '',
-            'table' => 'horde_vfs',
-            'username' => ''
+            'table' => 'horde_vfs'
         ), $this->_params);
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = DB::connect(
-            $this->_params,
-            array(
-                'persistent' => !empty($this->_params['persistent']),
-                'ssl' => !empty($this->_params['ssl']
-            )
-        ));
-
-        if ($this->_write_db instanceof PEAR_Error) {
-            $this->log($this->_write_db, PEAR_LOG_ERR);
-            $error = new VFS_Exception($this->_write_db->getMessage());
-            $this->_write_db = false;
-            throw $error;
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect(
-                $params,
-                array(
-                    'persistent' => !empty($params['persistent']),
-                    'ssl' => !empty($params['ssl']
-                )
-            ));
-
-            if ($this->_db instanceof PEAR_Error) {
-                throw new VFS_Exception($this->_db->getMessage());
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for reads. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $this->_params['db'];
+        $this->_write_db = isset($this->_params['writedb'])
+            ? $this->_params['writedb']
+            : $this->_params['db'];
 
         $this->_connected = true;
     }
index 8143a01..39a3126 100644 (file)
@@ -13,7 +13,7 @@ include_once 'VFS/file.php';
  * layer and local file system for file storage.
  *
  * Required values for $params:<pre>
- * phptype - (string) The database type (ie. 'pgsql', 'mysql', etc.).
+ * db - (DB) The DB object.
  * vfsroot - (string) The root directory of where the files should be
  *           actually stored.</pre>
  *
@@ -21,21 +21,11 @@ include_once 'VFS/file.php';
  * table - (string) The name of the vfs table in 'database'. Defaults to
  *         'horde_vfs'.</pre>
  *
- * Required by some database implementations:<pre>
- * hostspec - (string) The hostname of the database server.
- * protocol - (string) The communication protocol ('tcp', 'unix', etc.).
- * database - (string) The name of the database.
- * username - (string) The username with which to connect to the database.
- * password - (string) The password associated with 'username'.
- * options - (array) Additional options to pass to the database.
- * tty - (string) The TTY on which to connect to the database.
- * port - (integer) The port on which to connect to the database.</pre>
+ * The table structure for the VFS can be found in data/vfs.sql.
  *
- * The table structure for the VFS can be found in
- * data/vfs.sql.
- *
- * @author  Michael Varghese <mike.varghese@ascellatech.com>
- * @package VFS
+ * @author   Michael Varghese <mike.varghese@ascellatech.com>
+ * @category Horde
+ * @package  VFS
  */
 class VFS_sql_file extends VFS_file
 {
@@ -624,11 +614,7 @@ class VFS_sql_file extends VFS_file
             return;
         }
 
-        if (!is_array($this->_params)) {
-            throw new VFS_Exception('No configuration information specified for SQL-File VFS.');
-        }
-
-        $required = array('phptype', 'vfsroot');
+        $required = array('db', 'vfsroot');
         foreach ($required as $val) {
             if (!isset($this->_params[$val])) {
                 throw new VFS_Exception(sprintf('Required "%s" not specified in VFS configuration.', $val));
@@ -636,36 +622,10 @@ class VFS_sql_file extends VFS_file
         }
 
         $this->_params = array_merge(array(
-            'database' => '',
-            'hostspec' => '',
             'table' => 'horde_vfs',
-            'username' => ''
         ), $this->_params);
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = DB::connect(
-            $this->_params,
-            array(
-                'persistent' => !empty($this->_params['persistent']),
-                'ssl' => !empty($this->_params['ssl']
-            )
-        ));
-        if ($this->_db instanceof PEAR_Error) {
-            $error = new VFS_Exception($this->_db->getMessage());
-            $this->_db = false;
-            throw $error;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
+        $this->_db = $this->_params['db'];
     }
 
     /**
index df8b16e..15d8aa5 100644 (file)
@@ -692,44 +692,17 @@ class Hermes_Driver_sql extends Hermes_Driver {
     /**
      * Attempts to open a persistent connection to the SQL server.
      *
-     * @return boolean  True on success; exits (Horde::fatal()) on error.
+     * @return boolean  True on success.
+     * @throws Horde_Exception
      */
     function _connect()
     {
-        if (!$this->_connected) {
-            Horde::assertDriverConfig($this->_params, 'storage',
-                array('phptype'));
-
-            if (!isset($this->_params['database'])) {
-                $this->_params['database'] = '';
-            }
-            if (!isset($this->_params['username'])) {
-                $this->_params['username'] = '';
-            }
-            if (!isset($this->_params['hostspec'])) {
-                $this->_params['hostspec'] = '';
-            }
-
-            /* Connect to the SQL server using the supplied parameters. */
-            include_once 'DB.php';
-            $this->_db = &DB::connect($this->_params,
-                                      array('persistent' => !empty($this->_params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-            $this->_connected = true;
+        if ($this->_connected) {
+            return true;
         }
 
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hermes', 'storage');
+
         return true;
     }
 
index bae0af9..1eff224 100644 (file)
@@ -373,37 +373,7 @@ class Hylax_Storage_sql extends Hylax_Storage {
 
     function initialise()
     {
-        global $registry;
-
-        Horde::assertDriverConfig($this->_params, 'sql',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            Horde::fatal($this->_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'hylax', 'sql');
 
         return true;
     }
index 5284f7c..9593297 100644 (file)
@@ -3,20 +3,6 @@
  * Ingo_Storage_Sql implements the Ingo_Storage API to save Ingo data via
  * PHP's PEAR database abstraction layer.
  *
- * Required values for $params:<pre>
- *   'phptype'  - The database type (e.g. 'pgsql', 'mysql', etc.).
- *   'charset'  - The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *   'database' - The name of the database.
- *   'hostspec' - The hostname of the database server.
- *   'protocol' - The communication protocol ('tcp', 'unix', etc.).
- *   'username' - The username with which to connect to the database.
- *   'password' - The password associated with 'username'.
- *   'options'  - Additional options to pass to the database.
- *   'tty'      - The TTY on which to connect to the database.
- *   'port'     - The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/drivers/sql/ingo.sql
  * script.
  *
@@ -61,64 +47,16 @@ class Ingo_Storage_Sql extends Ingo_Storage
      */
     public function __construct($params = array())
     {
-        $this->_params = $params;
-
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        $this->_params['table_rules'] = 'ingo_rules';
-        $this->_params['table_lists'] = 'ingo_lists';
-        $this->_params['table_vacations'] = 'ingo_vacations';
-        $this->_params['table_forwards'] = 'ingo_forwards';
-        $this->_params['table_spam'] = 'ingo_spam';
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent']),
-                                              'ssl' => !empty($this->_params['ssl'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            throw new Horde_Exception_Prior($this->_write_db);
-        }
-        /* Set DB portability options. */
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent']),
-                                            'ssl' => !empty($params['ssl'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                throw new Horde_Exception_Prior($this->_db);
-            }
-
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'ingo', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'ingo', 'storage');
+
+        $this->_params = array_merge($params, array(
+            'table_rules' => 'ingo_rules',
+            'table_lists' => 'ingo_lists',
+            'table_vacations' => 'ingo_vacations',
+            'table_forwards' => 'ingo_forwards',
+            'table_spam' => 'ingo_spam'
+        ));
 
         parent::__construct();
     }
index 504f146..15a6354 100644 (file)
@@ -2,20 +2,6 @@
 /**
  * Jonah storage implementation for PHP's PEAR database abstraction layer.
  *
- * Required values for $params:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/db/jonah_news.sql
  * script. The needed tables are jonah_channels and jonah_stories.
  *
@@ -998,7 +984,7 @@ class Jonah_Driver_Sql extends Jonah_Driver
     /**
      * Attempts to open a persistent connection to the SQL server.
      *
-     * @return boolean    True on success; PEAR_Error on failure.
+     * @return boolean  True on success; PEAR_Error on failure.
      */
     protected function _connect()
     {
@@ -1006,37 +992,14 @@ class Jonah_Driver_Sql extends Jonah_Driver
             return true;
         }
 
-        Horde::assertDriverConfig($this->_params, 'news',
-            array('phptype', 'charset'),
-            'jonah news SQL');
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         $this->_connected = true;
+
         return true;
     }
 
index 8937990..a762e18 100644 (file)
@@ -2,20 +2,6 @@
 /**
  * Jonah storage implementation for PHP's PEAR database abstraction layer.
  *
- * Required values for $params:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/db/jonah_news.sql
  * script. The needed tables are jonah_channels and jonah_stories.
  *
@@ -850,7 +836,7 @@ class Jonah_News_sql extends Jonah_News {
     /**
      * Attempts to open a persistent connection to the SQL server.
      *
-     * @return boolean    True on success; PEAR_Error on failure.
+     * @return boolean  True on success; PEAR_Error on failure.
      */
     function _connect()
     {
@@ -858,37 +844,14 @@ class Jonah_News_sql extends Jonah_News {
             return true;
         }
 
-        Horde::assertDriverConfig($this->_params, 'news',
-            array('phptype', 'charset'),
-            'jonah news SQL');
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'jonah', 'news');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         $this->_connected = true;
+
         return true;
     }
 
index 7070d38..b52edc9 100644 (file)
@@ -882,79 +882,39 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
      */
     public function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'calendar',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['table'])) {
-            $this->_params['table'] = 'kronolith_events';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = DB::connect($this->_params,
-                                       array('persistent' => !empty($this->_params['persistent']),
-                                             'ssl' => !empty($this->_params['ssl'])));
-        $this->handleError($this->_write_db);
-        $this->_initConn($this->_write_db);
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                     array('persistent' => !empty($params['persistent']),
-                                           'ssl' => !empty($params['ssl'])));
-            $this->handleError($this->_db);
-            $this->_initConn($this->_db);
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db = $this->_write_db;
-        }
-    }
-
-    /**
-     */
-    private function _initConn(&$db)
-    {
-        // Set DB portability options.
-        switch ($db->phptype) {
-        case 'mssql':
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar');
+        } catch (Horde_Exception $e) {
+            throw new Kronolith_Exception($e);
         }
 
-        /* Handle any database specific initialization code to run. */
-        switch ($db->dbsyntax) {
-        case 'oci8':
-            $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
+        foreach (array($this->_db, $this->_write_db) as $db) {
+            /* Handle any database specific initialization code to run. */
+            switch ($db->dbsyntax) {
+            case 'oci8':
+                $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
 
-            /* Log the query at a DEBUG log level. */
-            Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
-                                      $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
+                /* Log the query at a DEBUG log level. */
+                Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
 
-            $db->query($query);
-            break;
+                $db->query($query);
+                break;
 
-        case 'pgsql':
-            $query = "SET datestyle TO 'iso'";
+            case 'pgsql':
+                $query = "SET datestyle TO 'iso'";
 
-            /* Log the query at a DEBUG log level. */
-            Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"',
-                                      $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
+                /* Log the query at a DEBUG log level. */
+                Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', $GLOBALS['registry']->getAuth(), $query), 'DEBUG');
 
-            $db->query($query);
-            break;
+                $db->query($query);
+                break;
+            }
         }
+
+        $this->_params = array_merge(array(
+            'table' => 'kronolith_events'
+        ), $this->_params);
     }
 
     /**
index 5b12b92..e6e3a0b 100644 (file)
@@ -8,9 +8,9 @@
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
- * @author  Michael J. Rubinsky <mrubinsk@horde.org>
- *
- * @package Kronolith
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @package  Kronolith
  */
 class Kronolith_Geo_Sql extends Kronolith_Geo
 {
@@ -22,61 +22,16 @@ class Kronolith_Geo_Sql extends Kronolith_Geo
      */
     public function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'calendar', array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['table'])) {
-            $this->_params['table'] = 'kronolith_events_geo';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = DB::connect($this->_params,
-                                       array('persistent' => !empty($this->_params['persistent']),
-                                             'ssl' => !empty($this->_params['ssl'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Kronolith_Exception($this->_write_db);
-        }
-        $this->_initConn($this->_write_db);
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                     array('persistent' => !empty($params['persistent']),
-                                           'ssl' => !empty($params['ssl'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Kronolith_Exception($this->_db);
-            }
-            $this->_initConn($this->_db);
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db = $this->_write_db;
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'calendar');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'calendar');
+        } catch (Horde_Exception $e) {
+            throw new Kronolith_Exception($e);
         }
 
         return true;
     }
 
-    protected function _initConn(&$db)
-    {
-        // Set DB portability options.
-        switch ($db->phptype) {
-        case 'mssql':
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-    }
-
     /**
      * Set the location of the specified event _id
      *
index 5344b40..ddc14b3 100644 (file)
@@ -50,53 +50,11 @@ class Kronolith_Storage_sql extends Kronolith_Storage
      */
     public function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype'),
-            'kronolith storage SQL');
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        include_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent']),
-                                              'ssl' => !empty($this->_params['ssl'])));
-        $this->handleError($this->_write_db);
-        $this->_initConn($this->_write_db);
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent']),
-                                            'ssl' => !empty($params['ssl'])));
-            $this->handleError($this->_db);
-            $this->_initConn($this->_db);
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
-    }
-
-    /**
-     */
-    private function _initConn(&$db)
-    {
-        // Set DB portability options.
-        switch ($db->phptype) {
-        case 'mssql':
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'kronolith', 'storage');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'kronolith', 'storage');
+        } catch (Horde_Exception $e) {
+            throw new Kronolith_Exception($e);
         }
     }
 
index c75cbdd..a764169 100644 (file)
@@ -2,20 +2,6 @@
 /**
  * Luxor storage implementation for PHP's PEAR database abstraction layer.
  *
- * Required values for $params:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'database'      The name of the database.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/drivers/luxor.sql
  * script.
  *
@@ -521,40 +507,12 @@ class Luxor_Driver_sql extends Luxor_Driver {
     /**
      * Attempts to open a persistent connection to the SQL server.
      *
-     * @return boolean  True on success; exits (Horde::fatal()) on error.
+     * @return boolean  True on success.
      */
     function _connect()
     {
         if (!$this->_connected) {
-            Horde::assertDriverConfig($this->_params, 'storage',
-                array('phptype', 'charset'));
-
-            if (!isset($this->_params['database'])) {
-                $this->_params['database'] = '';
-            }
-            if (!isset($this->_params['username'])) {
-                $this->_params['username'] = '';
-            }
-            if (!isset($this->_params['hostspec'])) {
-                $this->_params['hostspec'] = '';
-            }
-
-            /* Connect to the SQL server using the supplied parameters. */
-            $this->_db = &DB::connect($this->_params,
-                                      array('persistent' => !empty($this->_params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'luxor', 'storage');
             $this->_connected = true;
         }
 
index 637f4a6..cf58f79 100644 (file)
@@ -3,24 +3,6 @@
  * Mnemo storage implementation for PHP's PEAR database abstraction
  * layer.
  *
- * Required parameters:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'charset'       The database's internal charset.</pre>
- *
- * Optional values:<pre>
- *      'table'         The name of the memos table in 'database'. Defaults
- *                      to 'mnemo_memos'</pre>
- *
- * Required by some database implementations:<pre>
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'database'      The name of the database.
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure is defined in scripts/drivers/mnemo_memos.sql.
  *
  * $Horde: mnemo/lib/Driver/sql.php,v 1.53 2009/07/09 08:18:32 slusarz Exp $
@@ -73,68 +55,16 @@ class Mnemo_Driver_sql extends Mnemo_Driver {
     /**
      * Attempts to open a connection to the SQL server.
      *
-     * @return boolean  True on success, PEAR_Error on failure.
+     * @return boolean  True on success.
      */
     function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        if (!isset($this->_params['table'])) {
-            $this->_params['table'] = 'mnemo_memos';
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'mnemo', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'mnemo', 'storage');
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent']),
-                                              'ssl' => !empty($this->_params['ssl'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent']),
-                                            'ssl' => !empty($params['ssl'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-        } else {
-            /* Default to the same DB handle for reads. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_params = array_merge(array(
+            'table' => 'mnemo_memos'
+        ), $this->_params);
 
         return true;
     }
index 6070a5c..08bb572 100644 (file)
@@ -376,62 +376,13 @@ class News_Driver_sql extends News_Driver {
      */
     private function _connect()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'news', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'news', 'storage');
 
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
         if (isset($this->_params['prefix'])) {
             $this->prefix = $this->_params['prefix'];
         }
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if ($this->write_db instanceof PEAR_Error) {
-            throw new Horde_Exception_Prior($this->write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->write_db->phptype) {
-        case 'mssql':
-            $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if ($this->db instanceof PEAR_Error) {
-                throw new Horde_Exception_Prior($this->db);
-            }
-
-            // Set DB portability options.
-            switch ($this->db->phptype) {
-            case 'mssql':
-                $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->db =& $this->write_db;
-        }
-
         return true;
     }
 
index 55dbb41..068bdb3 100644 (file)
@@ -2,21 +2,6 @@
 /**
  * Operator storage implementation for PHP's PEAR database abstraction layer.
  *
- * Required values for $params:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'table'         The name of the foo table in 'database'.
- *      'charset'       The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *      'database'      The name of the database.
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/sql/operator_foo.sql
  * script.
  *
@@ -345,7 +330,8 @@ class Operator_Driver_asterisksql extends Operator_Driver {
     /**
      * Attempts to open a connection to the SQL server.
      *
-     * @return boolean  True on success; exits (Horde::fatal()) on error.
+     * @return boolean  True on success.
+     * @throws Horde_Exception
      */
     protected function _connect()
     {
@@ -353,60 +339,8 @@ class Operator_Driver_asterisksql extends Operator_Driver {
             return true;
         }
 
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset', 'table'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
-
-        $this->_connected = true;
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'operator', 'storage');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'operator', 'storage');
 
         return true;
     }
index fa517a2..2d176b6 100644 (file)
@@ -238,65 +238,11 @@ class Pastie_Driver_Sql extends Pastie_Driver
      */
     protected function _connect()
     {
-        if ($this->_connected) {
-            return;
-        }
-
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = DB::connect($this->_params,
-                                       array('persistent' => !empty($this->_params['persistent'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Horde_Exception_Prior($this->_write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                     array('persistent' => !empty($params['persistent'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Horde_Exception_Prior($this->_db);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db = $this->_write_db;
+        if (!$this->_connected) {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'pastie', 'storage');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'pastie', 'storage');
+            $this->_connected = true;
         }
-
-        $this->_connected = true;
     }
 
     /**
index 5448b6d..d21783f 100644 (file)
@@ -718,65 +718,16 @@ class Shout_Driver_Sql extends Shout_Driver
      */
     protected function _connect()
     {
-        if ($this->_connected) {
-            return;
-        }
-
-        Horde::assertDriverConfig($this->_params, $this->_params['class'],
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = DB::connect($this->_params,
-                                       array('persistent' => !empty($this->_params['persistent'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Shout_Exception($this->_write_db);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = DB::connect($params,
-                                     array('persistent' => !empty($params['persistent'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw Shout_Exception($this->_db);
+        if (!$this->_connected) {
+            try {
+                $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'shout', $this->_params['class']);
+                $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'shout', $this->_params['class']);
+            } catch (Horde_Exception $e) {
+                throw new Shout_Exception($e);
             }
 
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db = $this->_write_db;
+            $this->_connected = true;
         }
-
-        $this->_connected = true;
     }
 
     /**
index fb7393f..a63cfa8 100644 (file)
@@ -2,27 +2,6 @@
 /**
  * Skoli storage implementation for PHP's PEAR database abstraction layer.
  *
- * Required parameters:<pre>
- *   'phptype'      The database type (e.g. 'pgsql', 'mysql', etc.).
- *   'charset'      The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *   'hostspec'     The hostname of the database server.
- *   'protocol'     The communication protocol ('tcp', 'unix', etc.).
- *   'database'     The name of the database.
- *   'username'     The username with which to connect to the database.
- *   'password'     The password associated with 'username'.
- *   'options'      Additional options to pass to the database.
- *   'tty'          The TTY on which to connect to the database.
- *   'port'         The port on which to connect to the database.</pre>
- *
- * Optional values when using separate reading and writing servers, for example
- * in replication settings:<pre>
- *   'splitread'   Boolean, whether to implement the separation or not.
- *   'read'        Array containing the parameters which are different for
- *                 the read database connection, currently supported
- *                 only 'hostspec' and 'port' parameters.</pre>
- *
  * Optional parameters:<pre>
  *   'objects_table'            The name of the objects table in 'database'.
  *                              Default is 'skoli_objects'.
@@ -75,67 +54,18 @@ class Skoli_Driver_sql extends Skoli_Driver {
      */
     function initialize()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['objects_table'])) {
-            $this->_params['objects_table'] = 'skoli_objects';
-        }
-        if (!isset($this->_params['object_attributes_table'])) {
-            $this->_params['object_attributes_table'] = 'skoli_object_attributes';
-        }
-        if (!isset($this->_params['students_table'])) {
-            $this->_params['students_table'] = 'skoli_classes_students';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            return $this->_write_db;
-        }
-
-        /* Set DB portability options. */
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                return $this->_db;
-            }
-
-            /* Set DB portability options. */
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-
-        } else {
-            /* Default to the same DB handle for the writer too. */
-            $this->_db =& $this->_write_db;
-        }
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'skoli', 'storage');
+            $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'skoli', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
+        }
+
+        $this->_params = array_merge(array(
+            'objects_table' => 'skoli_objects',
+            'object_attributes_table' => 'skoli_object_attributes',
+            'students_table' => 'skoli_classes_students'
+        ), $this->_params);
 
         return true;
     }
index f6d1de7..dd36683 100755 (executable)
@@ -31,7 +31,7 @@ $dsn = $argv[1];
 
 // Connect to database.
 $db = DB::connect($dsn);
-if (is_a($db, 'PEAR_Error')) {
+if ($db instanceof PEAR_Error) {
     $cli->fatal($db->toString());
 }
 
index e00b021..10b1645 100755 (executable)
@@ -39,22 +39,10 @@ $do_email = true;
 require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('turba', array('authentication' => 'none', 'cli' => true));
 
-/* Grab what we need to steal the DB config */
-require_once HORDE_BASE . '/config/conf.php';
 require_once 'Horde/Form.php';
 
-$config = $GLOBALS['conf']['sql'];
-if (!is_null($db_user)) {
-    $config['username'] = $db_user;
-}
-if (!is_null($db_pass)) {
-    $config['password'] = $db_pass;
-}
-unset($config['charset']);
-$db = DB::connect($config);
-if (is_a($db, 'PEAR_Error')) {
-    throw new Horde_Exception($db);
-}
+$db = $injector->getInstance('Horde_Db_Pear')->getDb();
+
 if (!$for_real) {
     $cli->message('No changes will done to the existing data. Please read the comments in the code, then set the $for_real flag to true before running.', 'cli.message');
 }
@@ -97,15 +85,18 @@ $queries = array(
     'CREATE INDEX turba_firstname_idx ON ' . $db_table . ' (object_firstname)',
     'CREATE INDEX turba_lastname_idx ON ' . $db_table . ' (object_lastname)',
 );
+
 switch ($config['phptype']) {
 case 'mssql':
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo VARBINARY(MAX)';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo VARBINARY(MAX)';
     break;
+
 case 'pgsql':
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo TEXT';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo TEXT';
     break;
+
 default:
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_photo BLOB';
     $queries[] = 'ALTER TABLE ' . $db_table . ' ADD COLUMN object_logo BLOB';
index fe25747..85ca5eb 100644 (file)
@@ -1264,35 +1264,10 @@ class Vilma_Driver_qmailldap extends Vilma_Driver {
     {
         global $registry;
 
-        Horde::assertDriverConfig($this->_sqlparams, 'storage',
-                                  array('phptype'));
-
-        if (!isset($this->_sqlparams['database'])) {
-            $this->_sqlparams['database'] = '';
-        }
-        if (!isset($this->_sqlparams['username'])) {
-            $this->_sqlparams['username'] = '';
-        }
-        if (!isset($this->_sqlparams['hostspec'])) {
-            $this->_sqlparams['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_sqlparams,
-                                  array('persistent' => !empty($this->_sqlparams['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
     }
 }
index 4913b12..fc59859 100644 (file)
@@ -588,19 +588,10 @@ class Vilma_Driver_sql extends Vilma_Driver {
      */
     function initialise()
     {
-        global $registry;
-
-        Horde::assertDriverConfig($this->_params, 'storage',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'vilma', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
 
         /* Use default table names if these are not set. */
@@ -614,24 +605,6 @@ class Vilma_Driver_sql extends Vilma_Driver {
             $this->_params['tables']['virtuals'] = 'vilma_virtuals';
         }
 
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
         return true;
     }
 
index e36acac..b97799c 100644 (file)
@@ -2874,58 +2874,8 @@ class Whups_Driver_sql extends Whups_Driver {
      */
     function initialise()
     {
-        Horde::assertDriverConfig($this->_params, 'tickets',
-            array('phptype'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_write_db = &DB::connect($this->_params,
-                                        array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_write_db, 'PEAR_Error')) {
-            Horde::fatal($this->_write_db, __FILE__, __LINE__);
-        }
-
-        // Set DB portability options.
-        switch ($this->_write_db->phptype) {
-        case 'mssql':
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        /* Check if we need to set up the read DB connection
-         * seperately. */
-        if (!empty($this->_params['splitread'])) {
-            $params = array_merge($this->_params, $this->_params['read']);
-            $this->_db = &DB::connect($params,
-                                      array('persistent' => !empty($params['persistent'])));
-            if (is_a($this->_db, 'PEAR_Error')) {
-                Horde::fatal($this->_db, __FILE__, __LINE__);
-            }
-
-            // Set DB portability options.
-            switch ($this->_db->phptype) {
-            case 'mssql':
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-                break;
-            default:
-                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-            }
-        } else {
-            /* Default to the same DB handle for reads. */
-            $this->_db =& $this->_write_db;
-        }
+        $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('read', 'whups', 'tickets');
+        $this->_write_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'whups', 'tickets');
 
         return true;
     }
index 3d345fc..e56bcfd 100755 (executable)
@@ -53,7 +53,7 @@ function info($text)
 
 /* Connect to the Bugzilla database. */
 $bugzilla = DB::connect($BUGZILLA_DSN);
-if (is_a($bugzilla, 'PEAR_Error')) {
+if ($bugzilla instanceof PEAR_Error) {
     error('Failed to connect to Bugzilla database', $bugzilla);
     exit;
 }
index f3373fa..652e932 100644 (file)
@@ -7,21 +7,6 @@
  * Wicked storage implementation for PHP's PEAR database abstraction
  * layer.
  *
- * Required values for $params:<pre>
- *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
- *      'hostspec'      The hostname of the database server.
- *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
- *      'username'      The username with which to connect to the database.
- *      'password'      The password associated with 'username'.
- *      'database'      The name of the database.
- *      'table'         The name of the tasks table in 'database'.
- *      'charset'       The database's internal charset.</pre>
- *
- * Required by some database implementations:<pre>
- *      'options'       Additional options to pass to the database.
- *      'tty'           The TTY on which to connect to the database.
- *      'port'          The port on which to connect to the database.</pre>
- *
  * The table structure can be created by the scripts/drivers/wicked_foo.sql
  * script.
  *
@@ -957,47 +942,18 @@ class Wicked_Driver_sql extends Wicked_Driver {
      */
     function connect()
     {
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'charset'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-        if (!isset($this->_params['table'])) {
-            $this->_params['table'] = 'wicked_pages';
-        }
-        if (!isset($this->_params['historytable'])) {
-            $this->_params['historytable'] = 'wicked_history';
+        try {
+            $this->_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb('rw', 'wicked', 'storage');
+        } catch (Horde_Exception $e) {
+            return PEAR::raiseError($e->getMessage());
         }
-        if (!isset($this->_params['attachmenttable'])) {
-            $this->_params['attachmenttable'] = 'wicked_attachments';
-        }
-        if (!isset($this->_params['attachmenthistorytable'])) {
-            $this->_params['attachmenthistorytable'] = 'wicked_attachment_history';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        $this->_db = &DB::connect($this->_params,
-                                  array('persistent' => !empty($this->_params['persistent'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        // Set DB portability options.
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
 
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
+        $this->_params = array_merge(array(
+            'table' => 'wicked_pages',
+            'historytable' => 'wicked_history',
+            'attachmenttable' => 'wicked_attachments',
+            'attachmenthistorytable' => 'wicked_attachment_history'
+        ), $this->_params);
 
         return true;
     }