From: Tim Düsterhus Date: Mon, 15 Feb 2021 13:27:05 +0000 (+0100) Subject: Prune email log entries X-Git-Tag: 5.4.0_Alpha_1~252^2~9 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ccd687e1a501838e5be9eda897e0c854f02164a6;p=GitHub%2FWoltLab%2FWCF.git Prune email log entries --- diff --git a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php index 6d37ee37d0..b6febc13ff 100644 --- a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php +++ b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php @@ -26,6 +26,8 @@ use wcf\system\email\Email; */ class EmailLogEntry extends DatabaseObject { + public const LIFETIME = 30 * 86400; + public const STATUS_NEW = 'new'; public const STATUS_SUCCESS = 'success'; diff --git a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php index 1348b920b2..5f1c35fb35 100644 --- a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php +++ b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php @@ -3,6 +3,7 @@ namespace wcf\data\email\log\entry; use wcf\data\AbstractDatabaseObjectAction; +use wcf\system\WCF; /** * Executes email log entry-related actions. @@ -22,4 +23,21 @@ class EmailLogEntryAction extends AbstractDatabaseObjectAction * @inheritDoc */ protected $className = EmailLogEntryEditor::class; + + /** + * Deletes old log entries. + */ + public function prune() + { + $sql = "SELECT entryID + FROM wcf" . WCF_N . "_email_log_entry + WHERE time < ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + (\TIME_NOW - EmailLogEntry::LIFETIME), + ]); + $entryIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + + (new self($entryIDs, 'delete'))->executeAction(); + } } diff --git a/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php index e6e837ad66..d6bf033e6c 100644 --- a/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php @@ -3,6 +3,7 @@ namespace wcf\system\cronjob; use wcf\data\cronjob\Cronjob; +use wcf\data\email\log\entry\EmailLogEntryAction; use wcf\data\object\type\ObjectTypeCache; use wcf\system\flood\FloodControl; use wcf\system\user\multifactor\EmailMultifactorMethod; @@ -237,5 +238,6 @@ class DailyCleanUpCronjob extends AbstractCronjob FloodControl::getInstance()->prune(); EmailMultifactorMethod::prune(); + (new EmailLogEntryAction([], 'prune'))->executeAction(); } }