4 require_once
'./Services/Logging/classes/public/class.ilLoggerFactory.php';
39 $this->db = $DIC->database();
44 $this->mail_ids_for_path_stmt = $this->db->prepare(
45 'SELECT COUNT(*) cnt FROM mail_attachment WHERE path = ?',
53 private function deleteAttachments()
55 $attachment_paths = array();
57 $res = $this->db->query(
' 58 SELECT path, COUNT(mail_id) cnt_mail_ids 60 WHERE ' . $this->db->in(
'mail_id', $this->collector->getMailIdsToDelete(),
false,
'integer') .
' 64 while ($row = $this->db->fetchAssoc(
$res)) {
65 if (
$i > 0 &&
$i % self::PING_THRESHOLD) {
69 $usage_res = $this->db->execute(
70 $this->mail_ids_for_path_stmt,
74 $count_usages_data = $this->db->fetchAssoc($usage_res);
75 if (is_array($count_usages_data) && $count_usages_data !== [] && (
int) $row[
'cnt_mail_ids'] >= (
int) $count_usages_data[
'cnt']) {
77 $attachment_paths[] = $row[
'path'];
84 foreach ($attachment_paths as $path) {
85 if (
$i > 0 &&
$i % self::PING_THRESHOLD) {
90 $path = CLIENT_DATA_DIR .
'/mail/' . $path;
92 new RecursiveDirectoryIterator($path),
93 RecursiveIteratorIterator::CHILD_FIRST
96 foreach ($iter as $file) {
101 $path_name = $file->getPathname();
102 if ($file->isDir()) {
105 "Attachment directory '%s' deleted",
109 if (file_exists($path_name) && unlink($path_name)) {
111 "Attachment file '%s' deleted",
116 "Attachment file '%s' for mail_id could not be deleted " .
117 "due to missing file system permissions",
126 "Attachment directory '%s' deleted",
137 $this->db->manipulate(
'DELETE FROM mail_attachment WHERE ' . $this->db->in(
'mail_id', $this->collector->getMailIdsToDelete(),
false,
'integer'));
145 $this->db->manipulate(
'DELETE FROM mail WHERE ' . $this->db->in(
'mail_id', $this->collector->getMailIdsToDelete(),
false,
'integer'));
153 if ((
int) $this->
settings->get(
'mail_notify_orphaned') >= 1) {
154 $this->db->manipulate(
'DELETE FROM mail_cron_orphaned WHERE ' . $this->db->in(
'mail_id', $this->collector->getMailIdsToDelete(),
false,
'integer'));
156 $this->db->manipulate(
'DELETE FROM mail_cron_orphaned');
165 if (count($this->collector->getMailIdsToDelete()) > 0) {
167 $this->deleteAttachments();
170 require_once
'./Services/Logging/classes/public/class.ilLoggerFactory.php';
172 'Deleted mail_ids: %s',
173 implode(
', ', $this->collector->getMailIdsToDelete())
178 'Deleted mail_cron_orphaned mail_ids: %s',
179 implode(
', ', $this->collector->getMailIdsToDelete())
foreach($_POST as $key=> $value) $res
ilMailCronOrphanedMailsDeletionProcessor
ilMailCronOrphanedMailsDeletionCollector
__construct(ilMailCronOrphanedMails $job, ilMailCronOrphanedMailsDeletionCollector $collector)
static getLogger($a_component_id)
Get component logger.
deleteMarkedAsNotified()
Delete entries about notification.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively