Use History's iterators, catch exceptions.
authorJan Schneider <jan@horde.org>
Fri, 19 Mar 2010 16:56:32 +0000 (17:56 +0100)
committerJan Schneider <jan@horde.org>
Fri, 19 Mar 2010 17:06:32 +0000 (18:06 +0100)
23 files changed:
framework/Group/Group.php
framework/Group/Group/ldap.php
framework/Group/Group/sql.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php
imp/lib/Maillog.php
kronolith/lib/Api.php
kronolith/lib/Application.php
kronolith/lib/Driver.php
kronolith/lib/Driver/Kolab.php
kronolith/lib/Driver/Sql.php
kronolith/lib/Event.php
kronolith/lib/View/Event.php
nag/lib/Api.php
nag/lib/Application.php
nag/lib/Driver.php
nag/lib/Task.php
nag/scripts/upgrades/create_missing_add_histories_sql.php
nag/view.php
turba/lib/Api.php
turba/lib/Driver.php
turba/lib/Driver/Sql.php
turba/lib/View/Browse.php
turba/lib/View/Contact.php

index 0ba3ec5..55ccec9 100644 (file)
@@ -216,6 +216,9 @@ class Group {
      * function is called.
      *
      * @param DataTreeObject_Group $group  The new group object.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function addGroup($group)
     {
@@ -236,11 +239,7 @@ class Group {
         }
 
         /* Log the addition of the group in the history log. */
-        $history = &Horde_History::singleton();
-        $log = $history->log($this->getGUID($group), array('action' => 'add'), true);
-        if (is_a($log, 'PEAR_Error')) {
-            return $log;
-        }
+        Horde_History::singleton()->log($this->getGUID($group), array('action' => 'add'), true);
 
         return $result;
     }
@@ -249,6 +248,9 @@ class Group {
      * Stores updated data - users, etc. - of a group to the backend system.
      *
      * @param DataTreeObject_Group $group  The group to update.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function updateGroup($group)
     {
@@ -263,7 +265,7 @@ class Group {
         $this->_groupCache[$group->getName()] = &$group;
 
         /* Log the update of the group users on the history log. */
-        $history = &Horde_History::singleton();
+        $history = Horde_History::singleton();
         $guid = $this->getGUID($group);
         foreach ($group->getAuditLog() as $userId => $action) {
             $history->log($guid, array('action' => $action, 'user' => $userId), true);
@@ -280,6 +282,9 @@ class Group {
      *
      * @param DataTreeObject_Group $group  The group to remove.
      * @param boolean $force               Force to remove every child.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function removeGroup($group, $force = false)
     {
@@ -294,8 +299,7 @@ class Group {
         }
         unset($this->_groupCache[$group->getName()]);
 
-        $history = &Horde_History::singleton();
-        $history->log($this->getGUID($group), array('action' => 'delete'), true);
+        Horde_History::singleton()->log($this->getGUID($group), array('action' => 'delete'), true);
 
         return $this->_datatree->remove($group, $force);
     }
index b49a399..4953f2f 100644 (file)
@@ -322,6 +322,9 @@ class Group_ldap extends Group {
      * @param LDAP_Object $group  The group to update
      *
      * @return mixed  True on success, PEAR_Error otherwise.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function updateGroup($group)
     {
@@ -348,7 +351,7 @@ class Group_ldap extends Group {
         @ldap_close($this->_ds);
 
         /* Log the update of the group users on the history log. */
-        $history = &Horde_History::singleton();
+        $history = Horde_History::singleton();
         $guid = $this->getGUID($group);
         foreach ($group->getAuditLog() as $userId => $action) {
             $history->log($guid, array('action' => $action, 'user' => $userId), true);
index ac20516..b700db0 100644 (file)
@@ -193,6 +193,9 @@ class Group_sql extends Group {
      * function is called.
      *
      * @param SQLObject_Group $group  The new group object.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function addGroup(&$group)
     {
@@ -234,11 +237,8 @@ class Group_sql extends Group {
         }
 
         /* Log the addition of the group in the history log. */
-        $history = &Horde_History::singleton();
-        $log = $history->log($this->getGUID($group), array('action' => 'add'), true);
-        if (is_a($log, 'PEAR_Error')) {
-            return $log;
-        }
+        $history = Horde_History::singleton();
+        $history->log($this->getGUID($group), array('action' => 'add'), true);
 
         return $result;
     }
@@ -247,6 +247,9 @@ class Group_sql extends Group {
      * Stores updated data - users, etc. - of a group to the backend system.
      *
      * @param SQLObject_Group $group  The group to update.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function updateGroup($group)
     {
@@ -279,7 +282,7 @@ class Group_sql extends Group {
         $this->_groupCache[$group->getName()] = &$group;
 
         /* Log the update of the group users on the history log. */
-        $history = &Horde_History::singleton();
+        $history = Horde_History::singleton();
         $guid = $this->getGUID($group);
         foreach ($group->getAuditLog() as $userId => $action) {
             $history->log($guid, array('action' => $action, 'user' => $userId), true);
@@ -297,6 +300,9 @@ class Group_sql extends Group {
      *
      * @param SQLObject_Group $group  The group to remove.
      * @param boolean $force               Force to remove every child.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     function removeGroup($group, $force = false)
     {
@@ -313,8 +319,7 @@ class Group_sql extends Group {
         }
         unset($this->_groupCache[$name]);
 
-        $history = &Horde_History::singleton();
-        $history->log($this->getGUID($group), array('action' => 'delete'), true);
+        Horde_History::singleton()->log($this->getGUID($group), array('action' => 'delete'), true);
 
         $query = 'DELETE FROM horde_groups_members WHERE group_uid = ?';
         $result = $this->_write_db->query($query, array($id));
index 3976591..f2575d9 100644 (file)
@@ -475,11 +475,10 @@ class Horde_Kolab_Storage_Data
 
         /* Log the action on this item in the history log. */
         try {
-            $history = &Horde_History::singleton();
-
-            $history_id = $app . ':' . $this->_folder->getShareId() . ':' . $object_uid;
-            $history->log($history_id, array('action' => $action, 'ts' => $mod_ts),
-                          true);
+            Horde_History::singleton()
+                ->log($app . ':' . $this->_folder->getShareId() . ':' . $object_uid,
+                      array('action' => $action, 'ts' => $mod_ts),
+                      true);
         } catch (Horde_Exception $e) {
         }
     }
index 38bb1c5..0517015 100644 (file)
@@ -55,7 +55,7 @@ class IMP_Maillog
 
             try {
                 $history->log(self::_getUniqueHistoryId($val), $params);
-            } catch (Horde_Exception $e) {
+            } catch (Exception $e) {
                 /* On error, log the error message only since informing the
                  * user is just a waste of time and a potential point of
                  * confusion, especially since they most likely don't even
@@ -71,8 +71,7 @@ class IMP_Maillog
      *
      * @param string $msg_id  The Message-ID of the message.
      *
-     * @return DataTreeObject  The DataTreeObject object containing the log
-     *                         information.
+     * @return Horde_History_Log  The object containing the log information.
      * @throws Horde_Exception
      */
     static public function getLog($msg_id)
@@ -99,7 +98,7 @@ class IMP_Maillog
         }
 
         if ($msg_history) {
-            foreach ($msg_history->getData() as $entry) {
+            foreach ($msg_history as $entry) {
                 if (($entry['action'] == 'mdn') && ($entry['type'] == $type)) {
                     return true;
                 }
@@ -139,7 +138,7 @@ class IMP_Maillog
         $tf = $GLOBALS['prefs']->getValue('time_format');
         $ret = array();
 
-        foreach ($msg_history->getData() as $entry) {
+        foreach ($msg_history as $entry) {
             $msg = null;
 
             if (isset($entry['desc'])) {
@@ -197,7 +196,7 @@ class IMP_Maillog
         $msg_ids = array_map(array('IMP_Maillog', '_getUniqueHistoryId'), $msg_ids);
 
         $history = Horde_History::singleton();
-        return $history->removeByNames($msg_ids);
+        $history->removeByNames($msg_ids);
     }
 
     /**
index 2a55942..5467d8e 100644 (file)
@@ -326,25 +326,21 @@ class Kronolith_Api extends Horde_Registry_Api
                         $existing_event = $kronolith_driver->getByUID($uid, array($calendar));
                         // Check if our event is newer then the existing - get
                         // the event's history.
-                        $history = Horde_History::singleton();
                         $created = $modified = null;
-                        $log = $history->getHistory('kronolith:' . $calendar . ':' . $uid);
                         try {
-                            if ($log) {
-                                foreach ($log->getData() as $entry) {
-                                    switch ($entry['action']) {
-                                    case 'add':
-                                        $created = $entry['ts'];
-                                        break;
-
-                                    case 'modify':
-                                        $modified = $entry['ts'];
-                                        break;
-                                    }
+                            $log = Horde_History::singleton()->getHistory('kronolith:' . $calendar . ':' . $uid);
+                            foreach ($log as $entry) {
+                                switch ($entry['action']) {
+                                case 'add':
+                                    $created = $entry['ts'];
+                                    break;
+
+                                case 'modify':
+                                    $modified = $entry['ts'];
+                                    break;
                                 }
                             }
-                        } catch (Exception $e) {
-                        }
+                        } catch (Exception $e) {}
                         if (empty($modified) && !empty($created)) {
                             $modified = $created;
                         }
@@ -484,7 +480,10 @@ class Kronolith_Api extends Horde_Registry_Api
      * @param string  $calendar   The calendar to search in.
      *
      * @return array  An array of UIDs matching the action and time criteria.
+     *
      * @throws Kronolith_Exception
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     public function listBy($action, $timestamp, $calendar = null)
     {
@@ -497,8 +496,7 @@ class Kronolith_Api extends Horde_Registry_Api
             throw new Horde_Exception_PermissionDenied();
         }
 
-        $history = Horde_History::singleton();
-        $histories = $history->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'kronolith:' . $calendar);
+        $histories = Horde_History::singleton()->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'kronolith:' . $calendar);
 
         // Strip leading kronolith:username:.
         return preg_replace('/^([^:]*:){2}/', '', array_keys($histories));
@@ -512,7 +510,9 @@ class Kronolith_Api extends Horde_Registry_Api
      * @param string $calendar The calendar to search in.
      *
      * @return integer  The timestamp for this action.
+     *
      * @throws Kronolith_Exception
+     * @throws InvalidArgumentException
      */
     public function getActionTimestamp($uid, $action, $calendar = null)
     {
@@ -525,9 +525,7 @@ class Kronolith_Api extends Horde_Registry_Api
             throw new Horde_Exception_PermissionDenied();
         }
 
-        $history = Horde_History::singleton();
-        return $history->getActionTimestamp('kronolith:' . $calendar . ':' .
-            $uid, $action);
+        return Horde_History::singleton()->getActionTimestamp('kronolith:' . $calendar . ':' . $uid, $action);
     }
 
     /**
index 58d7462..5d35b6d 100644 (file)
@@ -311,6 +311,8 @@ class Kronolith_Application extends Horde_Registry_Application
      * @param string $user  Name of user to remove data for.
      *
      * @throws Kronolith_Exception
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     public function removeUserData($user)
     {
@@ -322,8 +324,7 @@ class Kronolith_Application extends Horde_Registry_Application
         $result = Kronolith::getDriver()->removeUserData($user);
 
         /* Now delete history as well. */
-        $history = Horde_History::singleton();
-        $histories = $history->removeByParent('kronolith:' . $user);
+        Horde_History::singleton()->removeByParent('kronolith:' . $user);
 
         /* Get the user's default share */
         try {
index 6b7d187..e4b77a9 100644 (file)
@@ -319,8 +319,12 @@ class Kronolith_Driver
         $uid = $event->uid;
         if ($uid) {
             $history = Horde_History::singleton();
-            $history->log('kronolith:' . $event->calendar . ':' . $uid, array('action' => 'delete'), true);
-            $history->log('kronolith:' . $newCalendar . ':' . $uid, array('action' => 'add'), true);
+            try {
+                $history->log('kronolith:' . $event->calendar . ':' . $uid, array('action' => 'delete'), true);
+                $history->log('kronolith:' . $newCalendar . ':' . $uid, array('action' => 'add'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
     }
 
index 5edb7ad..73a3858 100644 (file)
@@ -377,8 +377,11 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
         Kronolith::sendNotification($event, $edit ? 'edit' : 'add');
 
         /* Log the creation/modification of this item in the history log. */
-        $history = Horde_History::singleton();
-        $history->log('kronolith:' . $event->calendar . ':' . $event->uid, $action, true);
+        try {
+            Horde_History::singleton()->log('kronolith:' . $event->calendar . ':' . $event->uid, $action, true);
+        } catch (Exception $e) {
+            Horde::logMessage($e, 'ERR');
+        }
 
         // refresh IMAP cache
         $this->synchronize(true);
@@ -465,8 +468,11 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
             }
 
             /* Log the deletion of this item in the history log. */
-            $history = Horde_History::singleton();
-            $history->log('kronolith:' . $event->calendar . ':' . $event->uid, array('action' => 'delete'), true);
+            try {
+                Horde_History::singleton()->log('kronolith:' . $event->calendar . ':' . $event->uid, array('action' => 'delete'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
 
             if (is_callable('Kolab', 'triggerFreeBusyUpdate')) {
                 //Kolab::triggerFreeBusyUpdate($this->_store->parseFolder($event->calendar));
index 845337b..dbe82cf 100644 (file)
@@ -562,8 +562,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
 
             /* Log the modification of this item in the history log. */
             if ($event->uid) {
-                $history = Horde_History::singleton();
-                $history->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'modify'), true);
+                try {
+                    Horde_History::singleton()->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'modify'), true);
+                } catch (Exception $e) {
+                    Horde::logMessage($e, 'ERR');
+                }
             }
 
             /* Update tags */
@@ -624,8 +627,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         $this->handleError($result);
 
         /* Log the creation of this item in the history log. */
-        $history = Horde_History::singleton();
-        $history->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true);
+        try {
+            Horde_History::singleton()->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true);
+        } catch (Exception $e) {
+            Horde::logMessage($e, 'ERR');
+        }
 
         /* Deal with any tags */
         $tagger = Kronolith::getTagger();
@@ -723,8 +729,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
 
         /* Log the deletion of this item in the history log. */
         if ($event->uid) {
-            $history = Horde_History::singleton();
-            $history->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'delete'), true);
+            try {
+                Horde_History::singleton()->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'delete'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         /* Remove the event from any resources that are attached to it */
index 6dc1f05..a63ff09 100644 (file)
@@ -513,25 +513,21 @@ abstract class Kronolith_Event
         $vEvent->setAttribute('UID', $this->uid);
 
         /* Get the event's history. */
-        $history = &Horde_History::singleton();
         $created = $modified = null;
         try {
-            $log = $history->getHistory('kronolith:' . $this->calendar . ':' . $this->uid);
-            if ($log) {
-                foreach ($log->getData() as $entry) {
-                    switch ($entry['action']) {
-                    case 'add':
-                        $created = $entry['ts'];
-                        break;
+            $log = Horde_History::singleton()->getHistory('kronolith:' . $this->calendar . ':' . $this->uid);
+            foreach ($log as $entry) {
+                switch ($entry['action']) {
+                case 'add':
+                    $created = $entry['ts'];
+                    break;
 
-                    case 'modify':
-                        $modified = $entry['ts'];
-                        break;
-                    }
+                case 'modify':
+                    $modified = $entry['ts'];
+                    break;
                 }
             }
-        } catch (Exception $e) {
-        }
+        } catch (Exception $e) {}
         if (!empty($created)) {
             $vEvent->setAttribute($v1 ? 'DCREATED' : 'CREATED', $created);
             if (empty($modified)) {
@@ -1206,7 +1202,7 @@ abstract class Kronolith_Event
      * @param boolean $full        Whether to return all event details.
      * @param string $time_format  The date() format to use for time formatting.
      *
-     * @return object  A simple object.
+     * @return stdClass  A simple object.
      */
     public function toJson($allDay = null, $full = false, $time_format = 'H:i')
     {
index 900f0c5..6dca486 100644 (file)
@@ -51,35 +51,31 @@ class Kronolith_View_Event {
         $userId = Horde_Auth::getAuth();
         if ($this->event->uid) {
             /* Get the event's history. */
-            $history = &Horde_History::singleton();
             try {
-                $log = $history->getHistory('kronolith:' . $this->event->calendar . ':' .
-                                            $this->event->uid);
-                if ($log) {
-                    foreach ($log->getData() as $entry) {
-                        switch ($entry['action']) {
-                        case 'add':
-                            $created = new Horde_Date($entry['ts']);
-                            if ($userId != $entry['who']) {
-                                $createdby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
-                            } else {
-                                $createdby = _("by me");
-                            }
-                            break;
-
-                        case 'modify':
-                            $modified = new Horde_Date($entry['ts']);
-                            if ($userId != $entry['who']) {
-                                $modifiedby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
-                            } else {
-                                $modifiedby = _("by me");
-                            }
-                            break;
+                $log = Horde_History::singleton()
+                    ->getHistory('kronolith:' . $this->event->calendar . ':' . $this->event->uid);
+                foreach ($log as $entry) {
+                    switch ($entry['action']) {
+                    case 'add':
+                        $created = new Horde_Date($entry['ts']);
+                        if ($userId != $entry['who']) {
+                            $createdby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
+                        } else {
+                            $createdby = _("by me");
                         }
+                        break;
+
+                    case 'modify':
+                        $modified = new Horde_Date($entry['ts']);
+                        if ($userId != $entry['who']) {
+                            $modifiedby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
+                        } else {
+                            $modifiedby = _("by me");
+                        }
+                        break;
                     }
                 }
-            } catch (Exception $e) {
-            }
+            } catch (Exception $e) {}
         }
 
         $creatorId = $this->event->creator;
index 5883445..ccac405 100644 (file)
@@ -477,9 +477,9 @@ class Nag_Api extends Horde_Registry_Api
                         // the task's history.
                         $history = Horde_History::singleton();
                         $created = $modified = null;
-                        $log = $history->getHistory('nag:' . $tasklist . ':' . $task->uid);
-                        if ($log && !is_a($log, 'PEAR_Error')) {
-                            foreach ($log->getData() as $entry) {
+                        try {
+                            $log = $history->getHistory('nag:' . $tasklist . ':' . $task->uid);
+                            foreach ($log as $entry) {
                                 switch ($entry['action']) {
                                 case 'add':
                                     $created = $entry['ts'];
@@ -490,7 +490,7 @@ class Nag_Api extends Horde_Registry_Api
                                     break;
                                 }
                             }
-                        }
+                        } catch (Exception $e) {}
                         if (empty($modified) && !empty($add)) {
                             $modified = $add;
                         }
@@ -679,6 +679,9 @@ class Nag_Api extends Horde_Registry_Api
      *                            user's default tasklist will be used.
      *
      * @return array  An array of UIDs matching the action and time criteria.
+     *
+     * @throws Horde_History_Exception
+     * @throws InvalidArgumentException
      */
     public function listBy($action, $timestamp, $tasklist = null)
     {
@@ -691,11 +694,7 @@ class Nag_Api extends Horde_Registry_Api
                 return PEAR::raiseError(_("Permission Denied"));
             }
 
-        $history = Horde_History::singleton();
-        $histories = $history->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'nag:' . $tasklist);
-        if (is_a($histories, 'PEAR_Error')) {
-            return $histories;
-        }
+        $histories = Horde_History::singleton()->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'nag:' . $tasklist);
 
         // Strip leading nag:username:.
         return preg_replace('/^([^:]*:){2}/', '', array_keys($histories));
@@ -710,6 +709,8 @@ class Nag_Api extends Horde_Registry_Api
      *                         user's default tasklist will be used.
      *
      * @return integer  The timestamp for this action.
+     *
+     * @throws InvalidArgumentException
      */
     public function getActionTimestamp($uid, $action, $tasklist = null)
     {
@@ -722,8 +723,7 @@ class Nag_Api extends Horde_Registry_Api
                 return PEAR::raiseError(_("Permission Denied"));
             }
 
-        $history = Horde_History::singleton();
-        return $history->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
+        return Horde_History::singleton()->getActionTimestamp('nag:' . $tasklist . ':' . $uid, $action);
     }
 
     /**
index 50e015d..4fb0d9f 100644 (file)
@@ -179,8 +179,7 @@ class Nag_Application extends Horde_Registry_Application
         }
 
         /* Now delete history as well. */
-        $history = Horde_History::singleton();
-        $histories = $history->removeByParent('nag:' . $user);
+        Horde_History::singleton()->removeByParent('nag:' . $user);
 
         /* ...and finally, delete the actual share */
         if (!empty($share)) {
index a50780c..15ea959 100644 (file)
@@ -227,11 +227,19 @@ class Nag_Driver
 
         /* Log the creation of this item in the history log. */
         $history = Horde_History::singleton();
-        $history->log('nag:' . $this->_tasklist . ':' . $uid, array('action' => 'add'), true);
+        try {
+            $history->log('nag:' . $this->_tasklist . ':' . $uid, array('action' => 'add'), true);
+        } catch (Exception $e) {
+            Horde::logMessage($e, 'ERR');
+        }
 
         /* Log completion status changes. */
         if ($completed) {
-            $history->log('nag:' . $this->_tasklist . ':' . $uid, array('action' => 'complete'), true);
+            try {
+                $history->log('nag:' . $this->_tasklist . ':' . $uid, array('action' => 'complete'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         /* Notify users about the new event. */
@@ -330,8 +338,16 @@ class Nag_Driver
             /* Log the moving of this item in the history log. */
             if (!empty($task->uid)) {
                 $history = Horde_History::singleton();
-                $history->log('nag:' . $task->tasklist . ':' . $task->uid, array('action' => 'delete'), true);
-                $history->log('nag:' . $tasklist . ':' . $task->uid, array('action' => 'add'), true);
+                try {
+                    $history->log('nag:' . $task->tasklist . ':' . $task->uid, array('action' => 'delete'), true);
+                } catch (Exception $e) {
+                    Horde::logMessage($e, 'ERR');
+                }
+                try {
+                    $history->log('nag:' . $tasklist . ':' . $task->uid, array('action' => 'add'), true);
+                } catch (Exception $e) {
+                    Horde::logMessage($e, 'ERR');
+                }
                 $log_tasklist = $tasklist;
             }
         }
@@ -351,18 +367,24 @@ class Nag_Driver
 
         /* Log the modification of this item in the history log. */
         if (!empty($task->uid)) {
-            $history = Horde_History::singleton();
-            $history->log('nag:' . $log_tasklist . ':' . $task->uid, array('action' => 'modify'), true);
+            try {
+                Horde_History::singleton()->log('nag:' . $log_tasklist . ':' . $task->uid, array('action' => 'modify'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         /* Log completion status changes. */
         if ($task->completed != $completed) {
-            $history = Horde_History::singleton();
             $attributes = array('action' => 'complete');
             if (!$completed) {
                 $attributes['ts'] = 0;
             }
-            $history->log('nag:' . $log_tasklist . ':' . $task->uid, $attributes, true);
+            try {
+                Horde_History::singleton()->log('nag:' . $log_tasklist . ':' . $task->uid, $attributes, true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         /* Notify users about the changed event. */
@@ -391,8 +413,11 @@ class Nag_Driver
 
         /* Log the deletion of this item in the history log. */
         if (!empty($task->uid)) {
-            $history = Horde_History::singleton();
-            $history->log('nag:' . $this->_tasklist . ':' . $task->uid, array('action' => 'delete'), true);
+            try {
+                Horde_History::singleton()->log('nag:' . $this->_tasklist . ':' . $task->uid, array('action' => 'delete'), true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         /* Notify users about the deleted event. */
index 4b99756..6491d2e 100644 (file)
@@ -851,10 +851,10 @@ class Nag_Task {
         }
 
         /* Get the task's history. */
-        $history = Horde_History::singleton();
-        $log = $history->getHistory('nag:' . $this->tasklist . ':' . $this->uid);
-        if ($log && !is_a($log, 'PEAR_Error')) {
-            foreach ($log->getData() as $entry) {
+        $created = $modified = null;
+        try {
+            $log = Horde_History::singleton()->getHistory('nag:' . $this->tasklist . ':' . $this->uid);
+            foreach ($log as $entry) {
                 switch ($entry['action']) {
                 case 'add':
                     $created = $entry['ts'];
@@ -865,7 +865,7 @@ class Nag_Task {
                     break;
                 }
             }
-        }
+        } catch (Exception $e) {}
         if (!empty($created)) {
             $vTodo->setAttribute($v1 ? 'DCREATED' : 'CREATED', $created);
             if (empty($modified)) {
index 45a13fd..95c7a19 100755 (executable)
@@ -28,7 +28,7 @@ foreach ($tasklists as $tasklist => $share) {
     foreach ($tasks as $taskId => $task) {
         $log = $history->getHistory('nag:' . $tasklist . ':' . $task['uid']);
         $created = false;
-        foreach ($log->getData() as $entry) {
+        foreach ($log as $entry) {
             if ($entry['action'] == 'add') {
                 $created = true;
                 break;
index 5cba965..17f82fa 100644 (file)
@@ -61,10 +61,9 @@ $userId = Horde_Auth::getAuth();
 $createdby = '';
 $modifiedby = '';
 if (!empty($task->uid)) {
-    $history = Horde_History::singleton();
-    $log = $history->getHistory('nag:' . $tasklist_id . ':' . $task->uid);
-    if ($log && !is_a($log, 'PEAR_Error')) {
-        foreach ($log->getData() as $entry) {
+    try {
+        $log = Horde_History::singleton()->getHistory('nag:' . $tasklist_id . ':' . $task->uid);
+        foreach ($log as $entry) {
             switch ($entry['action']) {
             case 'add':
                 $created = $entry['ts'];
@@ -90,7 +89,7 @@ if (!empty($task->uid)) {
                 }
             }
         }
-    }
+    } catch (Exception $e) {}
 }
 
 $title = $task->name;
index eaac649..2364228 100644 (file)
@@ -487,7 +487,9 @@ class Turba_Api extends Horde_Registry_Api
      *                               history.
      *
      * @return array  An array of UIDs matching the action and time criteria.
+     *
      * @throws Horde_Exception
+     * @throws InvalidArgumentException
      */
     public function listBy($action, $timestamp, $sources = null)
     {
@@ -507,6 +509,7 @@ class Turba_Api extends Horde_Registry_Api
         }
 
         $uids = array();
+        $history = Horde_History::singleton();
         foreach ($sources as $source) {
             if (empty($source) || !isset($cfgSources[$source])) {
                 throw new Horde_Exception(sprintf(_("Invalid address book: %s"), $source));
@@ -517,17 +520,18 @@ class Turba_Api extends Horde_Registry_Api
                 throw new Horde_Exception(sprintf(_("Connection failed: %s"), $driver->getMessage()));
             }
 
-            $histories = Horde_History::singleton()->getByTimestamp('>', $timestamp,
+            $histories = $history->getByTimestamp(
+                '>', $timestamp,
                 array(array('op' => '=',
-                'field' => 'action',
-                'value' => $action)),
+                            'field' => 'action',
+                            'value' => $action)),
                 'turba:' . $driver->getName());
 
             // Strip leading turba:addressbook:.
             $uids = array_merge($uids,
-                str_replace('turba:' . $driver->getName() . ':',
-                '',
-                array_keys($histories)));
+                                str_replace('turba:' . $driver->getName() . ':',
+                                            '',
+                                            array_keys($histories)));
         }
 
         return $uids;
@@ -543,7 +547,9 @@ class Turba_Api extends Horde_Registry_Api
      *                               history.
      *
      * @return integer  The timestamp for this action.
+     *
      * @throws Horde_Exception
+     * @throws InvalidArgumentException
      */
     public function getActionTimestamp($uid, $action, $sources = null)
     {
@@ -563,6 +569,7 @@ class Turba_Api extends Horde_Registry_Api
         }
 
         $last = 0;
+        $history = Horde_History::singleton();
         foreach ($sources as $source) {
             if (empty($source) || !isset($cfgSources[$source])) {
                 throw new Horde_Exception(sprintf(_("Invalid address book: %s"), $source));
@@ -573,7 +580,6 @@ class Turba_Api extends Horde_Registry_Api
                 throw new Horde_Exception(sprintf(_("Connection failed: %s"), $driver->getMessage()));
             }
 
-            $history = Horde_History::singleton();
             $ts = $history->getActionTimestamp('turba:' . $driver->getName()
                 . ':' . $uid,
                 $action);
index e5471fc..854e905 100644 (file)
@@ -783,9 +783,13 @@ class Turba_Driver
         }
 
         /* Log the creation of this item in the history log. */
-        $history = &Horde_History::singleton();
-        $history->log('turba:' . $this->getName() . ':' . $uid,
+        try {
+            Horde_History::singleton()
+                ->log('turba:' . $this->getName() . ':' . $uid,
                       array('action' => 'add'), true);
+        } catch (Exception $e) {
+            Horde::logMessage($e, 'ERR');
+        }
 
         return $key;
     }
@@ -836,9 +840,13 @@ class Turba_Driver
 
         /* Log the deletion of this item in the history log. */
         if ($object->getValue('__uid')) {
-            $history = Horde_History::singleton();
-            $history->log($object->getGuid(),
-                          array('action' => 'delete'), true);
+            try {
+                Horde_History::singleton()->log($object->getGuid(),
+                                                array('action' => 'delete'),
+                                                true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
 
         return true;
@@ -879,9 +887,13 @@ class Turba_Driver
 
         /* Log the modification of this item in the history log. */
         if ($object->getValue('__uid')) {
-            $history = &Horde_History::singleton();
-            $history->log($object->getGuid(),
-                          array('action' => 'modify'), true);
+            try {
+                Horde_History::singleton()->log($object->getGuid(),
+                                                array('action' => 'modify'),
+                                                true);
+            } catch (Exception $e) {
+                Horde::logMessage($e, 'ERR');
+            }
         }
         return $object_id;
     }
index cb9c7a7..93ee615 100644 (file)
@@ -362,13 +362,18 @@ class Turba_Driver_Sql extends Turba_Driver
         }
 
         /* Update Horde_History */
-        $history = &Horde_History::singleton();
-        while($ids->fetchInto($row)) {
-            // This is slightly hackish, but it saves us from having to create
-            // and save an array of Turba_Objects before we delete them, just to
-            // be able to calculate this using Turba_Object#getGuid
-            $guid = 'turba:' . $this->getName() . ':' . $row[0];
-            $history->log($guid, array('action' => 'delete'), true);
+        $history = Horde_History::singleton();
+        try {
+            while ($ids->fetchInto($row)) {
+                // This is slightly hackish, but it saves us from having to
+                // create and save an array of Turba_Objects before we delete
+                // them, just to be able to calculate this using
+                // Turba_Object#getGuid
+                $guid = 'turba:' . $this->getName() . ':' . $row[0];
+                $history->log($guid, array('action' => 'delete'), true);
+            }
+        } catch (Exception $e) {
+            Horde::logMessage($e, 'ERR');
         }
 
         return true;
index 8a7edfe..71831c4 100644 (file)
@@ -218,9 +218,14 @@ class Turba_View_Browse {
                         /* Log the adding of this item in the history again,
                          * because otherwise the delete log would be after the
                          * add log. */
-                        $history = Horde_History::singleton();
-                        $history->log('turba:' . $targetDriver->getName() . ':' . $objAttributes['__uid'],
-                                      array('action' => 'add'), true);
+                        try {
+                            Horde_History::singleton()
+                                ->log('turba:' . $targetDriver->getName() . ':' . $objAttributes['__uid'],
+                                      array('action' => 'add'),
+                                      true);
+                        } catch (Exception $e) {
+                            Horde::logMessage($e, 'ERR');
+                        }
                     }
                 }
                 break;
index 7d5d9fe..c3c0aaa 100644 (file)
@@ -46,10 +46,9 @@ class Turba_View_Contact {
 
         /* Get the contact's history. */
         if ($this->contact->getValue('__uid')) {
-            $history = Horde_History::singleton();
-            $log = $history->getHistory($this->contact->getGuid());
-            if ($log && !is_a($log, 'PEAR_Error')) {
-                foreach ($log->getData() as $entry) {
+            try {
+                $log = Horde_History::singleton()->getHistory($this->contact->getGuid());
+                foreach ($log as $entry) {
                     switch ($entry['action']) {
                     case 'add':
                         if ($userId != $entry['who']) {
@@ -74,7 +73,7 @@ class Turba_View_Contact {
                         break;
                     }
                 }
-            }
+            } catch (Exception $e) {}
         }
 
         echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>';