Upload via GUI (346 Dateien)

This commit is contained in:
2026-10-28 07:55:07 +00:00
parent c7f79db919
commit e18614672f
3 changed files with 57 additions and 0 deletions
@@ -0,0 +1,24 @@
<?php
// Direkter Web-Zugriff wird geblockt (nur CLI oder Einbindung aus dem Backend/Pseudo-Cron).
if (php_sapi_name() !== 'cli' && !defined('DESKHUB_CRON_RUNNER')) { http_response_code(403); exit('Kein Web-Zugriff.'); }
/**
* cron/process_mail_queue.php
*
* Versucht Mails erneut zu senden, die wegen einer Störung (SMTP-Server nicht erreichbar, falscher Port …) nicht rausgingen.
* Läuft alle paar Minuten, z. B. per Cronjob:
* * /5 * * * * /usr/bin/php /pfad/zu/deskhub/cron/process_mail_queue.php
*/
require_once __DIR__ . '/../includes/bootstrap.php';
/** @return array{sent:int, failed:int, retry:int, gave_up:int, log:string[]} */
function run_process_mail_queue(PDO $pdo, bool $verbose = false): array
{
$r = mail_queue_run($pdo);
set_setting('cron_process_mail_queue_last_run', db_now());
$r['log'] = ['[' . date('Y-m-d H:i:s') . "] Mail-Warteschlange: {$r['sent']} gesendet, {$r['retry']} später erneut, {$r['gave_up']} aufgegeben."];
return $r;
}
if (php_sapi_name() === 'cli') {
foreach (run_process_mail_queue(get_db(), true)['log'] as $line) echo $line . "\n";
}
+3
View File
@@ -29,6 +29,9 @@ function run_plugins_cron(PDO $pdo, bool $verbose = false): array
}
if (php_sapi_name() === 'cli') {
// Der echte Cronjob lebt: immer vermerken, auch wenn der Lauf unten übersprungen wird (bei viel Besuch hat meist schon der eingebaute
// Hintergrund-Betrieb die Minute belegt; sonst stünde in der Plugin-Anzeige dauerhaft „bisher kein Lauf“)
set_setting('cron_run_plugins_last_cli', db_now());
// Läuft zeitgleich der eingebaute Hintergrund-Betrieb, nicht doppelt ausführen (gleiche Sperre wie dort)
if (!function_exists('pseudo_cron_try_claim') || pseudo_cron_try_claim(get_db(), 'cron_run_plugins_last_run', 50)) {
foreach (run_plugins_cron(get_db(), true)['log'] as $line) echo $line . "\n";
+30
View File
@@ -1820,6 +1820,36 @@ function run_migrations(PDO $pdo, bool $verbose = false): array
}
}
// Warteschlange für ausgehende Mails: Fehlgeschlagene Mails werden später erneut versucht
if (!isset($done['php_0064_mail_queue'])) {
try {
$drv = $pdo->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;
}