Add wcf1_email_log_entry
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Feb 2021 10:15:39 +0000 (11:15 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 15:24:44 +0000 (16:24 +0100)
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_db.php
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryEditor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryList.class.php [new file with mode: 0644]
wcfsetup/setup/db/install.sql

index 64f65a1d6f67c69f81d6042b1937e26c6e1a2ec8..7809379b5555909cfcd7a4370f06142afdea8f48 100644 (file)
@@ -30,6 +30,32 @@ use wcf\system\package\plugin\ScriptPackageInstallationPlugin;
 use wcf\system\WCF;
 
 $tables = [
+    DatabaseTable::create('wcf1_email_log_entry')
+        ->columns([
+            ObjectIdDatabaseTableColumn::create('entryID'),
+            NotNullInt10DatabaseTableColumn::create('time'),
+            NotNullVarchar255DatabaseTableColumn::create('messageID'),
+            NotNullVarchar255DatabaseTableColumn::create('recipient'),
+            IntDatabaseTableColumn::create('recipientID')
+                ->length(10)
+                ->notNull(false),
+            NotNullVarchar255DatabaseTableColumn::create('status'),
+            TextDatabaseTableColumn::create('message'),
+        ])
+        ->indices([
+            DatabaseTablePrimaryIndex::create()
+                ->columns(['entryID']),
+            DatabaseTableIndex::create('time')
+                ->columns(['time']),
+        ])
+        ->foreignKeys([
+            DatabaseTableForeignKey::create()
+                ->columns(['recipientID'])
+                ->referencedTable('wcf1_user')
+                ->referencedColumns(['userID'])
+                ->onDelete('SET NULL'),
+        ]),
+
     // This update script was added with 5.3.3. We need to ensure that the change is applied
     // when someone attempts to upgrade from an older 5.3.x for whatever reason.
     // If the database already has the proper state this will be a simple noop.
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
new file mode 100644 (file)
index 0000000..e723646
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace wcf\data\email\log\entry;
+
+use wcf\data\DatabaseObject;
+
+/**
+ * Represents an email log entry.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\Email\Log\Entry
+ *
+ * @property-read   int    $entryID      unique id of the log entry
+ * @property-read   int    $time         timestamp when the delivery job was created
+ * @property-read   string $messageID    the email's 'Message-ID'
+ * @property-read   string $recipient    the recipient ("RCPT TO")
+ * @property-read   ?int   $recipientID  the recipient's userID (if the email is being sent to a registered user)
+ * @property-read   string $status       one of the `STATUS_*` constants
+ * @property-read   string $message      a human readable explanation for the status
+ *
+ */
+class EmailLogEntry extends DatabaseObject
+{
+    public const STATUS_NEW = 'new';
+
+    public const STATUS_SUCCESS = 'success';
+
+    public const STATUS_TRANSIENT_FAILURE = 'transient_failure';
+
+    public const STATUS_PERMANENT_FAILURE = 'permanent_failure';
+}
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
new file mode 100644 (file)
index 0000000..1348b92
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace wcf\data\email\log\entry;
+
+use wcf\data\AbstractDatabaseObjectAction;
+
+/**
+ * Executes email log entry-related actions.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\Email\Log\Entry
+ *
+ * @method  EmailLogEntry        create()
+ * @method  EmailLogEntryEditor[]    getObjects()
+ * @method  EmailLogEntryEditor      getSingleObject()
+ */
+class EmailLogEntryAction extends AbstractDatabaseObjectAction
+{
+    /**
+     * @inheritDoc
+     */
+    protected $className = EmailLogEntryEditor::class;
+}
diff --git a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryEditor.class.php b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryEditor.class.php
new file mode 100644 (file)
index 0000000..fc11a2e
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace wcf\data\email\log\entry;
+
+use wcf\data\DatabaseObjectEditor;
+
+/**
+ * Extends the email log entry object with functions to create, update and delete history entries.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\Email\Log\Entry
+ *
+ * @method static EmailLogEntry    create(array $parameters = [])
+ * @method      EmailLogEntry    getDecoratedObject()
+ * @mixin       EmailLogEntry
+ */
+class EmailLogEntryEditor extends DatabaseObjectEditor
+{
+    /**
+     * @inheritDoc
+     */
+    protected static $baseClass = EmailLogEntry::class;
+}
diff --git a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryList.class.php b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntryList.class.php
new file mode 100644 (file)
index 0000000..d7fcc40
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace wcf\data\email\log\entry;
+
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Represents a list of email log entries.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\Emaiil\Log\Entry
+ *
+ * @method  EmailLogEntry        current()
+ * @method  EmailLogEntry[]      getObjects()
+ * @method  EmailLogEntry|null       search($objectID)
+ * @property    EmailLogEntry[] $objects
+ */
+class EmailLogEntryList extends DatabaseObjectList
+{
+    /**
+     * @inheritDoc
+     */
+    public $className = EmailLogEntry::class;
+}
index c035d5d883a89bfed9f6b010144eb82a010c2ff8..9c4d5eae4fb76f78675b4f32cce33a4c5fdc04e2 100644 (file)
@@ -551,6 +551,19 @@ CREATE TABLE wcf1_edit_history_entry (
        KEY (obsoletedAt, obsoletedByUserID)
 );
 
+DROP TABLE IF EXISTS wcf1_email_log_entry;
+CREATE TABLE wcf1_email_log_entry (
+       entryID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+       time INT(10) NOT NULL,
+       messageID VARCHAR(255) NOT NULL,
+       recipient VARCHAR(255) NOT NULL,
+       recipientID INT(10) DEFAULT NULL,
+       status VARCHAR(255) NOT NULL,
+       message TEXT,
+       
+       KEY time (time)
+);
+
 DROP TABLE IF EXISTS wcf1_event_listener;
 CREATE TABLE wcf1_event_listener (
        listenerID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -1995,6 +2008,8 @@ ALTER TABLE wcf1_edit_history_entry ADD FOREIGN KEY (objectTypeID) REFERENCES wc
 ALTER TABLE wcf1_edit_history_entry ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
 ALTER TABLE wcf1_edit_history_entry ADD FOREIGN KEY (obsoletedByUserID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
 
+ALTER TABLE wcf1_email_log_entry ADD FOREIGN KEY (recipientID) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
+
 ALTER TABLE wcf1_event_listener ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
 ALTER TABLE wcf1_language_item ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE;