Some low-hanging fruit locations to use the new PEAR DB binder
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 May 2010 19:17:21 +0000 (13:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 May 2010 20:08:42 +0000 (14:08 -0600)
23 files changed:
agora/scripts/phorum2agora.php
agora/scripts/upgrades/2006-10-26_forums_table.php
agora/scripts/upgrades/2006-10-26_messages_table.php
agora/scripts/upgrades/2006-10-28_update_counts.php
beatnik/lib/Driver/pdnsgsql.php
folks/config/hooks.php.dist
folks/scripts/activity.php
folks/scripts/import_letter.php
folks/scripts/mail-filter.php
folks/scripts/mail.php
folks/scripts/popularity.php
framework/SyncML/SyncML/Backend/Horde.php
framework/admintools/horde-create-sequence.php
framework/admintools/horde-remove-pref.php
framework/admintools/horde-sql-shell.php
horde/admin/sqlshell.php
horde/config/hooks.php.dist
horde/lib/Block/metar.php
horde/scripts/upgrades/convert_datatree_groups_to_sql.php
horde/scripts/upgrades/convert_datatree_perms_to_sql.php
kronolith/scripts/upgrades/convert_to_utc.php
vilma/lib/Driver/qmailldap.php
wicked/lib/Driver/sql.php

index e3fe366..18f6322 100755 (executable)
@@ -19,18 +19,7 @@ require_once dirname(__FILE__) . '/../lib/Application.php';
 Horde_Registry::appInit('agora', array('authentication' => 'none', 'cli' => true));
 
 /* Open Agora database. */
-$db_agora = &DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    var_dump($db);
-    exit;
-}
-
-/* Open Phorum database. */
-$db_phorum = &DB::connect($conf['sql']);
-if ($db_phorum instanceof PEAR_Error) {
-    var_dump($db_phorum);
-    exit;
-}
+$db_agora = $db_phorum = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 // We accept the user name on the command-line.
 $ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:p:a:t:f:c:',
index eba5702..20b7f27 100755 (executable)
@@ -8,12 +8,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('agora', array('authentication' => 'none', 'cli' => true));
 
 /* Open the database. */
-$db = DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    var_dump($db);
-    exit;
-}
-$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 /* Copy forums. */
 $max_id = 0;
index f3b00a4..cad8251 100755 (executable)
@@ -10,12 +10,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('agora', array('authentication' => 'none', 'cli' => true));
 
 /* Open the database. */
-$db = &DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    var_dump($db);
-    exit;
-}
-$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 /* Get messages. */
 $sql = 'SELECT DISTINCT d.datatree_id, d.datatree_parents FROM horde_datatree d, horde_datatree_attributes a '
index 61d3061..93b72ad 100755 (executable)
@@ -10,12 +10,7 @@ require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('agora', array('authentication' => 'none', 'cli' => true));
 
 /* Open the database. */
-$db = &DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    var_dump($db);
-    exit;
-}
-$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 /* Get threads. */
 $sql = 'SELECT message_id, forum_id FROM agora_messages WHERE message_thread = ?';
index 808b9e4..6129164 100644 (file)
@@ -50,9 +50,14 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
     *
     * @param array  $params    A hash containing connection parameters.
     */
