diff --git a/DeskHub-Webseite/cron/process_mail_queue.php b/DeskHub-Webseite/cron/process_mail_queue.php new file mode 100644 index 00000000..a718c439 --- /dev/null +++ b/DeskHub-Webseite/cron/process_mail_queue.php @@ -0,0 +1,24 @@ +getAttribute(PDO::ATTR_DRIVER_NAME); + $ai = $drv === 'sqlite' ? 'INTEGER PRIMARY KEY AUTOINCREMENT' : 'INT AUTO_INCREMENT PRIMARY KEY'; + $long = $drv === 'sqlite' ? 'TEXT' : 'MEDIUMTEXT'; + $eng = $drv === 'sqlite' ? '' : ' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'; + $pdo->exec("CREATE TABLE IF NOT EXISTS mail_queue ( + id $ai, + to_email VARCHAR(255) NOT NULL, + from_header VARCHAR(255) NULL, + subject VARCHAR(500) NOT NULL, + body $long NOT NULL, + status VARCHAR(10) NOT NULL DEFAULT 'pending', + attempts INT NOT NULL DEFAULT 0, + next_attempt_at DATETIME NOT NULL, + last_error VARCHAR(400) NULL, + created_at DATETIME NOT NULL, + sent_at DATETIME NULL + )$eng"); + $pdo->exec('CREATE INDEX idx_mail_queue_due ON mail_queue (status, next_attempt_at)'); + $pdo->prepare('INSERT INTO schema_migrations (migration) VALUES (?)')->execute(['php_0064_mail_queue']); + $result['applied']++; + if ($verbose) $result['log'][] = ' [OK] php_0064_mail_queue'; + } catch (Throwable $e) { + $result['errors'][] = 'php_0064_mail_queue: ' . $e->getMessage(); + if ($verbose) $result['log'][] = ' [FAIL] php_0064_mail_queue - ' . $e->getMessage(); + } + } + return $result; }