Create email log entry when creating a delivery job
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Feb 2021 10:44:32 +0000 (11:44 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 15:24:45 +0000 (16:24 +0100)
wcfsetup/install/files/lib/system/background/job/EmailDeliveryBackgroundJob.class.php

index 04eb69f33d071cf232af1bc5ac0e4e43cd7d61db..1194682e4137952eb9a1816be8c009b6275ef9fc 100644 (file)
@@ -2,9 +2,12 @@
 
 namespace wcf\system\background\job;
 
+use wcf\data\email\log\entry\EmailLogEntry;
+use wcf\data\email\log\entry\EmailLogEntryAction;
 use wcf\system\email\Email;
 use wcf\system\email\Mailbox;
 use wcf\system\email\transport\exception\PermanentFailure;
+use wcf\system\email\UserMailbox;
 
 /**
  * Delivers the given email to the given mailbox.
@@ -40,6 +43,11 @@ class EmailDeliveryBackgroundJob extends AbstractBackgroundJob
      */
     protected $envelopeTo;
 
+    /**
+     * @var int
+     */
+    protected $emailLogEntryId;
+
     /**
      * instance of the default transport
      * @var \wcf\system\email\transport\IEmailTransport
@@ -59,6 +67,24 @@ class EmailDeliveryBackgroundJob extends AbstractBackgroundJob
         $this->email = $email;
         $this->envelopeFrom = $envelopeFrom;
         $this->envelopeTo = $envelopeTo;
+
+        $this->emailLogEntryId = $this->createLog()->entryID;
+    }
+
+    /**
+     * Creates the email log entry.
+     */
+    final private function createLog(): EmailLogEntry
+    {
+        return (new EmailLogEntryAction([], 'create', [
+            'data' => [
+                'time' => \TIME_NOW,
+                'messageID' => $this->email->getMessageID(),
+                'recipient' => $this->envelopeTo->getAddress(),
+                'recipientID' => ($this->envelopeTo instanceof UserMailbox) ? $this->envelopeTo->getUser()->userID : null,
+                'status' => EmailLogEntry::STATUS_NEW,
+            ]
+        ]))->executeAction()['returnValues'];
     }
 
     /**