1: <?php
2: /**
3: * Login system task for performing periodical garbage collection.
4: *
5: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/gpl GPL
13: * @package IMP
14: */
15: class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_SystemTask
16: {
17: /**
18: * The interval at which to run the task.
19: *
20: * @var integer
21: */
22: public $interval = Horde_LoginTasks::WEEKLY;
23:
24: /**
25: * Perform all functions for this task.
26: */
27: public function execute()
28: {
29: /* Purge non-existent nav_poll entries. */
30: $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->prunePollList();
31:
32: /* Do garbage collection on sentmail entries. */
33: $GLOBALS['injector']->getInstance('IMP_Sentmail')->gc();
34:
35: /* Do garbage collection on compose VFS data. */
36: if ($GLOBALS['conf']['compose']['use_vfs']) {
37: try {
38: $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
39: Horde_Vfs_Gc::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400);
40: } catch (Horde_Vfs_Exception $e) {}
41: }
42:
43: /* Purge non-existent search sorts. */
44: $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
45: $update = false;
46: $sortpref = @unserialize($GLOBALS['prefs']->getValue('sortpref'));
47:
48: foreach (array_keys($sortpref) as $key) {
49: if ($imp_search->isSearchMbox($key) && !$imp_search[$key]) {
50: unset($sortpref[$key]);
51: $update = true;
52: }
53: }
54:
55: if ($update) {
56: $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref));
57: }
58: }
59:
60: }
61: