From: Chuck Hagenbuch Date: Sun, 3 Oct 2010 04:47:02 +0000 (-0400) Subject: A round of PEAR DB removal before bed X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=3385e180c9d408475b61d380c4702a7df1baebaf;p=horde.git A round of PEAR DB removal before bed --- diff --git a/agora/scripts/upgrades/2006-10-26_forums_table.php b/agora/scripts/upgrades/2006-10-26_forums_table.php deleted file mode 100755 index 05e05cdfa..000000000 --- a/agora/scripts/upgrades/2006-10-26_forums_table.php +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/php - 'none', 'cli' => true)); - -/* Open the database. */ -$db = $injector->getInstance('Horde_Db_Pear')->getDb(); - -/* Copy forums. */ -$max_id = 0; -$forums = $db->getAll('SELECT * FROM horde_datatree WHERE group_uid LIKE \'agora.forums%\'', DB_FETCHMODE_ASSOC); -foreach ($forums as $forum) { - if ($forum['datatree_id'] > $max_id) { - $max_id = $forum['datatree_id']; - } - - $result = $db->getAll('SELECT * FROM horde_datatree_attributes WHERE datatree_id = ?', array($forum['datatree_id']), DB_FETCHMODE_ASSOC); - $attributes = array(); - foreach ($result as $attr) { - $attributes[$attr['attribute_name'] . '_' . $attr['attribute_key']] = $attr['attribute_value']; - } - - $sql = 'INSERT INTO agora_forums' . - ' (forum_id, scope, active, forum_name, forum_description, author, forum_moderated, message_count, forum_attachments, forum_parent_id, count_views, thread_count)' . - ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, 0)'; - - $values = array($forum['datatree_id'], - ($forum['group_uid'] == 'agora.forums') ? 'agora' : substr($forum['group_uid'], 13), - 1, - $forum['datatree_name'], - $attributes['forum_description'], - $forum['user_uid'], - (int)$attributes['forum_moderated'], - $attributes['message_seq'], - (int)$attributes['forum_attachments']); - - $result = $db->query($sql, $values); - if ($result instanceof PEAR_Error) { - var_dump($result); - exit; - } -} - -// Update DB sequence. -while ($db->nextId('agora_forums') < $max_id); diff --git a/agora/scripts/upgrades/2006-10-26_messages_table.php b/agora/scripts/upgrades/2006-10-26_messages_table.php deleted file mode 100755 index 632a49f09..000000000 --- a/agora/scripts/upgrades/2006-10-26_messages_table.php +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/php - 'none', 'cli' => true)); - -/* Open the database. */ -$db = $injector->getInstance('Horde_Db_Pear')->getDb(); - -/* Get messages. */ -$sql = 'SELECT DISTINCT d.datatree_id, d.datatree_parents FROM horde_datatree d, horde_datatree_attributes a ' - . ' WHERE d.group_uid = \'agora.threads\' AND d.datatree_id = a.datatree_id'; -$threads = $db->getAssoc($sql); -if ($threads instanceof PEAR_Error) { - var_dump($threads); - exit; -} - -/* SQL mesage insert statement */ -$sql = 'INSERT INTO agora_messages ' - . '(message_id, forum_id, parents, message_thread, message_author, message_subject, body, message_timestamp, attachments, ip)' - . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, \'\') '; - -foreach ($threads as $id => $parents) { - $result = $db->getAll('SELECT * FROM horde_datatree_attributes WHERE datatree_id = ?', array($id), DB_FETCHMODE_ASSOC); - $attributes = array(); - foreach ($result as $attr) { - $attributes[$attr['attribute_key']] = $attr['attribute_value']; - } - - // Remove main thread - $thread = explode(':', $parents); - unset($thread[1]); - - $params = array($id); - $params[] = $attributes['forum_id']; - $params[] = implode(':', $thread); - $params[] = count($thread) > 1 ? $thread[2] : 0; - $params[] = $attributes['author']; - $params[] = $attributes['subject']; - $params[] = $attributes['body']; - $params[] = $attributes['timestamp']; - - $result = $db->query($sql, $params); - if ($result instanceof PEAR_Error) { - var_dump($result); - exit; - } -} diff --git a/agora/scripts/upgrades/2006-10-28_update_counts.php b/agora/scripts/upgrades/2006-10-28_update_counts.php deleted file mode 100755 index 202e5fca4..000000000 --- a/agora/scripts/upgrades/2006-10-28_update_counts.php +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/php - 'none', 'cli' => true)); - -/* Open the database. */ -$db = $injector->getInstance('Horde_Db_Pear')->getDb(); - -/* Get threads. */ -$sql = 'SELECT message_id, forum_id FROM agora_messages WHERE message_thread = ?'; -$threads = $db->getAssoc($sql, false, array(0)); -if ($threads instanceof PEAR_Error) { - var_dump($threads); - exit; -} - -/* Reset message count */ -$db->query('UPDATE agora_messages SET message_seq = 0'); -echo 'Processing ' . count($threads) . ' threads' . "\n"; - -$sql = 'SELECT message_thread, COUNT(*) FROM agora_messages WHERE message_thread > ? GROUP BY message_thread'; -$counts = $db->getAssoc($sql, false, array(0)); -if ($counts instanceof PEAR_Error) { - var_dump($counts); - exit; -} - -/* Update the number of messages in thread */ -$forums = array(); -foreach ($threads as $message_id => $forum_id) { - if (!isset($counts[$message_id])) { - continue; - } - $count = $counts[$message_id]; - $db->query('UPDATE agora_messages SET message_seq = ? WHERE message_id = ?', array($count, $message_id)); - - if (!isset($forums[$forum_id])) { - $forums[$forum_id] = array('threads' => 0, - 'messages' => 0, - 'forum_id' => $forum_id); - } - - $forums[$forum_id]['threads'] += 1; - $forums[$forum_id]['messages'] += ($count + 1); -} - -echo "Update forums \n"; - -/* Update thread and message count for forums */ -$db->query('UPDATE agora_forums SET thread_count = 0, message_count = 0'); -$sth = $db->prepare('UPDATE agora_forums SET thread_count = ?, message_count = ? WHERE forum_id = ?'); -$result = $db->executeMultiple($sth, $forums); -if ($result instanceof PEAR_Error) { - var_dump($result); - exit; -} - -echo "Clean cache \n"; - -/* Clean cache */ -$forums = Agora_Messages::singleton('agora'); -foreach ($forums->getForums(0, false) as $forum_id) { - @$forums->cleanCache($forum_id); -} - -echo "done\n"; diff --git a/agora/scripts/upgrades/2006-12-20_add_moderators_table.sql b/agora/scripts/upgrades/2006-12-20_add_moderators_table.sql deleted file mode 100644 index dad0e6230..000000000 --- a/agora/scripts/upgrades/2006-12-20_add_moderators_table.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE agora_moderators ( - forum_id INT DEFAULT 0 NOT NULL, - horde_uid VARCHAR(32) NOT NULL, --- - PRIMARY KEY (forum_id, horde_uid) -); diff --git a/folks/config/hooks.php.dist b/folks/config/hooks.php.dist index 6dae6c3e1..9501887d8 100644 --- a/folks/config/hooks.php.dist +++ b/folks/config/hooks.php.dist @@ -230,8 +230,8 @@ class Folks_Hooks || $group->userIsInGroup($user_uid, 1, false) || $group->userIsInGroup($user_uid, 2, false)) { - $db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb(); - $password = $db->getOne('SELECT password FROM mails.accountuser WHERE username = ?', array($user_uid . '@' . $_SERVER['SERVER_NAME'])); + $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter'); + $password = $db->selectValue('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))); if ($try) { @@ -271,10 +271,10 @@ class Folks_Hooks throw new Horde_Exception(_("Username can contain only alphanumeric characters, underscore and minus.")); } - $_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb(); + $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter'); $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); + $result = $db->selectOne($query, array($username, $info['extra']['email']), DB_FETCHMODE_ASSOC); if ($result instanceof PEAR_Error) { throw new Horde_Exception_Prior($result); @@ -294,11 +294,11 @@ class Folks_Hooks // Here we connect to the database and update folks user table // with additional user data and send confirmation code to check his email - public function signup_addextra($userID, $extra) - { + public function signup_addextra($userID, $extra) + { global $conf; - $_db = $GLOBALS['injector']->getInstance('Horde_Db_Pear')->getDb(); + $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter'); $fields = array(); $values = array(); foreach ($extra as $field => $value) { @@ -316,10 +316,7 @@ class Folks_Hooks $query = 'UPDATE folks_users SET ' . implode(' = ?, ', $fields) . ' = ? ' . ' WHERE user_uid = ?'; - $result = $_db->query($query, $values); - if ($result instanceof PEAR_Error) { - throw new Horde_Exception_Prior($result); - } + $result = $db->update($query, $values); require_once $GLOBALS['registry']->get('fileroot', 'folks') . '/lib/Folks.php'; $code = Folks::encodeString($userID, 'activate' . hash('md5', $extra['password'])); @@ -335,11 +332,11 @@ class Folks_Hooks $result = Folks::sendMail($extra['email'], _("Confirmation code"), $body); if ($result instanceof PEAR_Error) { - $_db->query('DELETE FROM folks_users WHERE user_uid = ?', array($userID)); + $db->delete('DELETE FROM folks_users WHERE user_uid = ?', array($userID)); } return $result; - } + } // This is an example of a post-push hook; it is called right after an // application is pushed successfully onto the app stack. Here we check diff --git a/framework/admintools/horde-create-sequence.php b/framework/admintools/horde-create-sequence.php deleted file mode 100755 index ec2fd09a5..000000000 --- a/framework/admintools/horde-create-sequence.php +++ /dev/null @@ -1,71 +0,0 @@ -#!@php_bin@ - - */ - -require_once dirname(__FILE__) . '/horde-base.php'; -Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true)); - -$db_lib = 'DB'; -$sequence = null; - -if (isset($_SERVER['argv']) && count($_SERVER['argv']) >= 2) { - array_shift($_SERVER['argv']); - while ($arg = array_shift($_SERVER['argv'])) { - if ($arg == '--mdb2') { - $db_lib = 'MDB2'; - } else { - $sequence = $arg; - } - } -} -if (is_null($sequence)) { - $sequence = $cli->prompt(_("What sequence do you want to create (_seq will be added automatically)?")); -} - -switch ($db_lib) { -case 'DB': - $dbh = $injector->getInstance('Horde_Db_Pear')->getDb(); - break; - -case 'MDB2': - require_once 'MDB2.php'; - $params = $conf['sql']; - unset($params['charset']); - $dbh = MDB2::factory($params); - break; - -default: - throw new Horde_Exception('Unknown database abstraction library'); -} -if (is_a($dbh, 'PEAR_Error')) { - throw new Horde_Exception_Prior($dbh); -} - -if (!preg_match('/^\w+$/', $sequence)) { - $cli->fatal('Invalid sequence name'); -} - -switch ($db_lib) { -case 'DB': - $result = $dbh->createSequence($sequence); - break; - -case 'MDB2': - $dbh->loadModule('Manager', null, true); - $result = $dbh->manager->createSequence($sequence); - break; -} -if (is_a($result, 'PEAR_Error')) { - $cli->fatal($result->getMessage()); -} - -$cli->green('Sequence created.'); -exit(0); diff --git a/framework/admintools/package.xml b/framework/admintools/package.xml index 125a07ac2..2019a584c 100644 --- a/framework/admintools/package.xml +++ b/framework/admintools/package.xml @@ -35,9 +35,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - @@ -59,7 +56,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/horde/admin/sqlshell.php b/horde/admin/sqlshell.php index 9f1a22fdd..2beb4cc03 100644 --- a/horde/admin/sqlshell.php +++ b/horde/admin/sqlshell.php @@ -18,21 +18,17 @@ require HORDE_TEMPLATES . '/admin/menu.inc'; ?>
-


+

getInstance('Horde_Db_Pear')->getDb(); +$db = $injector->getInstance('Horde_Db_Adapter'); if (Horde_Util::getFormData('list-tables')) { $description = 'LIST TABLES'; - $result = $dbh->getListOf('tables'); - $command = null; -} elseif (Horde_Util::getFormData('list-dbs')) { - $description = 'LIST DATABASES'; - $result = $dbh->getListOf('databases'); + $result = $db->tables(); $command = null; } elseif ($command = trim(Horde_Util::getFormData('sql'))) { // Keep a cache of prior queries for convenience. @@ -48,57 +44,51 @@ if (Horde_Util::getFormData('list-tables')) { } // Parse out the query results. - $result = $dbh->query(Horde_String::convertCharset($command, $GLOBALS['registry']->getCharset(), $conf['sql']['charset'])); + $result = $db->execute(Horde_String::convertCharset($command, $GLOBALS['registry']->getCharset(), $conf['sql']['charset'])); } if (isset($result)) { if ($command) { - echo '

' . _("Query") . '


' . htmlspecialchars($command) . '
'; + echo '

' . _("Query") . '

' . htmlspecialchars($command) . '
'; } - echo '

' . _("Results") . '


'; + echo '

' . _("Results") . '

'; - if ($result instanceof PEAR_Error) { - echo '
'; var_dump($result); echo '
'; - } else { - if (is_object($result)) { - echo ''; - $first = true; - $i = 0; - while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - if ($first) { - echo ''; - foreach ($row as $key => $val) { - echo ''; - } - echo ''; - $first = false; - } + if (is_object($result)) { + echo '
' . (!strlen($key) ? ' ' : htmlspecialchars(Horde_String::convertCharset($key, $conf['sql']['charset']))) . '
'; + $first = true; + $i = 0; + while ($row = $result->fetch()) { + if ($first) { echo ''; - foreach ($row as $val) { - echo ''; + foreach ($row as $key => $val) { + echo ''; } echo ''; + $first = false; } - echo '
' . (!strlen($val) ? ' ' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '' . (!strlen($key) ? ' ' : htmlspecialchars(Horde_String::convertCharset($key, $conf['sql']['charset']))) . '
'; - } elseif (is_array($result)) { - echo ''; - $first = true; - $i = 0; - foreach ($result as $val) { - if ($first) { - echo ''; - $first = false; - } - echo ''; + echo ''; + foreach ($row as $val) { + echo ''; } - echo '
' . (isset($description) ? htmlspecialchars($description) : ' ') . '
' . (!strlen($val) ? ' ' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '
' . (!strlen($val) ? ' ' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '
'; - } else { - echo '' . _("Success") . ''; + echo ''; } + echo ''; + } elseif (is_array($result)) { + echo ''; + $first = true; + $i = 0; + foreach ($result as $val) { + if ($first) { + echo ''; + $first = false; + } + echo ''; + } + echo '
' . (isset($description) ? htmlspecialchars($description) : ' ') . '
' . (!strlen($val) ? ' ' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '
'; + } else { + echo '' . _("Success") . ''; } - - echo '
'; } ?> @@ -110,22 +100,20 @@ if (isset($result)) { - " class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;" /> - " class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value; document.sqlshell.submit();" /> -
+ " class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;"> + " class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value; document.sqlshell.submit();"> -
-" /> -" onclick="document.sqlshell.sql.value=''" /> + +"> +" onclick="document.sqlshell.sql.value=''"> -" /> +"> -getSpecialQuery('tables') !== null): ?>" /> -getSpecialQuery('databases') !== null): ?>" /> +">
diff --git a/horde/lib/Test.php b/horde/lib/Test.php index e469cf98d..c928488aa 100644 --- a/horde/lib/Test.php +++ b/horde/lib/Test.php @@ -285,10 +285,6 @@ class Horde_Test 'path' => 'Date/Calc.php', 'error' => 'Horde requires the Date_Calc class for Kronolith to calculate dates.' ), - 'DB' => array( - 'error' => 'You will need DB if you are using SQL.', - 'function' => '_checkPearDbVersion' - ), 'HTTP_Request' => array( 'error' => 'Parts of Horde (Jonah, the XML-RPC client/server) use the HTTP_Request library to retrieve URLs and do other HTTP requests.' ), @@ -654,18 +650,6 @@ class Horde_Test } /** - * Additional check for PEAR DB module for its version. - * - * @return string Returns error string on error. - */ - protected function _checkPearDbVersion() - { - if (!defined('DB_PORTABILITY_LOWERCASE')) { - return 'Your version of DB is not recent enough.'; - } - } - - /** * Check the list of required files * * @return string The HTML output.