From 33eb7243328cac82e4f43fbc1060a9c089d7efb6 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 30 Jan 2010 11:53:52 -0700 Subject: [PATCH] Add Horde_History::removeByParent() --- framework/History/lib/Horde/History.php | 17 +++++++++++++++++ kronolith/lib/Application.php | 15 +-------------- nag/lib/Application.php | 15 +-------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/framework/History/lib/Horde/History.php b/framework/History/lib/Horde/History.php index d94ca8ac8..ebf9020fc 100644 --- a/framework/History/lib/Horde/History.php +++ b/framework/History/lib/Horde/History.php @@ -313,6 +313,23 @@ class Horde_History } /** + * Remove one or more history entries by parent. + * + * @param string $parent The parent name to remove. + * + * @throws Horde_Exception + */ + public function removeByParent($parent) + { + /* Remove entries 100 at a time. */ + $all = array_keys($this->getByTimestamp('>', 0, array(), $parent)); + + while (count($d = array_splice($all, 0, 100)) > 0) { + $this->removebyNames($d); + } + } + + /** * Remove one or more history entries by name. * * @param array $names The history entries to remove. diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index ff376c068..2e3a96a1a 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -327,20 +327,7 @@ class Kronolith_Application extends Horde_Registry_Application /* Now delete history as well. */ $history = Horde_History::singleton(); - if (method_exists($history, 'removeByParent')) { - $histories = $history->removeByParent('kronolith:' . $user); - } else { - /* Remove entries 100 at a time. */ - $all = $history->getByTimestamp('>', 0, array(), 'kronolith:' . $user); - if (is_a($all, 'PEAR_Error')) { - Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR); - } else { - $all = array_keys($all); - while (count($d = array_splice($all, 0, 100)) > 0) { - $history->removebyNames($d); - } - } - } + $histories = $history->removeByParent('kronolith:' . $user); if (is_a($result, 'PEAR_Error')) { return $result; diff --git a/nag/lib/Application.php b/nag/lib/Application.php index a5b4d741b..acdc5f8c3 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -193,20 +193,7 @@ class Nag_Application extends Horde_Registry_Application /* Now delete history as well. */ $history = Horde_History::singleton(); - if (method_exists($history, 'removeByParent')) { - $histories = $history->removeByParent('nag:' . $user); - } else { - /* Remove entries 100 at a time. */ - $all = $history->getByTimestamp('>', 0, array(), 'nag:' . $user); - if (is_a($all, 'PEAR_Error')) { - Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR); - } else { - $all = array_keys($all); - while (count($d = array_splice($all, 0, 100)) > 0) { - $history->removebyNames($d); - } - } - } + $histories = $history->removeByParent('nag:' . $user); /* ...and finally, delete the actual share */ if (!empty($share)) { -- 2.11.0