Move garbage collection tasks to a SystemTask.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 29 Jul 2009 18:05:06 +0000 (12:05 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 29 Jul 2009 18:45:20 +0000 (12:45 -0600)
imp/ajax.php
imp/lib/Block/Foldersummary.php
imp/lib/Block/summary.php
imp/lib/Compose.php
imp/lib/IMP.php
imp/lib/Imap/Tree.php
imp/lib/LoginTasks/SystemTask/GarbageCollection.php [new file with mode: 0644]
imp/lib/Search.php
imp/lib/Sentmail.php

index e85629f..3410d47 100644 (file)
@@ -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']);
         }
index f7f86b9..8c7f62d 100644 (file)
@@ -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();
index 73077f0..d644ff4 100644 (file)
@@ -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'));
index b6350e5..b144490 100644 (file)
@@ -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
index c06e668..7bd73b8 100644 (file)
@@ -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));
         }
     }
 
index e1697c0..98c9e6c 100644 (file)
@@ -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 (file)
index 0000000..eba564e
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Login system task for performing periodical garbage collection.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @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));
+        }
+    }
+
+}
index 7b2f6f6..d5221e3 100644 (file)
@@ -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);
index 3cd71c1..08f7fb8 100644 (file)
@@ -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);
     }
 
     /**