1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task
14: {
15: 16: 17:
18: public function __construct()
19: {
20: $this->active = !empty($conf['compose']['link_attachments']) &&
21: $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep');
22: if ($this->active &&
23: $GLOBALS['prefs']->isLocked('delete_attachments_monthly_keep')) {
24: $this->display = Horde_LoginTasks::DISPLAY_NONE;
25: }
26: }
27:
28: 29: 30: 31: 32:
33: public function execute()
34: {
35: 36:
37: $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
38:
39: try {
40: $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
41: } catch (Horde_Vfs_Exception $e) {
42: return false;
43: }
44: $path = IMP_Compose::VFS_LINK_ATTACH_PATH . '/' . $GLOBALS['registry']->getAuth();
45:
46:
47: try {
48: $files = $vfs->listFolder($path, null, true, false, true);
49: } catch (Horde_Vfs_Exception $e) {
50: return false;
51: }
52:
53: $retval = false;
54: foreach ($files as $dir) {
55: $filetime = (isset($dir['date'])) ? $dir['date'] : intval(basename($dir['name']));
56: if ($del_time > $filetime) {
57: try {
58: $vfs->deleteFolder($path, $dir['name'], true);
59: $retval = true;
60: } catch (Horde_Vfs_Exception $e) {}
61: }
62: }
63:
64: return $retval;
65: }
66:
67: 68: 69: 70: 71: 72:
73: public function describe()
74: {
75: return sprintf(_("All old linked attachments more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'));
76: }
77:
78: }
79: