1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Kronolith_LoginTasks_Task_PurgeEvents extends Horde_LoginTasks_Task
15: {
16: 17: 18:
19: public function __construct()
20: {
21: $this->active = $GLOBALS['prefs']->getValue('purge_events');
22: if ($this->active) {
23: $this->interval = $GLOBALS['prefs']->getValue('purge_events_interval');
24: if ($GLOBALS['prefs']->isLocked('purge_events')) {
25: $this->display = Horde_LoginTasks::DISPLAY_NONE;
26: }
27: }
28: }
29:
30: 31: 32: 33: 34: 35:
36: public function execute()
37: {
38: 39: 40:
41: $del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
42: $del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
43:
44: 45:
46: $calendars = Kronolith::listInternalCalendars(true, Horde_Perms::DELETE);
47:
48:
49: $kronolith_driver = Kronolith::getDriver();
50: $query = new StdClass();
51: $query->start = null;
52: $query->end = $del_time;
53: $query->status = null;
54: $query->calendars = array(Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => array_keys($calendars));
55: $query->creator = $GLOBALS['registry']->getAuth();
56:
57:
58: $days = Kronolith::search($query);
59: $count = 0;
60: foreach ($days as $events) {
61: foreach ($events as $event) {
62:
63: if (!$event->recurs() ||
64: $event->recurrence->nextRecurrence($del_time) == false) {
65:
66: if ($event->calendar != $kronolith_driver->calendar) {
67: $kronolith_driver->open($event->calendar);
68: }
69: try {
70: $kronolith_driver->deleteEvent($event->id, true);
71: ++$count;
72: } catch (Exception $e) {
73: Horde::logMessage($e, 'ERR');
74: throw $e;
75: }
76: }
77: }
78: }
79:
80: $GLOBALS['notification']->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $GLOBALS['prefs']->getValue('purge_events_keep')));
81: }
82:
83: 84: 85: 86: 87: 88:
89: public function describe()
90: {
91: return sprintf(_("All of your events older than %d days will be permanently deleted."),
92: $GLOBALS['prefs']->getValue('purge_events_keep'));
93: }
94:
95: }
96: