Prune email log entries
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Feb 2021 13:27:05 +0000 (14:27 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 15:25:20 +0000 (16:25 +0100)
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php
wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php

index 6d37ee37d01e74b703119da2e0699f67c2ae5761..b6febc13ff7da241fc9d1d5df6a4d794d85f87a1 100644 (file)
@@ -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';
index 1348b920b2557aa38610c3cea76f94b75766e9a9..5f1c35fb35a3e117092d44aa8533ef638aadbd2e 100644 (file)
@@ -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();
+    }
 }
index e6e837ad66f1d618e7d725f1fcd97397c48d3da1..d6bf033e6ce62a2467027b032e025e8fbd77b942 100644 (file)
@@ -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();
     }
 }