A round of PEAR DB removal before bed
authorChuck Hagenbuch <chuck@horde.org>
Sun, 3 Oct 2010 04:47:02 +0000 (00:47 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 3 Oct 2010 15:22:51 +0000 (11:22 -0400)
agora/scripts/upgrades/2006-10-26_forums_table.php [deleted file]
agora/scripts/upgrades/2006-10-26_messages_table.php [deleted file]
agora/scripts/upgrades/2006-10-28_update_counts.php [deleted file]
agora/scripts/upgrades/2006-12-20_add_moderators_table.sql [deleted file]
folks/config/hooks.php.dist
framework/admintools/horde-create-sequence.php [deleted file]
framework/admintools/package.xml
horde/admin/sqlshell.php
horde/lib/Test.php

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 (executable)
index 05e05cd..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/php
-<?php
-/**
- * Script to migrate forums from datatree agora_forms table
- */
-
-require_once dirname(__FILE__) . '/../../lib/Application.php';
-Horde_Registry::appInit('agora', array('authentication' => '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 (executable)
index 632a49f..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/php
-<?php
-/**
- * TODO: Attachments
- *
- * Script to migrate forums from datatree agora_forms table
- */
-
-require_once dirname(__FILE__) . '/../../lib/Application.php';
-Horde_Registry::appInit('agora', array('authentication' => '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 (executable)
index 202e5fc..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/php
-<?php
-/**
- * Upgrades counters
- *
- * TODO Get rid of moderation
- */
-
-require_once dirname(__FILE__) . '/../../lib/Application.php';
-Horde_Registry::appInit('agora', array('authentication' => '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 (file)
index dad0e62..0000000
+++ /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)
-);
index 6dae6c3..9501887 100644 (file)
@@ -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 (executable)
index ec2fd09..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#!@php_bin@
-<?php
-/**
- * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @package admintools
- * @author Chuck Hagenbuch <chuck@horde.org>
- */
-
-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);
index 125a07a..2019a58 100644 (file)
@@ -35,9 +35,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <contents>
   <dir name="/">
    <file name="horde-base.php" role="script" />
-   <file name="horde-create-sequence.php" role="script">
-    <tasks:replace from="@php_bin@" to="php_bin" type="pear-config"/>
-   </file>
    <file name="horde-remove-pref.php" role="script">
     <tasks:replace from="@php_bin@" to="php_bin" type="pear-config"/>
    </file>
@@ -59,7 +56,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <phprelease>
   <filelist>
    <install name="horde-base.php" as="horde-base.php" />
-   <install name="horde-create-sequence.php" as="horde-create-sequence.php" />
    <install name="horde-remove-pref.php" as="horde-remove-pref.php" />
    <install name="horde-sql-shell.php" as="horde-sql-shell.php" />
   </filelist>
index 9f1a22f..2beb4cc 100644 (file)
@@ -18,21 +18,17 @@ require HORDE_TEMPLATES . '/admin/menu.inc';
 
 ?>
 <div>
-<h1 class="header"><?php echo $title ?></h1><br />
+<h1 class="header"><?php echo $title ?></h1>
 <form name="sqlshell" action="sqlshell.php" method="post">
 <?php Horde_Util::pformInput() ?>
 
 <?php
 
-$dbh = $injector->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 '<h1 class="header">' . _("Query") . '</h1><br /><pre class="text">' . htmlspecialchars($command) . '</pre>';
+        echo '<h1 class="header">' . _("Query") . '</h1><pre class="text">' . htmlspecialchars($command) . '</pre>';
     }
 
-    echo '<h1 class="header">' . _("Results") . '</h1><br />';
+    echo '<h1 class="header">' . _("Results") . '</h1>';
 
-    if ($result instanceof PEAR_Error) {
-        echo '<pre class="text">'; var_dump($result); echo '</pre>';
-    } else {
-        if (is_object($result)) {
-            echo '<table cellspacing="1" class="item striped">';
-            $first = true;
-            $i = 0;
-            while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
-                if ($first) {
-                    echo '<tr>';
-                    foreach ($row as $key => $val) {
-                        echo '<th align="left">' . (!strlen($key) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($key, $conf['sql']['charset']))) . '</th>';
-                    }
-                    echo '</tr>';
-                    $first = false;
-                }
+    if (is_object($result)) {
+        echo '<table cellspacing="1" class="item striped">';
+        $first = true;
+        $i = 0;
+        while ($row = $result->fetch()) {
+            if ($first) {
                 echo '<tr>';
-                foreach ($row as $val) {
-                    echo '<td class="fixed">' . (!strlen($val) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '</td>';
+                foreach ($row as $key => $val) {
+                    echo '<th align="left">' . (!strlen($key) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($key, $conf['sql']['charset']))) . '</th>';
                 }
                 echo '</tr>';
+                $first = false;
             }
-            echo '</table>';
-        } elseif (is_array($result)) {
-            echo '<table cellspacing="1" class="item striped">';
-            $first = true;
-            $i = 0;
-            foreach ($result as $val) {
-                if ($first) {
-                    echo '<tr><th align="left">' . (isset($description) ? htmlspecialchars($description) : '&nbsp;') . '</th></tr>';
-                    $first = false;
-                }
-                echo '<tr><td class="fixed">' . (!strlen($val) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '</td></tr>';
+            echo '<tr>';
+            foreach ($row as $val) {
+                echo '<td class="fixed">' . (!strlen($val) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '</td>';
             }
-            echo '</table>';
-        } else {
-            echo '<strong>' . _("Success") . '</strong>';
+            echo '</tr>';
         }
+        echo '</table>';
+    } elseif (is_array($result)) {
+        echo '<table cellspacing="1" class="item striped">';
+        $first = true;
+        $i = 0;
+        foreach ($result as $val) {
+            if ($first) {
+                echo '<tr><th align="left">' . (isset($description) ? htmlspecialchars($description) : '&nbsp;') . '</th></tr>';
+                $first = false;
+            }
+            echo '<tr><td class="fixed">' . (!strlen($val) ? '&nbsp;' : htmlspecialchars(Horde_String::convertCharset($val, $conf['sql']['charset']))) . '</td></tr>';
+        }
+        echo '</table>';
+    } else {
+        echo '<strong>' . _("Success") . '</strong>';
     }
-
-    echo '<br />';
 }
 ?>
 
@@ -110,22 +100,20 @@ if (isset($result)) {
     <option value="<?php echo htmlspecialchars($query) ?>"><?php echo htmlspecialchars($query) ?></option>
   <?php endforeach; ?>
   </select>
-  <input type="button" value="<?php echo _("Paste") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;" />
-  <input type="button" value="<?php echo _("Run") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value; document.sqlshell.submit();" />
-  <br />
+  <input type="button" value="<?php echo _("Paste") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;">
+  <input type="button" value="<?php echo _("Run") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value; document.sqlshell.submit();">
 <?php endif; ?>
 
 <label for="sql" class="hidden"><?php echo ("SQL Query") ?></label>
 <textarea class="fixed" id="sql" name="sql" rows="10" cols="80">
 <?php if (strlen($command)) echo htmlspecialchars($command) ?></textarea>
-<br />
-<input type="submit" class="button" value="<?php echo _("Execute") ?>" />
-<input type="button" class="button" value="<?php echo _("Clear Query") ?>" onclick="document.sqlshell.sql.value=''" />
+
+<input type="submit" class="button" value="<?php echo _("Execute") ?>">
+<input type="button" class="button" value="<?php echo _("Clear Query") ?>" onclick="document.sqlshell.sql.value=''">
 <?php if (strlen($command)): ?>
-<input type="reset" class="button" value="<?php echo _("Restore Last Query") ?>" />
+<input type="reset" class="button" value="<?php echo _("Restore Last Query") ?>">
 <?php endif; ?>
-<?php if ($dbh->getSpecialQuery('tables') !== null): ?><input type="submit" class="button" name="list-tables" value="<?php echo _("List Tables") ?>" /> <?php endif; ?>
-<?php if ($dbh->getSpecialQuery('databases') !== null): ?><input type="submit" class="button" name="list-dbs" value="<?php echo _("List Databases") ?>" /> <?php endif; ?>
+<input type="submit" class="button" name="list-tables" value="<?php echo _("List Tables") ?>">
 <?php echo Horde_Help::link('admin', 'admin-sqlshell') ?>
 
 </form>
index e469cf9..c928488 100644 (file)
@@ -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.