From 7e23da770e15011048375e5554f08dee8fb8aa03 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 14 May 2010 13:17:21 -0600 Subject: [PATCH] Some low-hanging fruit locations to use the new PEAR DB binder --- agora/scripts/phorum2agora.php | 13 +----------- agora/scripts/upgrades/2006-10-26_forums_table.php | 7 +------ .../scripts/upgrades/2006-10-26_messages_table.php | 7 +------ .../scripts/upgrades/2006-10-28_update_counts.php | 7 +------ beatnik/lib/Driver/pdnsgsql.php | 16 +++++++-------- folks/config/hooks.php.dist | 7 +++---- folks/scripts/activity.php | 20 +++++++----------- folks/scripts/import_letter.php | 11 +++++++--- folks/scripts/mail-filter.php | 23 +++++++-------------- folks/scripts/mail.php | 24 +++++++--------------- folks/scripts/popularity.php | 20 +++++++----------- framework/SyncML/SyncML/Backend/Horde.php | 21 +++---------------- framework/admintools/horde-create-sequence.php | 3 +-- framework/admintools/horde-remove-pref.php | 15 +------------- framework/admintools/horde-sql-shell.php | 6 +----- horde/admin/sqlshell.php | 6 +----- horde/config/hooks.php.dist | 4 ++-- horde/lib/Block/metar.php | 17 ++------------- .../upgrades/convert_datatree_groups_to_sql.php | 2 +- .../upgrades/convert_datatree_perms_to_sql.php | 2 +- kronolith/scripts/upgrades/convert_to_utc.php | 2 +- vilma/lib/Driver/qmailldap.php | 3 --- wicked/lib/Driver/sql.php | 3 --- 23 files changed, 64 insertions(+), 175 deletions(-) diff --git a/agora/scripts/phorum2agora.php b/agora/scripts/phorum2agora.php index e3fe3668f..18f632253 100755 --- a/agora/scripts/phorum2agora.php +++ b/agora/scripts/phorum2agora.php @@ -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:', diff --git a/agora/scripts/upgrades/2006-10-26_forums_table.php b/agora/scripts/upgrades/2006-10-26_forums_table.php index eba570208..20b7f27bc 100755 --- a/agora/scripts/upgrades/2006-10-26_forums_table.php +++ b/agora/scripts/upgrades/2006-10-26_forums_table.php @@ -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; diff --git a/agora/scripts/upgrades/2006-10-26_messages_table.php b/agora/scripts/upgrades/2006-10-26_messages_table.php index f3b00a476..cad82517d 100755 --- a/agora/scripts/upgrades/2006-10-26_messages_table.php +++ b/agora/scripts/upgrades/2006-10-26_messages_table.php @@ -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 ' diff --git a/agora/scripts/upgrades/2006-10-28_update_counts.php b/agora/scripts/upgrades/2006-10-28_update_counts.php index 61d3061aa..93b72adc8 100755 --- a/agora/scripts/upgrades/2006-10-28_update_counts.php +++ b/agora/scripts/upgrades/2006-10-28_update_counts.php @@ -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 = ?'; diff --git a/beatnik/lib/Driver/pdnsgsql.php b/beatnik/lib/Driver/pdnsgsql.php index 808b9e456..612916460 100644 --- a/beatnik/lib/Driver/pdnsgsql.php +++ b/beatnik/lib/Driver/pdnsgsql.php @@ -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, diff --git a/folks/config/hooks.php.dist b/folks/config/hooks.php.dist index 1e74e7db6..ec6be97a0 100644 --- a/folks/config/hooks.php.dist +++ b/folks/config/hooks.php.dist @@ -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) { diff --git a/folks/scripts/activity.php b/folks/scripts/activity.php index b2599d0c8..24dda7703 100644 --- a/folks/scripts/activity.php +++ b/folks/scripts/activity.php @@ -13,22 +13,16 @@ * @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(); diff --git a/folks/scripts/import_letter.php b/folks/scripts/import_letter.php index 275aa171e..057bf7af3 100644 --- a/folks/scripts/import_letter.php +++ b/folks/scripts/import_letter.php @@ -13,12 +13,17 @@ * @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 = ?)' diff --git a/folks/scripts/mail-filter.php b/folks/scripts/mail-filter.php index 838348d6e..9c83e9a4a 100644 --- a/folks/scripts/mail-filter.php +++ b/folks/scripts/mail-filter.php @@ -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(); diff --git a/folks/scripts/mail.php b/folks/scripts/mail.php index 681d86d34..81e032b95 100644 --- a/folks/scripts/mail.php +++ b/folks/scripts/mail.php @@ -11,21 +11,8 @@ * @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'; diff --git a/folks/scripts/popularity.php b/folks/scripts/popularity.php index c3bef3fe8..ad326c34e 100644 --- a/folks/scripts/popularity.php +++ b/folks/scripts/popularity.php @@ -13,22 +13,16 @@ * @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(); diff --git a/framework/SyncML/SyncML/Backend/Horde.php b/framework/SyncML/SyncML/Backend/Horde.php index 38b043915..bf92bedad 100644 --- a/framework/SyncML/SyncML/Backend/Horde.php +++ b/framework/SyncML/SyncML/Backend/Horde.php @@ -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(); } /** diff --git a/framework/admintools/horde-create-sequence.php b/framework/admintools/horde-create-sequence.php index c77f6a205..247e0f013 100755 --- a/framework/admintools/horde-create-sequence.php +++ b/framework/admintools/horde-create-sequence.php @@ -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': diff --git a/framework/admintools/horde-remove-pref.php b/framework/admintools/horde-remove-pref.php index 0ff09c8d3..587df5709 100755 --- a/framework/admintools/horde-remove-pref.php +++ b/framework/admintools/horde-remove-pref.php @@ -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 = ?'; diff --git a/framework/admintools/horde-sql-shell.php b/framework/admintools/horde-sql-shell.php index 57d1a6f6c..4c2e95d8f 100755 --- a/framework/admintools/horde-sql-shell.php +++ b/framework/admintools/horde-sql-shell.php @@ -13,11 +13,7 @@ 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'); diff --git a/horde/admin/sqlshell.php b/horde/admin/sqlshell.php index 68e0e26a8..9ab8cfc4a 100644 --- a/horde/admin/sqlshell.php +++ b/horde/admin/sqlshell.php @@ -24,11 +24,7 @@ require HORDE_TEMPLATES . '/admin/menu.inc'; setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); +$dbh = $injector->getInstance('Horde_Db_Pear')->getOb(); if (Horde_Util::getFormData('list-tables')) { $description = 'LIST TABLES'; diff --git a/horde/config/hooks.php.dist b/horde/config/hooks.php.dist index f23be3aae..8ee4eee69 100644 --- a/horde/config/hooks.php.dist +++ b/horde/config/hooks.php.dist @@ -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); diff --git a/horde/lib/Block/metar.php b/horde/lib/Block/metar.php index 27492adc3..298e535c4 100644 --- a/horde/lib/Block/metar.php +++ b/horde/lib/Block/metar.php @@ -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')) { diff --git a/horde/scripts/upgrades/convert_datatree_groups_to_sql.php b/horde/scripts/upgrades/convert_datatree_groups_to_sql.php index 27077c386..2db11d180 100755 --- a/horde/scripts/upgrades/convert_datatree_groups_to_sql.php +++ b/horde/scripts/upgrades/convert_datatree_groups_to_sql.php @@ -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) { diff --git a/horde/scripts/upgrades/convert_datatree_perms_to_sql.php b/horde/scripts/upgrades/convert_datatree_perms_to_sql.php index 395eda3c3..2b6fd395a 100755 --- a/horde/scripts/upgrades/convert_datatree_perms_to_sql.php +++ b/horde/scripts/upgrades/convert_datatree_perms_to_sql.php @@ -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) { diff --git a/kronolith/scripts/upgrades/convert_to_utc.php b/kronolith/scripts/upgrades/convert_to_utc.php index db08b94d6..ce3a73771 100755 --- a/kronolith/scripts/upgrades/convert_to_utc.php +++ b/kronolith/scripts/upgrades/convert_to_utc.php @@ -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 = ?'); diff --git a/vilma/lib/Driver/qmailldap.php b/vilma/lib/Driver/qmailldap.php index da1f0236e..fe25747c0 100644 --- a/vilma/lib/Driver/qmailldap.php +++ b/vilma/lib/Driver/qmailldap.php @@ -9,9 +9,6 @@ * @author David Cummings * @package Vilma */ - -require_once 'Horde/SQL.php'; - class Vilma_Driver_qmailldap extends Vilma_Driver { /** diff --git a/wicked/lib/Driver/sql.php b/wicked/lib/Driver/sql.php index 611eaca6c..2a99442ba 100644 --- a/wicked/lib/Driver/sql.php +++ b/wicked/lib/Driver/sql.php @@ -3,9 +3,6 @@ * @package Wicked */ -/** DB */ -require_once 'DB.php'; - /** * Wicked storage implementation for PHP's PEAR database abstraction * layer. -- 2.11.0