From de9dbe36397c5a5c69706d2b052ea6e093b128f5 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 29 Jul 2009 12:05:06 -0600 Subject: [PATCH] Move garbage collection tasks to a SystemTask. --- imp/ajax.php | 2 +- imp/lib/Block/Foldersummary.php | 2 +- imp/lib/Block/summary.php | 2 +- imp/lib/Compose.php | 1 - imp/lib/IMP.php | 3 +- imp/lib/Imap/Tree.php | 4 +- .../LoginTasks/SystemTask/GarbageCollection.php | 58 ++++++++++++++++++++++ imp/lib/Search.php | 5 +- imp/lib/Sentmail.php | 9 +--- 9 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 imp/lib/LoginTasks/SystemTask/GarbageCollection.php diff --git a/imp/ajax.php b/imp/ajax.php index e85629f5e..3410d47ef 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -305,7 +305,7 @@ case 'Poll': $imptree = IMP_Imap_Tree::singleton(); $result->poll = array(); - foreach ($imptree->getPollList(true) as $val) { + foreach ($imptree->getPollList() as $val) { if ($info = $imptree->getElementInfo($val)) { $result->poll[$val] = intval($info['unseen']); } diff --git a/imp/lib/Block/Foldersummary.php b/imp/lib/Block/Foldersummary.php index f7f86b935..8c7f62d66 100644 --- a/imp/lib/Block/Foldersummary.php +++ b/imp/lib/Block/Foldersummary.php @@ -29,7 +29,7 @@ class IMP_Block_Foldersummary extends Horde_Block /* Get list of mailboxes to poll. */ $imptree = IMP_Imap_Tree::singleton(); - $folders = $imptree->getPollList(true, true); + $folders = $imptree->getPollList(true); $anyUnseen = false; $newmsgs = array(); diff --git a/imp/lib/Block/summary.php b/imp/lib/Block/summary.php index 73077f0d6..d644ff453 100644 --- a/imp/lib/Block/summary.php +++ b/imp/lib/Block/summary.php @@ -56,7 +56,7 @@ class Horde_Block_imp_summary extends Horde_Block /* Get list of mailboxes to poll. */ $imaptree = IMP_Imap_Tree::singleton(); - $folders = $imaptree->getPollList(true, true); + $folders = $imaptree->getPollList(true); /* Quota info, if available. */ $quota_msg = Horde_Util::bufferOutput(array('IMP', 'quota')); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index b6350e5cb..b144490a1 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1681,7 +1681,6 @@ class IMP_Compose /* Store in VFS. */ if ($conf['compose']['use_vfs']) { $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); - VFS_GC::gc($vfs, self::VFS_ATTACH_PATH, 86400); $cacheID = uniqid(mt_rand()); $result = $vfs_file diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index c06e66840..7bd73b84e 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1118,7 +1118,6 @@ class IMP /** * Set the sorting preference for the current mailbox. - * TODO: Purge non-existant search sorts (i.e. non VFolder entries). * * @param integer $by The sort type. * @param integer $dir The sort direction. @@ -1158,7 +1157,7 @@ class IMP } if ($delete || !empty($entry)) { - $GLOBALS['prefs']->setValue('sortpref', @serialize($sortpref)); + $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); } } diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index e1697c049..98c9e6ce1 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -1137,12 +1137,12 @@ class IMP_Imap_Tree /** * Initializes and returns the list of mailboxes to poll. * - * @param boolean $prune Prune non-existent folders from list? * @param boolean $sort Sort the directory list? + * @param boolean $prune Prune non-existent folders from list? * * @return array The list of mailboxes to poll. */ - public function getPollList($prune = false, $sort = false) + public function getPollList($sort = false, $prune = false) { $this->_initPollList(); diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php new file mode 100644 index 000000000..eba564ec8 --- /dev/null +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -0,0 +1,58 @@ + + * @package Horde_LoginTasks + */ +class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_SystemTask +{ + /** + * The interval at which to run the task. + * + * @var integer + */ + public $interval = Horde_LoginTasks::WEEKLY; + + /** + * Perform all functions for this task. + */ + public function execute() + { + IMP::initialize(); + + /* Purge non-existent nav_poll entries. */ + $imaptree = IMP_Imap_Tree::singleton(); + $imaptree->getPollList(true, true); + + /* Do garbage collection on sentmail entries. */ + $sentmail = IMP_Sentmail::factory(); + $sentmail->gc(); + + /* Do garbage collection on compose VFS data. */ + if ($GLOBALS['conf']['compose']['use_vfs']) { + $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type'])); + VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400); + } + + /* Purge non-existent search sorts. */ + $update = false; + $sortpref = @unserialize($GLOBALS['prefs']->getValue('sortpref')); + foreach (array_keys($sortpref) as $key) { + if ($GLOBALS['imp_search']->isSearchMbox($key) && + !$GLOBALS['imp_search']->isEditableVFolder($key)) { + unset($sortpref[$key]); + $update = true; + } + } + if ($update) { + $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); + } + } + +} diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 7b2f6f6a0..d5221e3b9 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -409,10 +409,9 @@ class IMP_Search return; } - /* Create Virtual INBOX with nav_poll list. Filter out any nav_poll - * entries that don't exist. Sort the list also. */ + /* Create Virtual INBOX with nav_poll list. */ $imaptree = IMP_Imap_Tree::singleton(); - $flist = $imaptree->getPollList(true, true); + $flist = $imaptree->getPollList(); $query = new Horde_Imap_Client_Search_Query(); $query->flag('\\seen', false); diff --git a/imp/lib/Sentmail.php b/imp/lib/Sentmail.php index 3cd71c19d..08f7fb843 100644 --- a/imp/lib/Sentmail.php +++ b/imp/lib/Sentmail.php @@ -85,8 +85,6 @@ class IMP_Sentmail $this->_log($action, $message_id, $recipient, $success); } } - - $this->gc(); } /** @@ -134,14 +132,11 @@ class IMP_Sentmail } /** - * Garbage collect log entries with a probability of 1%. + * Garbage collect log entries. */ public function gc() { - /* A 1% chance we will run garbage collection during a call. */ - if (rand(0, 99) == 0) { - $this->_deleteOldEntries(time() - $this->_params['threshold'] * 86400); - } + $this->_deleteOldEntries(time() - $this->_params['threshold'] * 86400); } /** -- 2.11.0