-    function Beatnik_Driver_pdnsgsql($params = array())
+    function __construct($params = array())
     {
-        parent::Beatnik_Driver($params);
+        $params = array_merge(array(
+            'domains_table' => 'domains',
+            'records_table' => 'records'
+        ), $params);
+
+        parent::__construct($params);
     }
 
     /**
@@ -427,13 +432,6 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
             throw $e;
         }
 
-        if (!isset($this->_params['domains_table'])) {
-            $this->_params['domains_table'] = 'domains';
-        }
-        if (!isset($this->_params['records_table'])) {
-            $this->_params['records_table'] = 'records';
-        }
-
         /* Connect to the SQL server using the supplied parameters. */
         require_once 'DB.php';
         $this->_write_db = &DB::connect($this->_params,
index 1e74e7d..ec6be97 100644 (file)
@@ -226,12 +226,11 @@ class Folks_Hooks
             break;
 
         case 'imp':
-
             if (Horde_Auth::isAdmin()
                 || $group->userIsInGroup($user_uid, 1, false)
                 || $group->userIsInGroup($user_uid, 2, false)) {
 
-                $db = DB::connect($GLOBALS['conf']['sql']);
+                $db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getOb();
                 $password = $db->getOne('SELECT password FROM mails.accountuser WHERE username = ?', array($user_uid . '@' . $_SERVER['SERVER_NAME']));
 
                 $try = $GLOBALS['registry']->callByPackage('imp', 'authenticate', array($user_uid, array('password' => $password)));
@@ -272,7 +271,7 @@ class Folks_Hooks
             throw new Horde_Exception(_("Username can contain only alphanumeric characters, underscore and minus."));
         }
 
-        $_db = DB::connect($GLOBALS['conf']['sql'], true);
+        $_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getOb();
 
         $query  = 'SELECT user_uid, user_email FROM folks_users WHERE user_uid = ? OR user_email = ?';
         $result = $_db->getRow($query, array($username, $info['extra']['email']), DB_FETCHMODE_ASSOC);
@@ -299,7 +298,7 @@ class Folks_Hooks
      {
         global $conf;
 
-        $_db = DB::connect($conf['sql']);
+        $_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getOb();
         $fields = array();
         $values = array();
         foreach ($extra as $field => $value) {
index b2599d0..24dda77 100644 (file)
  * @package Folks
  */
 
+// Disabled by default
 exit;
 
-$folks_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('folks', array('authentication' => 'none', 'cli' => true));
 
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-// Load the CLI environment.
-$cli = Horde_Cli::init();
-
-$db = DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    $cli->fatal($db);
+try {
+    $db = $injector->getInstance('Horde_Db_Pear')->getOb();
+} catch (Horde_Exception $e) {
+    $cli->fatal($e);
 }
 
 $users = array();
index 275aa17..057bf7a 100644 (file)
  * @package Folks
  */
 
+// Disabled by default
 exit;
 
-$folks_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('folks', array('authentication' => 'none', 'cli' => true));
 
-$db = DB::connect($conf['sql']);
+try {
+    $db = $injector->getInstance('Horde_Db_Pear')->getOb();
+} catch (Horde_Exception $e) {
+    $cli->fatal($e);
+}
 
 $sql = 'SELECT pref_uid, pref_value, pref_name FROM horde_prefs WHERE '
         . ' pref_scope = ? AND (pref_name = ? OR pref_name = ?)'
index 838348d..9c83e9a 100644 (file)
@@ -37,20 +37,8 @@ Options:
 EOU;
 }
 
-// Do CLI checks and environment setup first.
-require_once dirname(__FILE__) . '/../../lib/core.php';
-
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-// Load the CLI environment - make sure there's no time limit, init some
-// variables, etc.
-$cli = Horde_Cli::init();
-
-$horde_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('folks', array('authentication' => 'none', 'cli' => true));
 
 // Read command-line parameters.
 $info = array();
@@ -119,8 +107,11 @@ if (!$imap) {
 $from_str = array('Undelivered Mail', 'MAILER-DAEMON', 'root@' . $conf['server']['name']);
 
 // Connect to db
-$dbconf = Horde::getDriverConfig('storage', 'sql');
-$db = DB::connect($dbconf);
+try {
+    $db = $injector->getInstance('Horde_Db_Pear')->getOb();
+} catch (Horde_Exception $e) {
+    $cli->fatal($e);
+}
 
 // get mails
 $mails = array();
index 681d86d..81e032b 100644 (file)
  * @package Folks
  */
 
-// Do CLI checks and environment setup first.
-require_once 'Horde/Cli.php';
-
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-// Load the CLI environment.
-$cli = Horde_Cli::init();
-
-// Load Folks.
-$folks_authentication = 'none';
-$no_compress = true;
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('folks', array('authentication' => 'none', 'cli' => true, 'no_compress' => true));
 
 // We accept the user name on the command-line.
 $ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u:p:dt:f:c:',
@@ -93,8 +80,11 @@ if (!Horde_Auth::isAdmin('folks:admin')) {
 }
 
 // Connect to db
-$dbconf = Horde::getDriverConfig('storage', 'sql');
-$db = DB::connect($dbconf);
+try {
+    $db = $injector->getInstance('Horde_Db_Pear')->getOb();
+} catch (Horde_Exception $e) {
+    $cli->fatal($e);
+}
 
 // Get new messages older time
 $query = 'SELECT user_uid, user_email FROM folks_users ORDER BY user_uid ASC';
index c3bef3f..ad326c3 100644 (file)
  * @package Folks
  */
 
+// Disabled by default
 exit;
 
-$folks_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('folks', array('authentication' => 'none', 'cli' => true));
 
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-// Load the CLI environment.
-$cli = Horde_Cli::init();
-
-$db = DB::connect($conf['sql']);
-if ($db instanceof PEAR_Error) {
-    $cli->fatal($db);
+try {
+    $db = $injector->getInstance('Horde_Db_Pear')->getOb();
+} catch (Horde_Exception $e) {
+    $cli->fatal($e);
 }
 
 $users = array();
index 38b0439..bf92bed 100644 (file)
@@ -26,26 +26,11 @@ class SyncML_Backend_Horde extends SyncML_Backend {
      *
      * @param array $params  Any parameters the backend might need.
      */
-    function SyncML_Backend_Horde($params)
+    function __construct($params)
     {
-        parent::SyncML_Backend($params);
+        parent::__construct($params);
 
-        $this->_db = DB::connect($GLOBALS['conf']['sql']);
-
-        if (is_a($this->_db, 'PEAR_Error')) {
-            Horde::logMessage($this->_db, 'ERR');
-        }
-
-        /* Set DB portability options. */
-        if (is_a($this->_db, 'DB_common')) {
-            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')->getOb();
     }
 
     /**
index c77f6a2..247e0f0 100755 (executable)
@@ -32,8 +32,7 @@ if (is_null($sequence)) {
 
 switch ($db_lib) {
 case 'DB':
-    require_once 'DB.php';
-    $dbh = DB::connect($conf['sql']);
+    $dbh = $injector->getInstance('Horde_Db_Pear')->getOb();
     break;
 
 case 'MDB2':
index 0ff09c8..587df57 100755 (executable)
@@ -20,20 +20,7 @@ $scope = $cli->prompt(_("Enter value for pref_scope:"));
 $name = $cli->prompt(_("Enter value for pref_name:"));
 
 /* Open the database. */
-$db = DB::connect($conf['sql']);
-if (is_a($db, 'PEAR_Error')) {
-   var_dump($db);
-   exit;
-}
-
-// 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);
-}
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 if ($live) {
     $sql = 'DELETE FROM horde_prefs WHERE pref_scope = ? AND pref_name = ?';
index 57d1a6f..4c2e95d 100755 (executable)
 require_once dirname(__FILE__) . '/horde-base.php';
 Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true));
 
-$dbh = DB::connect($conf['sql']);
-if (is_a($dbh, 'PEAR_Error')) {
-    throw new Horde_Exception_Prior($dbh);
-}
-$dbh->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+$dbh = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 // list databases command
 // $result = $dbh->getListOf('databases');
index 68e0e26..9ab8cfc 100644 (file)
@@ -24,11 +24,7 @@ require HORDE_TEMPLATES . '/admin/menu.inc';
 
 <?php
 
-$dbh = DB::connect($conf['sql']);
-if (is_a($dbh, 'PEAR_Error')) {
-    throw new Horde_Exception_Prior($dbh);
-}
-$dbh->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+$dbh = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 if (Horde_Util::getFormData('list-tables')) {
     $description = 'LIST TABLES';
index f23be3a..8ee4eee 100644 (file)
@@ -577,7 +577,7 @@ class Horde_Hooks
 //        store this in whichever backend you require.
 //        // NOTE: You NEED Turba to be correctly installed before you can use
 //        // this example. It also assumes you are using an SQL backend.
-//        $db = DB::connect($GLOBALS['conf']['sql'], true);
+//        $db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getOb();
 //
 //        $fields = $values = array();
 //        foreach ($extra as $field => $value) {
@@ -655,7 +655,7 @@ class Horde_Hooks
 //        switch ($groupName) {
 //        case 'IT_department':
 //            $dept = 'IT';
-//            $db = DB::connect($conf['sql'], true);
+//            $db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getOb();
 //            $query = 'SELECT COUNT(*) FROM departments WHERE user_name = ? AND department = ?';
 //            $values = array($userName, $dept);
 //            $result = $db->getOne($query, $values);
index 27492ad..298e535 100644 (file)
@@ -33,7 +33,7 @@ class Horde_Block_Horde_metar extends Horde_Block {
 
     function _params()
     {
-        if (!@include_once 'Services/Weather.php') {
+        if (!class_exists('Services_Weather')) {
             Horde::logMessage('The metar block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', 'ERR');
             return array(
                 'error' => array(
@@ -46,20 +46,7 @@ class Horde_Block_Horde_metar extends Horde_Block {
             global $conf;
 
             // Get locations from the database.
-            require_once 'DB.php';
-            $db = &DB::connect($conf['sql']);
-            if (is_a($db, 'PEAR_Error')) {
-                return $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);
-            }
+            $db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
             $result = $db->query('SELECT icao, name, country FROM metarAirports ORDER BY country');
             if (is_a($result, 'PEAR_Error')) {
index 27077c3..2db11d1 100755 (executable)
@@ -25,7 +25,7 @@ VALUES
     (?, ?)
 ';
 
-$db = DB::connect($conf['sql']);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 foreach ($g->listGroups(true) as $id => $name) {
     if ($id == -1) {
index 395eda3..2b6fd39 100755 (executable)
@@ -17,7 +17,7 @@ VALUES
     (?, ?, ?, ?)
 ';
 
-$db = DB::connect($conf['sql']);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 
 foreach ($p->getTree() as $id => $row) {
     if ($id == -1) {
index db08b94..ce3a737 100755 (executable)
@@ -10,7 +10,7 @@ Horde_Registry::appInit('kronolith', array('authentication' => 'none', 'cli' =>
 
 /* Prepare DB stuff. */
 PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, create_function('$e', 'echo $e->toString()."\n";exit;'));
-$db = DB::connect($conf['sql']);
+$db = $injector->getInstance('Horde_Db_Pear')->getOb();
 $result = $db->query('SELECT event_title, event_id, event_creator_id, event_start, event_end, event_allday, event_recurenddate FROM ' . $conf['calendar']['params']['table'] . ' ORDER BY event_creator_id');
 $stmt = $db->prepare('UPDATE kronolith_events SET event_start = ?, event_end = ?, event_recurenddate = ? WHERE event_id = ?');
 
index da1f023..fe25747 100644 (file)
@@ -9,9 +9,6 @@
  * @author David Cummings <davidcummings@acm.org>
  * @package Vilma
  */
-
-require_once 'Horde/SQL.php';
-
 class Vilma_Driver_qmailldap extends Vilma_Driver {
 
     /**
index 611eaca..2a99442 100644 (file)
@@ -3,9 +3,6 @@
  * @package Wicked
  */
 
-/** DB */
-require_once 'DB.php';
-
 /**
  * Wicked storage implementation for PHP's PEAR database abstraction
  * layer.