ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler Class Reference
+ Collaboration diagram for ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler:

Public Member Functions

 __construct (private readonly ilMailCronOrphanedMails $job, private readonly ExpiredOrOrphanedMailsCollector $collector, ?ilDBInterface $db=null, ?ilSetting $setting=null, ?ilLogger $logger=null, ?callable $delete_directory_callback=null)
 
 delete ()
 

Private Member Functions

 determineDeletableAttachmentPaths ()
 
 deleteDirectory (string $directory)
 
 deleteMails ()
 
 deleteMarkedAsNotified ()
 

Private Attributes

const int PING_THRESHOLD = 250
 
readonly ilDBInterface $db
 
readonly ilSetting $settings
 
readonly ilLogger $logger
 
readonly ilDBStatement $mail_ids_for_path_stmt
 
 $delete_directory_callback
 

Detailed Description

Definition at line 36 of file MailDeletionHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::__construct ( private readonly ilMailCronOrphanedMails  $job,
private readonly ExpiredOrOrphanedMailsCollector  $collector,
?ilDBInterface  $db = null,
?ilSetting  $setting = null,
?ilLogger  $logger = null,
?callable  $delete_directory_callback = null 
)
Parameters
callable(string)void|null $delete_directory_callback

Definition at line 50 of file MailDeletionHandler.php.

57 {
58 global $DIC;
59
60 $this->db = $db ?? $DIC->database();
61 $this->settings = $setting ?? $DIC->settings();
62 $this->logger = $logger ?? ilLoggerFactory::getLogger('mail');
63 $this->delete_directory_callback = $delete_directory_callback;
64
65 $this->mail_ids_for_path_stmt = $this->db->prepare(
66 'SELECT COUNT(*) cnt FROM mail_attachment WHERE path = ?',
68 );
69 }
ilSetting $setting
Definition: class.ilias.php:68
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:26

References ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\$db, ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\$delete_directory_callback, $DIC, ILIAS\$setting, ilLoggerFactory\getLogger(), ILIAS\Repository\logger(), ILIAS\Repository\settings(), and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::delete ( )

Definition at line 210 of file MailDeletionHandler.php.

210 : void
211 {
212 if ($this->collector->mailIdsToDelete() !== []) {
213 $this->deleteAttachments();
214
215 $this->deleteMails();
216
217 $this->logger->info(
218 \sprintf(
219 'Deleted mail_ids: %s',
220 implode(', ', $this->collector->mailIdsToDelete())
221 )
222 );
223
224 $this->deleteMarkedAsNotified();
225 $this->logger->info(
226 \sprintf(
227 'Deleted mail_cron_orphaned mail_ids: %s',
228 implode(', ', $this->collector->mailIdsToDelete())
229 )
230 );
231 }
232 }

References ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\deleteMails(), ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\deleteMarkedAsNotified(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ deleteDirectory()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::deleteDirectory ( string  $directory)
private

Definition at line 114 of file MailDeletionHandler.php.

114 : void
115 {
116 if ($this->delete_directory_callback !== null) {
117 \call_user_func($this->delete_directory_callback, $directory);
118 } else {
119 ilFileUtils::delDir($directory);
120 }
121 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilFileUtils\delDir().

+ Here is the call graph for this function:

◆ deleteMails()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::deleteMails ( )
private

Definition at line 190 of file MailDeletionHandler.php.

190 : void
191 {
192 $this->db->manipulate(
193 'DELETE FROM mail WHERE ' .
194 $this->db->in('mail_id', $this->collector->mailIdsToDelete(), false, ilDBConstants::T_INTEGER)
195 );
196 }

References ilDBConstants\T_INTEGER.

Referenced by ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\delete().

+ Here is the caller graph for this function:

◆ deleteMarkedAsNotified()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::deleteMarkedAsNotified ( )
private

Definition at line 198 of file MailDeletionHandler.php.

198 : void
199 {
200 if ((int) $this->settings->get('mail_notify_orphaned', '0') >= 1) {
201 $this->db->manipulate(
202 'DELETE FROM mail_cron_orphaned WHERE ' .
203 $this->db->in('mail_id', $this->collector->mailIdsToDelete(), false, ilDBConstants::T_INTEGER)
204 );
205 } else {
206 $this->db->manipulate('DELETE FROM mail_cron_orphaned');
207 }
208 }

References ILIAS\Repository\settings(), and ilDBConstants\T_INTEGER.

Referenced by ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ determineDeletableAttachmentPaths()

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::determineDeletableAttachmentPaths ( )
private
Returns
list<string>

Definition at line 74 of file MailDeletionHandler.php.

74 : array
75 {
76 $attachment_paths = [];
77
78 $res = $this->db->query(
79 '
80 SELECT path, COUNT(mail_id) cnt_mail_ids
81 FROM mail_attachment
82 WHERE ' . $this->db->in(
83 'mail_id',
84 $this->collector->mailIdsToDelete(),
85 false,
87 ) . ' GROUP BY path'
88 );
89
90 $i = 0;
91 while ($row = $this->db->fetchAssoc($res)) {
92 if ($i > 0 && $i % self::PING_THRESHOLD) {
93 $this->job->ping();
94 }
95
96 $num_usages_total = (int) $this->db->fetchAssoc(
97 $this->db->execute(
98 $this->mail_ids_for_path_stmt,
99 [$row['path']]
100 )
101 )['cnt'];
102 $num_usages_within_deleted_mails = (int) $row['cnt_mail_ids'];
103
104 if ($num_usages_within_deleted_mails >= $num_usages_total) {
105 $attachment_paths[] = $row['path'];
106 }
107
108 ++$i;
109 }
110
111 return $attachment_paths;
112 }
$res
Definition: ltiservices.php:69

References $res, ILIAS\Repository\int(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

Field Documentation

◆ $db

readonly ilDBInterface ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::$db
private

◆ $delete_directory_callback

ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::$delete_directory_callback
private

◆ $logger

readonly ilLogger ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::$logger
private

Definition at line 42 of file MailDeletionHandler.php.

◆ $mail_ids_for_path_stmt

readonly ilDBStatement ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::$mail_ids_for_path_stmt
private

Definition at line 43 of file MailDeletionHandler.php.

◆ $settings

readonly ilSetting ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::$settings
private

Definition at line 41 of file MailDeletionHandler.php.

◆ PING_THRESHOLD

const int ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler::PING_THRESHOLD = 250
private

Definition at line 38 of file MailDeletionHandler.php.


The documentation for this class was generated from the following file: