From 1705744809b0440774cdf3bdef1cf9217e856b4c Mon Sep 17 00:00:00 2001 From: Eduard Wisch Date: Thu, 9 Apr 2026 08:58:39 +0200 Subject: [PATCH] fix: Cronjob entfernt, Cleanup opportunistisch beim Token-Create MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Dolibarr-Cron-Scheduler ist auf Prod nicht aktiv, deshalb hing der tägliche Cleanup-Job 'Expired Upload-Tokens bereinigen' auf 'Geplant' und GlobalNotify meldete ihn als hängenden Job. Lösung: Cronjob komplett aus dem Modul entfernt. Das Cleanup läuft jetzt opportunistisch bei jedem neuen Token-Insert: BerichtUploadToken::create() führt vor dem INSERT ein DELETE FROM llx_bericht_upload_token WHERE expires_at < NOW() aus. Das ist minimal teurer (1 Query extra pro Token-Create, ~0ms bei leerer Tabelle), aber vollständig cron-unabhängig. WICHTIG für Prod: Nach Deploy muss der bestehende Cron-Eintrag manuell aus llx_cronjob gelöscht werden (oder das Modul einmal deaktiviert + reaktiviert werden, dann wird er mit remove() bzw. init() neu gesetzt — ohne Eintrag). GlobalNotify ist danach ruhig. Co-Authored-By: Claude Opus 4.6 (1M context) [deploy] --- class/upload_token.class.php | 5 +++++ core/modules/modBericht.class.php | 20 +++----------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/class/upload_token.class.php b/class/upload_token.class.php index 57bffba..8bb2c2e 100644 --- a/class/upload_token.class.php +++ b/class/upload_token.class.php @@ -25,10 +25,15 @@ class BerichtUploadToken /** * Erstellt einen neuen Token für einen Bericht. + * Räumt dabei abgelaufene Tokens gleich mit auf (kein Cronjob nötig). * @return string|false Hex-Token bei Erfolg */ public function create($fk_bericht, $fk_user, $lifetime = null, $max_uploads = null) { + // Opportunistisches Cleanup: entferne abgelaufene Tokens bei jedem Insert + $this->db->query("DELETE FROM ".$this->db->prefix()."bericht_upload_token" + ." WHERE expires_at < '".$this->db->idate(dol_now())."'", 1); + $this->token = bin2hex(random_bytes(32)); $this->fk_bericht = (int) $fk_bericht; $this->fk_user_creat = (int) $fk_user; diff --git a/core/modules/modBericht.class.php b/core/modules/modBericht.class.php index 8f88cfc..76f398a 100644 --- a/core/modules/modBericht.class.php +++ b/core/modules/modBericht.class.php @@ -89,23 +89,9 @@ class modBericht extends DolibarrModules $this->dictionaries = array(); $this->boxes = array(); - // Cleanup expired Mobile-Upload-Tokens (täglich um 03:30) - $this->cronjobs = array( - 0 => array( - 'label' => 'Bericht: Expired Upload-Tokens bereinigen', - 'jobtype' => 'method', - 'class' => '/bericht/class/upload_token.class.php', - 'objectname' => 'BerichtUploadToken', - 'method' => 'cleanupExpired', - 'parameters' => '', - 'comment' => 'Löscht abgelaufene Mobile-Upload-Tokens aus llx_bericht_upload_token', - 'frequency' => 1, - 'unitfrequency' => 86400, - 'status' => 1, - 'test' => 'isModEnabled("bericht")', - 'priority' => 50, - ), - ); + // Kein Cronjob — Cleanup expired Upload-Tokens passiert on-demand + // beim Anlegen eines neuen Tokens (siehe BerichtUploadToken::create()). + $this->cronjobs = array(); // Rechte — wie Stundenzettel: [4]=perms, [5]=subperms (leer) $this->rights = array();