/usr/share/horde/nag/lib/LoginTasks/Task/PurgeCompleted.php is in php-horde-nag 4.2.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | <?php
/**
* Login tasks module that purges completed tasks.
*
* Copyright 2012-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package Nag
*/
class Nag_LoginTasks_Task_PurgeCompleted extends Horde_LoginTasks_Task
{
/**
* Constructor.
*/
public function __construct()
{
if ($this->interval = $GLOBALS['prefs']->getValue('purge_completed_interval')) {
if ($GLOBALS['prefs']->isLocked('purge_completed_interval')) {
$this->display = Horde_LoginTasks::DISPLAY_NONE;
}
} else {
$this->active = false;
}
}
/**
* Purge completed tasks that were completed before the configured date.
*
* @return boolean Whether any messages were purged from the mailbox.
*/
public function execute()
{
global $injector, $prefs;
/* Get the current UNIX timestamp minus the number of days specified
* in 'purge_completed_keep'. If a task has a timestamp prior to
* this value, it will be deleted. */
$del_time = new Horde_Date($_SERVER['REQUEST_TIME'] - ($prefs->getValue('purge_completed_keep') * 86400));
$del_time = $del_time->timestamp();
$tasklists = Nag::listTasklists(true, Horde_Perms::DELETE, false);
$tasks = Nag::listTasks(array(
'completed' => Nag::VIEW_COMPLETE,
'tasklists' => array_keys($tasklists))
);
$factory = $GLOBALS['injector']->getInstance('Nag_Factory_Driver');
$count = 0;
$tasks->reset();
while ($task = $tasks->each()) {
if (($task->completed_date && $task->completed_date < $del_time) ||
(!$task->completed_date && $task->modified && $task->modified->timestamp() < $del_time)) {
try {
$factory->create($task->tasklist)->delete($task->id);
++$count;
} catch (Nag_Exception $e) {
Horde::log($e->getMessage(), 'ERR');
}
}
}
$GLOBALS['notification']->push(
sprintf(ngettext("Purging %d completed task.", "Purging %d completed tasks.", $count), $count), 'horde.message');
return true;
}
/**
* Return information for the login task.
*
* @return string Description of what the operation is going to do during
* this login.
*/
public function describe()
{
return sprintf(
_("All completed tasks older than %d days will be permanently deleted."),
$GLOBALS['prefs']->getValue('purge_completed_keep')
);
}
}
|