Two more places to use Horde_Db_Adapter_Base
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 May 2010 17:58:44 +0000 (11:58 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 May 2010 17:58:44 +0000 (11:58 -0600)
framework/admintools/horde-remove-pref.php
framework/admintools/horde-sql-shell.php

index 587df57..4b69af4 100755 (executable)
 $live = false;
 
 require_once dirname(__FILE__) . '/horde-base.php';
-Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true, 'nocompress' => true));
+Horde_Registry::appInit('horde', array(
+    'authentication' => 'none',
+    'cli' => true
+));
 
-$scope = $cli->prompt(_("Enter value for pref_scope:"));
-$name = $cli->prompt(_("Enter value for pref_name:"));
+$scope = $cli->prompt('Enter value for pref_scope:');
+$name = $cli->prompt('Enter value for pref_name:');
 
 /* Open the database. */
-$db = $injector->getInstance('Horde_Db_Pear')->getOb();
+$db = $injector->getInstance('Horde_Db_Base_Adapter');
 
 if ($live) {
     $sql = 'DELETE FROM horde_prefs WHERE pref_scope = ? AND pref_name = ?';
     $values = array($scope, $name);
-    $result = $db->getAll($sql, $values);
-    if (is_a($result, 'PEAR_Error')) {
-        var_dump($result);
-    } elseif (empty($result)) {
-        $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope));
-    } else {
-        $cli->writeln(sprintf(_("Preferences \"%s\" deleted in scope \"%s\"."), $name, $scope));
+    try {
+        if ($db->delete($sql, $values)) {
+            $cli->writeln(sprintf(_("Preferences \"%s\" deleted in scope \"%s\"."), $name, $scope));
+        } else {
+            $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope));
+        }
+    } catch (Horde_Db_Exception $e) {
+        print_r($e);
     }
 } else {
     $sql = 'SELECT * FROM horde_prefs WHERE pref_scope = ? AND pref_name = ?';
     $values = array($scope, $name);
-    $result = $db->getAll($sql, $values);
-    if (empty($result)) {
-        $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope));
-    } else {
-        var_dump($result);
+    try {
+        if ($result = $db->selectAll($sql, $values)) {
+            var_dump($result);
+        } else {
+            $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope));
+        }
+    } catch (Horde_Db_Exception $e) {
+        print_r($e);
     }
 }
index 4c2e95d..2522b66 100755 (executable)
  */
 
 require_once dirname(__FILE__) . '/horde-base.php';
-Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true));
+Horde_Registry::appInit('horde', array(
+    'authentication' => 'none',
+    'cli' => true
+));
 
-$dbh = $injector->getInstance('Horde_Db_Pear')->getOb();
-
-// list databases command
-// $result = $dbh->getListOf('databases');
-
-// list tables command
-// $result = $dbh->getListOf('tables');
+$dbh = $injector->getInstance('Horde_Db_Adapter_Base');
 
 // read sql file for statements to run
 $statements = new Horde_Db_StatementParser($_SERVER['argv'][1]);
 foreach ($statements as $stmt) {
     echo "Running:\n  " . preg_replace('/\s+/', ' ', $stmt) . "\n";
-    $result = $dbh->query($stmt);
-    if (is_a($result, 'PEAR_Error')) {
-        var_dump($result);
+    try {
+        $dbh->execute($stmt);
+    } catch (Horde_Db_Exception $e) {
+        print_r($e);
         exit;
     }