3
* Login tasks module that purges completed tasks.
5
* Copyright 2012-2013 Horde LLC (http://www.horde.org/)
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.
10
* @author Michael J Rubinsky <mrubinsk@horde.org>
12
* @license http://www.horde.org/licenses/gpl GPL
15
class Nag_LoginTasks_Task_PurgeCompleted extends Horde_LoginTasks_Task
20
public function __construct()
22
if ($this->interval = $GLOBALS['prefs']->getValue('purge_completed_interval')) {
23
if ($GLOBALS['prefs']->isLocked('purge_completed_interval')) {
24
$this->display = Horde_LoginTasks::DISPLAY_NONE;
27
$this->active = false;
32
* Purge completed tasks that were completed before the configured date.
34
* @return boolean Whether any messages were purged from the mailbox.
36
public function execute()
38
global $injector, $prefs;
40
/* Get the current UNIX timestamp minus the number of days specified
41
* in 'purge_completed_keep'. If a message has a timestamp prior to
42
* this value, it will be deleted. */
43
$del_time = new Horde_Date(time() - ($prefs->getValue('purge_completed_keep') * 86400));
44
$del_time = $del_time->timestamp();
45
$tasklists = Nag::listTasklists(true, Horde_Perms::DELETE, false);
46
$tasks = Nag::listTasks(array(
47
'completed' => Nag::VIEW_COMPLETE,
48
'tasklists' => array_keys($tasklists),
49
'include_history' => false)
51
$factory = $GLOBALS['injector']->getInstance('Nag_Factory_Driver');
54
while ($task = $tasks->each()) {
55
if (($task->completed_date) && $task->completed_date < $del_time) {
57
$factory->create($task->tasklist)->delete($task->id);
59
} catch (Nag_Exception $e) {
60
Horde::logMessage($e->getMessage(), 'ERR');
65
$GLOBALS['notification']->push(
66
sprintf(ngettext("Purging %d completed task.", "Purging %d completed tasks.", $count), $count), 'horde.message');
72
* Return information for the login task.
74
* @return string Description of what the operation is going to do during
77
public function describe()
81
_("All completed tasks older than %d days will be permanently deleted."),
82
$GLOBALS['prefs']->getValue('purge_completed_keep')