Convert to H4 and exception handling
authorBen Klang <ben@alkaloid.net>
Wed, 30 Dec 2009 22:17:43 +0000 (17:17 -0500)
committerBen Klang <ben@alkaloid.net>
Wed, 30 Dec 2009 22:17:43 +0000 (17:17 -0500)
Some PEAR_Error checks are left for the PEAR DB library.  Everything else should be handled using PHP5 exceptions.

12 files changed:
beatnik/autogenerate.php
beatnik/commit.php
beatnik/delete.php
beatnik/editrec.php
beatnik/lib/Beatnik.php
beatnik/lib/Driver.php
beatnik/lib/Driver/ldap2dns.php
beatnik/lib/Driver/pdnsgsql.php
beatnik/lib/Driver/sql.php
beatnik/lib/base.php
beatnik/scripts/export_config.php
beatnik/viewzone.php

index 1e7e9ce..504a78a 100644 (file)
@@ -21,12 +21,13 @@ $form = new Autogenerate($vars);
 
 if ($form->validate($vars)) {
     if (Horde_Util::getFormData('submitbutton') == _("Autogenerate")) {
-       $result = Beatnik::autogenerate($vars);
-       if (is_a($result, 'PEAR_Error')) {
-           $notification->push($zonedata, 'horde.error');
-           header('Location:' . Horde::applicationUrl('listzones.php'));
-           exit;
-       }
+        try {
+            $result = Beatnik::autogenerate($vars);
+        } catch (Exception $e) {
+            $notification->push($e->getMessage(), 'horde.error');
+            header('Location:' . Horde::applicationUrl('listzones.php'));
+            exit;
+        }
     } else {
         $notification->push(_("Autogeneration not performed"), 'horde.warning');
     }
index 5780529..b0004bb 100644 (file)
@@ -36,13 +36,13 @@ foreach ($domains as $domain) {
     $form->setSubmitted(true);
     if ($form->validate($vars)) {
         $form->getInfo($vars, $info);
-        $result = $beatnik_driver->saveRecord($info);
 
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result->getMessage() . ': ' . $result->getDebugInfo(), 'horde.error');
-        } else {
-            $notification->push(sprintf(_('Zone serial for %s incremented.'), $domain['zonename']), 'horde.success');
+        try {
+            $result = $beatnik_driver->saveRecord($info);
+        } catch (Exception $e) {
+            $notification->push($e->getMessage(), 'horde.error');
         }
+        $notification->push(sprintf(_('Zone serial for %s incremented.'), $domain['zonename']), 'horde.success');
     } else {
         $notification->push(sprintf(_("Unable to construct valid SOA for %s.  Not incrementing serial."), $domain['zonename']), 'horde.error');
     }
index 302a53f..d975d4a 100644 (file)
@@ -20,17 +20,18 @@ $form = new DeleteRecord($vars);
 if ($form->validate($vars)) {
     $form->getInfo($vars, $info);
     if (Horde_Util::getFormData('submitbutton') == _("Delete")) {
-        $result = $beatnik_driver->deleteRecord($info);
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result->getMessage() . ': ' . $result->getDebugInfo(), 'horde.error');
+        try {
+            $result = $beatnik_driver->deleteRecord($info);
+        } catch (Exception $e) {
+            $notification->push($e->getMessage(), 'horde.error');
             header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('viewzone.php'), $info));
+            exit;
+        }
+        $notification->push(_("Record deleted"), 'horde.success');
+        if ($info['rectype'] == 'soa') {
+            header('Location: ' . Horde::applicationUrl('listzones.php'));
         } else {
-            $notification->push(_("Record deleted"), 'horde.success');
-            if ($info['rectype'] == 'soa') {
-                header('Location: ' . Horde::applicationUrl('listzones.php'));
-            } else {
-                header('Location: ' . Horde::applicationUrl('viewzone.php'));
-            }
+            header('Location: ' . Horde::applicationUrl('viewzone.php'));
         }
     } else {
         $notification->push(_("Record not deleted"), 'horde.warning');
index 718ccc0..11f5d98 100644 (file)
@@ -18,22 +18,23 @@ $form = new EditRecord($vars);
 
 if ($form->validate($vars)) {
     $form->getInfo($vars, $info);
-    $result = $beatnik_driver->saveRecord($info);
 
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage() . ': ' . $result->getDebugInfo(), 'horde.error');
+    try {
+        $result = $beatnik_driver->saveRecord($info);
+    } catch (Exception $e) {
+        $notification->push($e->getMessage(), 'horde.error');
+    }
+
+    $notification->push('Record data saved.', 'horde.success');
+
+    // Check to see if this is a new domain
+    $edit = $vars->get('id');
+    if ($info['rectype'] == 'soa' && !$edit) {
+        // if added a soa redirect to the autogeneration page
+        $url = Horde_Util::addParameter(Horde::applicationUrl('autogenerate.php'),
+                                  array('rectype' => 'soa', 'curdomain' => $info['zonename']), false, false);
     } else {
-        $notification->push('Record data saved.', 'horde.success');
-
-        // Check to see if this is a new domain
-        $edit = $vars->get('id');
-        if ($info['rectype'] == 'soa' && !$edit) {
-            // if added a soa redirect to the autogeneration page
-            $url = Horde_Util::addParameter(Horde::applicationUrl('autogenerate.php'),
-                                      array('rectype' => 'soa', 'curdomain' => $info['zonename']), false, false);
-        } else {
-            $url = Horde::applicationUrl('viewzone.php');
-        }
+        $url = Horde::applicationUrl('viewzone.php');
     }
 
     header('Location: ' . $url);
index 9a8740d..a0b385b 100644 (file)
@@ -425,7 +425,7 @@ class Beatnik {
             return true;
         } else {
             // Somebody sent something they should not have...
-            return PEAR::raiseError(_("Unable to determine if domain needs committing: invalid parameter."));
+            throw new Horde_Exception(_("Unable to determine if domain needs committing: invalid parameter."));
         }
     }
 
