Fix check for existing wicked page
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 Oct 2010 18:28:29 +0000 (14:28 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 7 Oct 2010 18:42:40 +0000 (14:42 -0400)
wicked/lib/Driver/sql.php
wicked/lib/Exception.php [new file with mode: 0644]

index aefab71..2b8b050 100644 (file)
@@ -622,12 +622,11 @@ class Wicked_Driver_sql extends Wicked_Driver {
         Horde::logMessage('Page ' . $pagename . ' saved with user agent ' . $GLOBALS['browser']->getAgentString(), 'DEBUG');
         Horde::logMessage('Wicked_Driver_sql::updateText(): ' . $query, 'DEBUG');
 
-        $this->_db->insert($query, $values);
-
-        /* Return an error immediately if the query failed. */
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, 'ERR');
-            return $result;
+        try {
+            $this->_db->insert($query, $values);
+        } catch (Horde_Db_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            throw new Wicked_Exception($e);
         }
 
         /* Now move on to updating the record. */
@@ -660,17 +659,15 @@ class Wicked_Driver_sql extends Wicked_Driver {
     {
         static $pageNames;
         if (!isset($pageNames) || $no_cache) {
-            $query = 'SELECT page_id, page_name FROM ' . $this->_params['table'];
-
+            $query = 'SELECT page_name FROM ' . $this->_params['table'];
             Horde::logMessage('Wicked_Driver_sql::getPages(): ' . $query, 'DEBUG');
-
-            $result = $this->_db->selectValues($query);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
+            try {
+                $result = $this->_db->selectValues($query);
+            } catch (Horde_Db_Exception $e) {
+                throw new Wicked_Exception($e);
             }
             $pageNames = $this->_convertFromDriver($result);
         }
-
         if ($special) {
             return $pageNames + $this->getSpecialPages();
         }
diff --git a/wicked/lib/Exception.php b/wicked/lib/Exception.php
new file mode 100644 (file)
index 0000000..8f6795a
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Base exception class for Wicked.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Wicked
+ */
+class Wicked_Exception extends Horde_Exception_Prior
+{
+}