From e9bbdcadead3594fe6e608e0e530895d7d2c616e Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Mar 2010 17:56:32 +0100 Subject: [PATCH] Use History's iterators, catch exceptions. --- framework/Group/Group.php | 20 ++++++---- framework/Group/Group/ldap.php | 5 ++- framework/Group/Group/sql.php | 21 ++++++---- .../Kolab_Storage/lib/Horde/Kolab/Storage/Data.php | 9 ++--- imp/lib/Maillog.php | 11 +++--- kronolith/lib/Api.php | 38 +++++++++--------- kronolith/lib/Application.php | 5 ++- kronolith/lib/Driver.php | 8 +++- kronolith/lib/Driver/Kolab.php | 14 +++++-- kronolith/lib/Driver/Sql.php | 21 +++++++--- kronolith/lib/Event.php | 26 ++++++------ kronolith/lib/View/Event.php | 46 ++++++++++------------ nag/lib/Api.php | 22 +++++------ nag/lib/Application.php | 3 +- nag/lib/Driver.php | 45 ++++++++++++++++----- nag/lib/Task.php | 10 ++--- .../upgrades/create_missing_add_histories_sql.php | 2 +- nag/view.php | 9 ++--- turba/lib/Api.php | 20 ++++++---- turba/lib/Driver.php | 28 +++++++++---- turba/lib/Driver/Sql.php | 19 +++++---- turba/lib/View/Browse.php | 11 ++++-- turba/lib/View/Contact.php | 9 ++--- 23 files changed, 236 insertions(+), 166 deletions(-) diff --git a/framework/Group/Group.php b/framework/Group/Group.php index 0ba3ec52c..55ccec9cc 100644 --- a/framework/Group/Group.php +++ b/framework/Group/Group.php @@ -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); } diff --git a/framework/Group/Group/ldap.php b/framework/Group/Group/ldap.php index b49a3993f..4953f2f30 100644 --- a/framework/Group/Group/ldap.php +++ b/framework/Group/Group/ldap.php @@ -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); diff --git a/framework/Group/Group/sql.php b/framework/Group/Group/sql.php index ac20516d4..b700db034 100644 --- a/framework/Group/Group/sql.php +++ b/framework/Group/Group/sql.php @@ -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)); diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php index 39765913d..f2575d9d0 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Data.php @@ -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) { } } diff --git a/imp/lib/Maillog.php b/imp/lib/Maillog.php index 38bb1c564..0517015b1 100644 --- a/imp/lib/Maillog.php +++ b/imp/lib/Maillog.php @@ -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); } /** diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index 2a55942ef..5467d8e01 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -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); } /** diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 58d7462b5..5d35b6d02 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -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 { diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 6b7d187d6..e4b77a9c3 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -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'); + } } } diff --git a/kronolith/lib/Driver/Kolab.php b/kronolith/lib/Driver/Kolab.php index 5edb7add8..73a385870 100644 --- a/kronolith/lib/Driver/Kolab.php +++ b/kronolith/lib/Driver/Kolab.php @@ -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)); diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 845337b92..dbe82cf5e 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -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 */ diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 6dc1f05c4..a63ff0920 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -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') { diff --git a/kronolith/lib/View/Event.php b/kronolith/lib/View/Event.php index 900f0c523..6dca48647 100644 --- a/kronolith/lib/View/Event.php +++ b/kronolith/lib/View/Event.php @@ -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; diff --git a/nag/lib/Api.php b/nag/lib/Api.php index 588344523..ccac40538 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -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); } /** diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 50e015d53..4fb0d9feb 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -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)) { diff --git a/nag/lib/Driver.php b/nag/lib/Driver.php index a50780c9a..15ea959b2 100644 --- a/nag/lib/Driver.php +++ b/nag/lib/Driver.php @@ -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. */ diff --git a/nag/lib/Task.php b/nag/lib/Task.php index 4b9975631..6491d2e0b 100644 --- a/nag/lib/Task.php +++ b/nag/lib/Task.php @@ -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)) { diff --git a/nag/scripts/upgrades/create_missing_add_histories_sql.php b/nag/scripts/upgrades/create_missing_add_histories_sql.php index 45a13fdad..95c7a190d 100755 --- a/nag/scripts/upgrades/create_missing_add_histories_sql.php +++ b/nag/scripts/upgrades/create_missing_add_histories_sql.php @@ -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; diff --git a/nag/view.php b/nag/view.php index 5cba9654c..17f82fa16 100644 --- a/nag/view.php +++ b/nag/view.php @@ -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; diff --git a/turba/lib/Api.php b/turba/lib/Api.php index eaac649d4..236422886 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -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); diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index e5471fc36..854e9057d 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -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; } diff --git a/turba/lib/Driver/Sql.php b/turba/lib/Driver/Sql.php index cb9c7a7dc..93ee6152e 100644 --- a/turba/lib/Driver/Sql.php +++ b/turba/lib/Driver/Sql.php @@ -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; diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index 8a7edfec3..71831c4ee 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -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; diff --git a/turba/lib/View/Contact.php b/turba/lib/View/Contact.php index 7d5d9fe80..c3c0aaa39 100644 --- a/turba/lib/View/Contact.php +++ b/turba/lib/View/Contact.php @@ -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 '