@@ -488,9 +488,10 @@ class Beatnik {
 
         require BEATNIK_BASE . '/config/autogenerate.php';
         $template = $templates[$vars->get('template')];
-        $zonedata = $GLOBALS['beatnik_driver']->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
-        if (is_a($zonedata, 'PEAR_Error')) {
-            return $zonedata;
+        try {
+            $zonedata = $GLOBALS['beatnik_driver']->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e);
         }
 
         foreach ($template['types'] as $rectype => $definitions) {
@@ -500,9 +501,10 @@ class Beatnik {
                 switch($definitions['replace']) {
                 case 'all':
                     foreach ($zonedata[$rectype] as $record) {
+                        try {
                         $result = $GLOBALS['beatnik_driver']->deleteRecord($record);
-                        if (is_a($result, 'PEAR_Error')) {
-                            $GLOBALS['notification']->push($result);
+                        } catch (Exception $e) {
+                            $GLOBALS['notification']->push($e);
                         }
                     }
                     break;
@@ -513,9 +515,10 @@ class Beatnik {
                         // hostname matches
                         foreach ($definitions['records'] as $Trecord) {
                             if ($record['hostname'] == $Trecord['hostname']) {
-                                $result = $GLOBALS['beatnik_driver']->deleteRecord($record);
-                                if (is_a($result, 'PEAR_Error')) {
-                                    $GLOBALS['notification']->push($result);
+                                try {
+                                    $result = $GLOBALS['beatnik_driver']->deleteRecord($record);
+                                } catch (Exception $e) {
+                                    $GLOBALS['notification']->push($e);
                                 }
                             }
                         }
@@ -534,12 +537,12 @@ class Beatnik {
                     $GLOBALS['notification']->push(_("Skipping existing identical record"));
                     continue;
                 }
-                $result = $GLOBALS['beatnik_driver']->saveRecord(array_merge($defaults, $info));
-                if (is_a($result, 'PEAR_Error')) {
+                try {
+                    $result = $GLOBALS['beatnik_driver']->saveRecord(array_merge($defaults, $info));
+                } catch (Exception $e) {
                     $GLOBALS['notification']->push($result->getMessage() . ': ' . $result->getDebugInfo(), 'horde.error');
-                } else {
-                    $GLOBALS['notification']->push(sprintf(_('Record added: %s/%s'), $rectype, $info['hostname']), 'horde.success');
                 }
+                $GLOBALS['notification']->push(sprintf(_('Record added: %s/%s'), $rectype, $info['hostname']), 'horde.success');
             }
         }
         return true;
index 2337552..3962da6 100644 (file)
@@ -57,9 +57,10 @@ class Beatnik_Driver {
      */
     function getDomains($perms = Horde_Perms::SHOW)
     {
-        $domains = $this->_getDomains();
-        if (is_a($domains, 'PEAR_Error')) {
-            $GLOBALS['notification']->push($domains->getMessage() . ': ' . $domains->getDebugInfo(), 'horde.warning');
+        try {
+            $domains = $this->_getDomains();
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e->getMessage(), 'horde.warning');
             return array();
         }
 
@@ -90,8 +91,7 @@ class Beatnik_Driver {
      *
      * @param string $domain   Domain for which to return SOA information
      *
-     * @return mixed           Array of SOA information for domain or PEAR_Error
-     *                         on failure.
+     * @return mixed           Array of SOA information for domain
      */
     function getDomain($domainname)
     {
@@ -102,7 +102,7 @@ class Beatnik_Driver {
                 return $domain;
             }
         }
-        return PEAR::raiseError(sprintf(_("Unable to read requested domain %s"), $domainname));
+        throw new Horde_Exception(sprintf(_("Unable to read requested domain %s"), $domainname));
     }
 
     /**
@@ -161,9 +161,10 @@ class Beatnik_Driver {
      */
     function recordExists($record, $rectype)
     {
-        $zonedata = $this->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
-        if (is_a($zonedata, 'PEAR_Error')) {
-            $notification->push($zonedata, 'horde.error');
+        try {
+            $zonedata = $this->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
+        } catch (Exception $e) {
+            $notification->push($e, 'horde.error');
             header('Location:' . Horde::applicationUrl('listzones.php'));
             exit;
         }
@@ -201,7 +202,7 @@ class Beatnik_Driver {
         if ($info['rectype'] == 'soa' && $info['zonename'] != $_SESSION['beatnik']['curdomain']['zonename']) {
             // Make sure the user has permissions to add domains
             if (!Beatnik::hasPermission('beatnik:domains', Horde_Perms::EDIT)) {
-                return PEAR::raiseError(_('You do not have permission to create new domains.'));
+                throw new Horde_Exception(_('You do not have permission to create new domains.'));
             }
 
             // Create a dummy old domain for comparison purposes
@@ -214,12 +215,12 @@ class Beatnik_Driver {
             if ($info['rectype'] == 'soa') {
                 $node = 'beatnik:domains:' . $info['zonename'];
                 if (!Beatnik::hasPermission($node, Horde_Perms::EDIT, 1)) {
-                    return PEAR::raiseError(_('You do not have permssion to edit the SOA of this zone.'));
+                    throw new Horde_Exception(_('You do not have permssion to edit the SOA of this zone.'));
                 }
             } else {
                 $node = 'beatnik:domains:' . $_SESSION['beatnik']['curdomain']['zonename'] . ':' . $info['id'];
                 if (!Beatnik::hasPermission($node, Horde_Perms::EDIT, 2)) {
-                    return PEAR::raiseError(_('You do not have permssion to edit this record.'));
+                    throw new Horde_Exception(_('You do not have permssion to edit this record.'));
                 }
             }
         }
@@ -228,19 +229,13 @@ class Beatnik_Driver {
         // FIXME: Modify saveRecord() to return the new (possibly changed) ID of the
         // record and then use that ID to update permissions
         $return = $this->_saveRecord($info);
-
         $oldsoa =& $_SESSION['beatnik']['curdomain'];
-
-        if (is_a($return, 'PEAR_Error')) {
-            return $return;
+        if ($info['rectype'] == 'soa' &&
+           ($oldsoa['serial'] < $info['serial'])) {
+            // Clear the commit flag (if set)
+            Beatnik::needCommit($oldsoa['zonename'], false);
         } else {
-            if ($info['rectype'] == 'soa' &&
-               ($oldsoa['serial'] < $info['serial'])) {
-                // Clear the commit flag (if set)
-                Beatnik::needCommit($oldsoa['zonename'], false);
-            } else {
-                Beatnik::needCommit($oldsoa['zonename'], true);
-            }
+            Beatnik::needCommit($oldsoa['zonename'], true);
         }
 
         // Check to see if an SOA was just added or updated.
@@ -259,21 +254,16 @@ class Beatnik_Driver {
      *
      * @param array $info  Reference to array of record information for deletion
      *
-     * @return boolean true on success, PEAR::raiseError on error
+     * @return boolean true on success
      */
     function deleteRecord(&$info)
     {
         $return = $this->_deleteRecord($info);
-
         $oldsoa =& $_SESSION['beatnik']['curdomain'];
 
-        if (is_a($return, 'PEAR_Error')) {
-            return $return;
-        } else {
-            // No need to commit if the whole zone is gone
-            if ($info['rectype'] != 'soa') {
-                Beatnik::needCommit($oldsoa['zonename'], true);
-            }
+        // No need to commit if the whole zone is gone
+        if ($info['rectype'] != 'soa') {
+            Beatnik::needCommit($oldsoa['zonename'], true);
         }
     }
 
@@ -320,7 +310,7 @@ class Beatnik_Driver {
         if (class_exists($class)) {
             return new $class($params);
         } else {
-            return PEAR::raiseError(_('Driver not found.'));
+            throw new Horde_Exception(_('Driver not found.'));
         }
     }
 
index c17f1a0..8e18f7a 100644 (file)
@@ -134,14 +134,14 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
             "(objectClass=dnszone)");
 
         if ($res === false) {
-            return PEAR::raiseError("Unable to locate any DNS zones " .
+            throw new Horde_Exception("Unable to locate any DNS zones " .
             "underneath ".$this->_params['basedn']);
         }
 
         $res = ldap_get_entries($this->_LDAP, $res);
 
         if ($res === false) {
-            return PEAR::raiseError(sprintf(_("Unable to retrieve data from LDAP results: %s"), @ldap_error($this->_LDAP)));
+            throw new Horde_Exception(sprintf(_("Unable to retrieve data from LDAP results: %s"), @ldap_error($this->_LDAP)));
         }
 
         $fields = Beatnik::getRecFields('soa');
@@ -234,14 +234,14 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
         $res = @ldap_list($this->_LDAP, $dn, '(objectClass=dnsrrset)');
 
         if ($res === false) {
-            return PEAR::raiseError("Unable to locate any DNS data for $domain");
+            throw new Horde_Exception("Unable to locate any DNS data for $domain");
         }
 
         # FIXME Cache these results
         $zonedata = array();
         $res = @ldap_get_entries($this->_LDAP, $res);
         if ($res === false) {
-            return PEAR::raiseError(sprintf(_("Internal error: %s"), @ldap_error($this->_LDAP)));
+            throw new Horde_Exception(sprintf(_("Internal error: %s"), @ldap_error($this->_LDAP)));
         }
 
         $i = 0;
@@ -289,13 +289,13 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
      *
      * @param array $info  Reference to array of record information for deletion
      *
-     * @return boolean true on success, PEAR::raiseError on error
+     * @return boolean true on success
      */
     function _deleteRecord(&$info)
     {
         // Ensure we have a record ID before continuing
         if (!isset($info['id'])) {
-            return PEAR::raiseError(_("Unable to delete record: No record ID specified."));
+            throw new Horde_Exception(_("Unable to delete record: No record ID specified."));
         }
 
         // Attribute used to identify objects
@@ -304,7 +304,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
         $suffix = $dnattr . '=' . $_SESSION['beatnik']['curdomain']['zonename'] . ',' . $this->_params['basedn'];
         if ($info['rectype'] == 'soa') {
             // FIXME: Add recursion
-            return PEAR::raiseError(_("Unsupported recursive delete."));
+            throw new Horde_Exception(_("Unsupported recursive delete."));
 
             $domain = $this->cleanDNString($info['zonename']);
             $dn = $suffix;
@@ -316,7 +316,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
 
         $res = @ldap_delete($this->_LDAP, $dn);
         if ($res === false) {
-            return PEAR::raiseError(sprintf(_("Unable to delete record.  Reason: %s"), @ldap_error($this->_LDAP)));
+            throw new Horde_Exception(sprintf(_("Unable to delete record.  Reason: %s"), @ldap_error($this->_LDAP)));
         }
         return true;
     }
@@ -329,7 +329,6 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
      * @param array $info Array from Horde_Form with record data
      *
      * @return mixed  The new or modified record ID on success;
-     *                PEAR_Error on error
      */
     function _saveRecord($info)
     {
@@ -344,7 +343,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
         }
 
         if (!$rdata) {
-            return PEAR::raiseError(_("Invalid record type specified."));
+            throw new Horde_Exception(_("Invalid record type specified."));
         }
 
         $recfields = Beatnik::getRecFields($rectype);
@@ -395,7 +394,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
 
             if (!isset($entry[$key]) && $fdata['required']) {
                 // No value available but required field
-                return PEAR::raiseError(sprintf(_("Missing required field %s to save record."), $fdata['name']));
+                throw new Horde_Exception(sprintf(_("Missing required field %s to save record."), $fdata['name']));
             }
 
             // Construct an ID for this object as a tuple of its data.
@@ -432,12 +431,12 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
                 // We have an old DN but it doesn't match the new DN.
                 // Need to rename the old object
                 if ($rectype == 'soa') {
-                    return PEAR::raiseError(_("Unsupported operation: cannot rename a domain."));
+                    throw new Horde_Exception(_("Unsupported operation: cannot rename a domain."));
                 }
                 $res = @ldap_rename($this->_LDAP, $oldRDN . ',' . $suffix,
                     $dn, $suffix, true);
                 if ($res === false) {
-                    return PEAR::raiseError(sprintf(_("Unable to rename old object.  Reason: %s"), @ldap_error($this->_LDAP)));
+                    throw new Horde_Exception(sprintf(_("Unable to rename old object.  Reason: %s"), @ldap_error($this->_LDAP)));
                 }
             }
 
@@ -447,7 +446,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
             // Modify the existing record
             $res = @ldap_mod_replace($this->_LDAP, $dn, $entry);
             if ($res === false) {
-                return PEAR::raiseError(sprintf(_("Unable to modify record.  Reason: %s"), @ldap_error($this->_LDAP)));
+                throw new Horde_Exception(sprintf(_("Unable to modify record.  Reason: %s"), @ldap_error($this->_LDAP)));
             }
 
         } else {
@@ -464,7 +463,7 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
             }
             $res = @ldap_add($this->_LDAP, $dn, $entry);
             if ($res === false) {
-                return PEAR::raiseError(sprintf(_("Unable to add record to LDAP. Reason: %s"), @ldap_error($this->_LDAP)));
+                throw new Horde_Exception(sprintf(_("Unable to add record to LDAP. Reason: %s"), @ldap_error($this->_LDAP)));
             }
         }
 
@@ -510,11 +509,11 @@ class Beatnik_Driver_ldap2dns extends Beatnik_Driver
             }
             $res = ldap_set_option($this->_LDAP, LDAP_OPT_PROTOCOL_VERSION, $this->_params['version']);
             if ($res === false) {
-                return PEAR::raiseError("Unable to set LDAP protocol version");
+                throw new Horde_Exception("Unable to set LDAP protocol version");
             }
             $res = ldap_bind($this->_LDAP, $this->_params['binddn'], $this->_params['password']);
             if ($res === false) {
-                return PEAR::raiseError("Unable to bind to the LDAP server. Check authentication credentials.");
+                throw new Horde_Exception("Unable to bind to the LDAP server. Check authentication credentials.");
             }
 
             $this->_connected = true;
index bd56351..e5fcda9 100644 (file)
@@ -64,10 +64,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      */
     function _getDomains()
     {
-       if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Internal database error.  Details have been logged for the administrator."));
-        }
+        $this->_connect();
 
         $query = 'SELECT d.id, d.name AS name, r.content AS content, ' .
                  'r.ttl AS ttl FROM ' . $this->_params['domains_table'] .
@@ -78,7 +75,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
         $domainlist =  $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
         if (is_a($domainlist, 'PEAR_Error')) {
             Horde::logMessage($domainlist, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return array();
+            throw new Horde_Exception(_("Error getting domain list.  Details have been logged for the administrator."));
         }
 
         $results = array();
@@ -114,10 +111,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      */
     function getDomain($domainname)
     {
-       if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Internal database error.  Details have been logged for the administrator."));
-        }
+        $this->_connect();
 
         $query = 'SELECT d.id AS id, d.name AS name, r.content AS content, ' .
                  'r.ttl AS ttl FROM ' . $this->_params['domains_table'] .
@@ -129,11 +123,11 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
         $result =  $this->_db->getAll($query, $values, DB_FETCHMODE_ASSOC);
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("An error occurred while searching the database.  Details have been logged for the administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Exception(_("An error occurred while searching the database.  Details have been logged for the administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
         }
 
         if (count($result) != 1) {
-            return PEAR::raiseError(_("Too many domains matched that name.  Contact your administrator."));
+            throw new Horde_Exception(_("Too many domains matched that name.  Contact your administrator."));
         }
 
         $info = $result[0];
@@ -141,7 +135,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
         $soa = explode(' ', $info['content']);
         if (count($soa) != 7) {
             Horde::logMessage(sprintf('Invalid SOA found for %s, skipping.', $info['name']), __FILE__, __LINE__, PEAR_LOG_WARN);
-            return PEAR::raiseError(_("Corrupt SOA found for zone.  Contact your administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Exception(_("Corrupt SOA found for zone.  Contact your administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
         }
 
         $ret = array();
@@ -167,10 +161,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      */
     function getRecords($domain)
     {
-       if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Internal database error.  Details have been logged for the administrator."));
-        }
+        $this->_connect();
 
         $zonedata = array();
 
@@ -186,7 +177,7 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
         $result = $this->_db->getAll($query, $values, DB_FETCHMODE_ASSOC);
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("An error occurred while searching the database.  Details have been logged for the administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Exception(_("An error occurred while searching the database.  Details have been logged for the administrator."), __FILE__, __LINE__, PEAR_LOG_ERR);
         }
 
         foreach ($result as $rec) {
@@ -272,14 +263,11 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      *
      * @param array $info Array of record data
      *
-     * @return boolean true on success, PEAR::raiseError on error
+     * @return boolean true on success
      */
     function _saveRecord($info)
     {
-       if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Internal database error.  Details have been logged for the administrator."));
-        }
+        $this->_connect();
 
         $change_date = time();
         $domain_id = $_SESSION['beatnik']['curdomain']['id'];
@@ -414,12 +402,9 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
      */
     function _deleteRecord($data)
     {
-       if (is_a(($result = $this->_connect()), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Internal database error.  Details have been logged for the administrator."));
-        }
+        $this->_connect();
 
-        return PEAR::raiseError(_("Not implemented."));
+        throw new Horde_Exception(_("Not implemented."));
     }
 
     /**
@@ -435,12 +420,13 @@ class Beatnik_Driver_pdnsgsql extends Beatnik_Driver
             return true;
         }
 
-        $result = Horde_Util::assertDriverConfig($this->_params, array('phptype'),
-                                           'PowerDNS Generic SQL',
-                                           array('driver' => 'pdnsgsql'));
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $result;
+        try {
+            $result = Horde_Util::assertDriverConfig($this->_params, array('phptype'),
+                                               'PowerDNS Generic SQL',
+                                               array('driver' => 'pdnsgsql'));
+        } catch (Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw $e;
         }
 
         if (!isset($this->_params['domains_table'])) {
index 56a639c..395f8a1 100644 (file)
@@ -141,7 +141,7 @@ class Beatnik_Driver_sql extends Beatnik_Driver
      *
      * @param array $info Array of record data
      *
-     * @return boolean true on success, PEAR::raiseError on error
+     * @return boolean true on success
      */
     function _saveRecord($info)
     {
index bdce7de..b22f992 100644 (file)
@@ -47,9 +47,10 @@ $notification->attach('status');
 require_once BEATNIK_BASE . '/lib/Beatnik.php';
 require_once BEATNIK_BASE . '/lib/Driver.php';
 
-$GLOBALS['beatnik_driver'] = Beatnik_Driver::factory();
-if (is_a($GLOBALS['beatnik_driver'], 'PEAR_Error')) {
-    Horde::fatal($GLOBALS['beatnik_driver'], __FILE__, __LINE__);
+try {
+    $GLOBALS['beatnik_driver'] = Beatnik_Driver::factory();
+} catch (Exception $e) {
+    Horde::fatal($e, __FILE__, __LINE__);
 }
 
 // Get a list of domains to work with
@@ -57,9 +58,10 @@ $domains = $GLOBALS['beatnik_driver']->getDomains();
 
 // Jump to new domain
 if (Horde_Util::getFormData('curdomain') !== null && !empty($domains)) {
-    $domain = $GLOBALS['beatnik_driver']->getDomain(Horde_Util::getFormData('curdomain'));
-    if (is_a($domain, 'PEAR_Error')) {
-        $notification->push($domain->getMessage() . ': ' . $domain->getDebugInfo(), 'horde.error');
+    try {
+        $domain = $GLOBALS['beatnik_driver']->getDomain(Horde_Util::getFormData('curdomain'));
+    } catch (Exception $e) {
+        $notification->push($e->getMessage(), 'horde.error');
         $domain = $domains[0];
     }
 
index 0d27c56..3baa394 100644 (file)
@@ -35,10 +35,10 @@ $cli = &Horde_CLI::singleton();
 
 // We accept the user name on the command-line.
 require_once 'Console/Getopt.php';
-$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u:p:t:r',
+try {
+    Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'h:u:p:t:r',
                               array('help', 'username=', 'password=', 'type=', 'rpc='));
-
-if (is_a($ret, 'PEAR_Error')) {
+} catch (Exception $e) {
     $error = _("Couldn't read command-line options.");
     Horde::logMessage($error, __FILE__, __LINE__, PEAR_LOG_DEBUG);
     $cli->fatal($error);
@@ -83,21 +83,18 @@ foreach ($opts as $opt) {
 
 // We will fetch data from RPC
 if (!empty($rpc)) {
-
-    require_once 'Horde/RPC.php';
-    $domains = Horde_RPC::request('xmlrpc', $rpc,
-                                                            'dns.getDomains',
-                                                                array(),
-                                                                    array('user' => $username,
-                                                                                'pass' => $password));
-    if (is_a($result, 'PEAR_Error')) {
-        $cli->fatal($domains);
+    try {
+        $domains = Horde_RPC::request('xmlrpc', $rpc, 'dns.getDomains', array(),
+                                      array('user' => $username,
+                                            'pass' => $password));
+    } catch (Exception $e) {
+        $cli->fatal($e);
     }
     
 // Login to horde if username & password are set and load module.
 } elseif (!empty($username) && !empty($password)) {
 
-     require_once HORDE_BASE . '/lib/base.php';
+    require_once HORDE_BASE . '/lib/base.php';
     $auth = &Horde_Auth::singleton($conf['auth']['driver']);
     if (!$auth->authenticate($username, array('password' => $password))) {
         $error = _("Login is incorrect.");
@@ -150,18 +147,18 @@ function _getRecords($domain)
     if (empty($GLOBALS['rpc'])) {
         $result = $GLOBALS['beatnik_driver']->getRecords($domain);
     } else {
+        try {
         $result = Horde_RPC::request('xmlrpc', $GLOBALS['rpc'],
-                                                            'dns.getRecords',
-                                                                array($domain),
-                                                                    array('user' => $GLOBALS['username'],
-                                                                                'pass' => $GLOBALS['password']));
+                                     'dns.getRecords',
+                                     array($domain),
+                                     array('user' => $GLOBALS['username'],
+                                     'pass' => $GLOBALS['password']));
+        } catch (Exception $e) {
+            $GLOBALS['cli']->fatal($e);
+        }
     }
     
-    if (is_a($result, 'PEAR_Error')) {
-        $GLOBALS['cli']->fatal($result);    
-    } else {
-        return $result;
-    }
+    return $result;
 }
 
 /**
index ab4ea48..eceac13 100644 (file)
@@ -10,9 +10,10 @@ define('BEATNIK_BASE', dirname(__FILE__));
 require_once BEATNIK_BASE . '/lib/base.php';
 require_once BEATNIK_BASE . '/lib/Beatnik.php';
 
-$zonedata = $beatnik_driver->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
-if (is_a($zonedata, 'PEAR_Error')) {
-    $notification->push($zonedata, 'horde.error');
+try {
+    $zonedata = $beatnik_driver->getRecords($_SESSION['beatnik']['curdomain']['zonename']);
+} catch (Exception $e) {
+    $notification->push($e, 'horde.error');
     header('Location:' . Horde::applicationUrl('listzones.php'));
     exit;
 }