ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMailCronOrphanedMailsDeletionProcessor.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
5
11{
15 protected $collector;
16
21 {
22 $this->collector = $collector;
23 }
24
28 private function deleteAttachments()
29 {
30 global $ilDB;
31
32 $attachment_paths = array();
33
34 $res = $ilDB->query('
35 SELECT path, COUNT(mail_id) cnt_mail_ids
36 FROM mail_attachment
37 WHERE '. $ilDB->in('mail_id', $this->collector->getMailIdsToDelete(), false, 'integer').'
38 GROUP BY path');
39
40 while($row = $ilDB->fetchAssoc($res))
41 {
42 $usage_res = $ilDB->queryF('SELECT mail_id, path FROM mail_attachment WHERE path = %s',
43 array('text'), array($row['path']));
44
45 $num_rows = $ilDB->numRows($usage_res);
46
47 if($row['cnt_mail_ids'] >= $num_rows)
48 {
49 // collect path to delete attachment file
50 $attachment_paths[$row['mail_id']] = $row['path'];
51 }
52 }
53
54 foreach($attachment_paths as $mail_id => $path)
55 {
56 try
57 {
58 $path = CLIENT_DATA_DIR.'/mail/'.$path;
59 $iter = new RecursiveIteratorIterator(
60 new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
61
62 foreach($iter as $file)
63 {
68 $path_name = $file->getPathname();
69 if($file->isDir())
70 {
71 @rmdir($path_name);
72 ilLoggerFactory::getLogger('mail')->info(sprintf(
73 'Attachment directory (%s) deleted for mail_id: %s', $path_name, $mail_id
74 ));
75 }
76 else
77 {
78 @unlink($path_name);
79 ilLoggerFactory::getLogger('mail')->info(sprintf(
80 'Attachment file (%s) deleted for mail_id: %s', $path_name, $mail_id
81 ));
82 }
83 }
84 @rmdir($path);
85 ilLoggerFactory::getLogger('mail')->info(sprintf(
86 'Attachment directory (%s) deleted for mail_id: %s', $path, $mail_id
87 ));
88 }
89 catch(Exception $e) { }
90 }
91
92 $ilDB->manipulate('DELETE FROM mail_attachment WHERE '. $ilDB->in('mail_id', $this->collector->getMailIdsToDelete(), false, 'integer'));
93 }
94
98 private function deleteMails()
99 {
100 global $ilDB;
101
102 $ilDB->manipulate('DELETE FROM mail WHERE ' . $ilDB->in('mail_id', $this->collector->getMailIdsToDelete(), false, 'integer'));
103 }
104
108 private function deleteMarkedAsNotified()
109 {
110 global $ilDB, $ilSetting;
111
112 if((int)$ilSetting->get('mail_notify_orphaned') >= 1)
113 {
114 $ilDB->manipulate('DELETE FROM mail_cron_orphaned WHERE ' . $ilDB->in('mail_id', $this->collector->getMailIdsToDelete(), false, 'integer'));
115 }
116 else
117 {
118 $ilDB->manipulate('DELETE FROM mail_cron_orphaned');
119 }
120 }
121
125 public function processDeletion()
126 {
127 if(count($this->collector->getMailIdsToDelete()) > 0)
128 {
129 // delete possible attachments ...
130 $this->deleteAttachments();
131
132 $this->deleteMails();
133 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
134 ilLoggerFactory::getLogger('mail')->info(sprintf(
135 'Deleted mail_ids: %s', implode(', ', $this->collector->getMailIdsToDelete())
136 ));
137
138 $this->deleteMarkedAsNotified();
139 ilLoggerFactory::getLogger('mail')->info(sprintf(
140 'Deleted mail_cron_orphaned mail_ids: %s', implode(', ', $this->collector->getMailIdsToDelete())
141 ));
142 }
143 }
144}
print $file
static getLogger($a_component_id)
Get component logger.
__construct(ilMailCronOrphanedMailsDeletionCollector $collector)
global $ilSetting
Definition: privfeed.php:40
$path
Definition: index.php:22
global $ilDB