From 197d87c6632ed6cd56450862eca00242931dbae8 Mon Sep 17 00:00:00 2001 From: data Date: Mon, 23 Feb 2026 11:22:29 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Konfigurierbares=20Cron-Pr=C3=BCfinterv?= =?UTF-8?q?all=20und=20Dokumentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Admin-Seite mit Einstellung für Cron-Prüfintervall (10-3600 Sek) - checkStuckCronJobs() nutzt jetzt konfigurierbare Einstellung - README.md mit vollständiger Integrations-Dokumentation - Sichere Nutzung ohne Fatal Error wenn Modul nicht installiert - Version 1.3.0 Co-Authored-By: Claude Opus 4.5 --- CHANGELOG.md | 8 + README.md | 333 +++++++++++++++++++++++++ admin/setup.php | 41 +++ class/actions_globalnotify.class.php | 10 +- core/modules/modGlobalNotify.class.php | 2 +- 5 files changed, 391 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 471db11..7e95de1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ Alle wesentlichen Änderungen an diesem Projekt werden in dieser Datei dokumentiert. +## [1.3.0] - 2026-02-23 + +### Neu +- **Konfigurierbares Prüfintervall**: Im Admin-Center kann eingestellt werden, wie oft auf hängende Cron-Jobs geprüft wird (10-3600 Sekunden) + +### Verbessert +- Admin-Seite mit Einstellungs-Formular erweitert + ## [1.2.0] - 2026-02-23 ### Neu diff --git a/README.md b/README.md new file mode 100644 index 0000000..042a188 --- /dev/null +++ b/README.md @@ -0,0 +1,333 @@ +# GlobalNotify - Dolibarr Benachrichtigungsmodul + +Ein zentrales Benachrichtigungssystem für Dolibarr, das Meldungen von allen Modulen sammelt und in einem schwebenden Widget anzeigt. + +## Features + +- **Schwebendes Widget**: Messenger-artiges Panel, immer sichtbar (unten links) +- **Verschiebbar**: FAB-Button kann frei positioniert werden (Position wird gespeichert) +- **Benachrichtigungston**: Akustisches Signal bei neuen Nachrichten +- **Shake-Animation**: Visuelle Aufmerksamkeit bei neuen Benachrichtigungen +- **Farbkodierung**: + - Grau: Keine Benachrichtigungen + - Rot: Benachrichtigungen vorhanden + - Pulsierend rot: Dringende Benachrichtigungen (Fehler/Aktionen) +- **Historie**: Gelesene Benachrichtigungen bleiben in der Historie verfügbar +- **Cron-Überwachung**: Automatische Erkennung hängender Cron-Jobs + +## Installation + +1. Modul nach `/custom/globalnotify/` kopieren +2. In Dolibarr unter Einstellungen → Module → GlobalNotify aktivieren +3. Konfiguration unter Einstellungen → Module → GlobalNotify → Setup + +## Einstellungen + +- **Cron-Prüfintervall**: Wie oft auf hängende Cron-Jobs geprüft wird (10-3600 Sekunden) + +--- + +## Integration in andere Module + +### Grundprinzip + +GlobalNotify bietet eine einfache API zum Erstellen von Benachrichtigungen. **Wichtig**: Module sollten immer prüfen, ob GlobalNotify verfügbar ist, bevor sie es verwenden. + +### Sichere Integration (empfohlen) + +```php +getMessage(), LOG_WARNING); + return false; + } +} +``` + +### Direkte Nutzung der Klasse + +```php +addNotification( + 'mymodule', // Modul-Name + GlobalNotify::TYPE_ERROR, // Typ + 'Import fehlgeschlagen', // Titel + 'Die Datei konnte nicht gelesen werden: file.pdf', // Nachricht + dol_buildpath('/mymodule/list.php', 1), // Aktions-URL + 'Details anzeigen', // Aktions-Label + 10, // Priorität (1-10) + 0 // User-ID (0 = alle Admins) + ); +} +``` + +### Statische Helper-Methoden + +```php + 0) { + $this->notifyAdmin( + 'warning', + 'Import mit Warnungen', + "{$errorCount} Dateien konnten nicht importiert werden" + ); + } + + } catch (Exception $e) { + $this->notifyAdmin( + 'error', + 'Cron-Job fehlgeschlagen', + $e->getMessage(), + dol_buildpath('/mymodule/admin/setup.php', 1), + 'Einstellungen prüfen' + ); + return -1; + } + + return 0; + } + + private function notifyAdmin($type, $title, $message, $url = '', $label = '') + { + if (!isModEnabled('globalnotify')) { + // Fallback: Nur ins Log schreiben + dol_syslog("MyModule: {$title} - {$message}", LOG_WARNING); + return; + } + + dol_include_once('/globalnotify/class/globalnotify.class.php'); + + if (class_exists('GlobalNotify')) { + switch ($type) { + case 'error': + GlobalNotify::error('mymodule', $title, $message, $url, $label); + break; + case 'warning': + GlobalNotify::warning('mymodule', $title, $message, $url, $label); + break; + default: + GlobalNotify::info('mymodule', $title, $message, $url, $label); + } + } + } +} +``` + +### Benachrichtigungen verwalten + +```php +getAllNotifications($user->id, true); + +// Gelesene Benachrichtigungen (Historie) +$history = $notify->getReadNotifications($user->id, 20); + +// Als gelesen markieren +$notify->markAsRead($notificationId); + +// Alle als gelesen markieren +$notify->markAllAsRead(); + +// Nur für ein bestimmtes Modul +$notify->markAllAsRead('mymodule'); + +// Benachrichtigung löschen +$notify->deleteNotification($notificationId); + +// Alle Benachrichtigungen eines Moduls löschen +$notify->clearModuleNotifications('mymodule'); + +// Ungelesene Anzahl für Badge +$count = $notify->getUnreadCount(); +``` + +--- + +## Best Practices + +### 1. Immer Verfügbarkeit prüfen + +```php +// RICHTIG +if (isModEnabled('globalnotify') && class_exists('GlobalNotify')) { + GlobalNotify::error('mymodule', 'Fehler', 'Details'); +} + +// FALSCH - kann zu Fatal Error führen +GlobalNotify::error('mymodule', 'Fehler', 'Details'); +``` + +### 2. Nicht zu viele Benachrichtigungen + +GlobalNotify speichert maximal 50 Benachrichtigungen pro Modul. Vermeiden Sie: +- Benachrichtigungen in Schleifen +- Benachrichtigungen für jeden einzelnen Datensatz +- Wiederholte identische Benachrichtigungen + +### 3. Aussagekräftige Informationen + +```php +// RICHTIG +GlobalNotify::error( + 'bankimport', + 'Bank-Login fehlgeschlagen', + 'Sparkasse Musterstadt: Falsches Passwort (3. Versuch)', + dol_buildpath('/bankimport/admin/setup.php', 1), + 'Zugangsdaten prüfen' +); + +// FALSCH +GlobalNotify::error('bankimport', 'Fehler', 'Es ist ein Fehler aufgetreten'); +``` + +### 4. Sinnvolle Aktions-URLs + +Wenn eine Benachrichtigung eine Aktion erfordert, fügen Sie immer eine URL hinzu: + +```php +GlobalNotify::actionRequired( + 'importzugferd', + 'Lieferant nicht gefunden', + 'Rechnung von "Neue Firma GmbH" konnte nicht zugeordnet werden', + dol_buildpath('/importzugferd/pending.php?id=123', 1), + 'Rechnung prüfen' +); +``` + +--- + +## Technische Details + +### Speicherung + +Benachrichtigungen werden in `llx_const` als JSON gespeichert: +- Key: `GLOBALNOTIFY_` (z.B. `GLOBALNOTIFY_BANKIMPORT`) +- Value: JSON-Array mit Benachrichtigungen + +### Caching + +- Cron-Prüfung: Konfigurierbar (Standard: 60 Sekunden) +- Client-Refresh: Alle 2 Minuten via AJAX + +### Hooks + +Das Modul nutzt folgende Hooks: +- `printTopRightMenu` - Widget-Anzeige +- `addMoreActionsButtons` - Modul-Status-Checks + +--- + +## Changelog + +Siehe [CHANGELOG.md](CHANGELOG.md) + +## Lizenz + +GPL v3 - siehe [LICENSE](LICENSE) + +## Autor + +Eduard Wisch - Data IT Solution +https://data-it-solution.de diff --git a/admin/setup.php b/admin/setup.php index 92e7063..23c72f1 100644 --- a/admin/setup.php +++ b/admin/setup.php @@ -56,6 +56,20 @@ $action = GETPOST('action', 'aZ09'); * Actions */ +if ($action == 'update') { + $cronCheckInterval = GETPOST('GLOBALNOTIFY_CRON_CHECK_INTERVAL', 'int'); + if ($cronCheckInterval < 10) { + $cronCheckInterval = 10; // Minimum 10 seconds + } + if ($cronCheckInterval > 3600) { + $cronCheckInterval = 3600; // Maximum 1 hour + } + dolibarr_set_const($db, 'GLOBALNOTIFY_CRON_CHECK_INTERVAL', $cronCheckInterval, 'chaine', 0, '', $conf->entity); + setEventMessages("Einstellungen gespeichert", null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]); + exit; +} + if ($action == 'clearall') { // Clear all notifications $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name LIKE 'GLOBALNOTIFY_%'"; @@ -84,6 +98,33 @@ llxHeader('', $page_name); print load_fiche_titre($page_name, '', 'title_setup'); +// Settings Form +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; + +// Cron check interval +$cronCheckInterval = getDolGlobalInt('GLOBALNOTIFY_CRON_CHECK_INTERVAL', 60); +print ''; +print ''; +print ''; +print ''; + +print '
Einstellungen
'; +print '
Wie oft soll auf hängende Cron-Jobs geprüft werden? (10-3600 Sekunden)
Sekunden
'; + +print '
'; +print ''; +print '
'; +print '
'; + +print '
'; + // Get all notifications $notify = new GlobalNotify($db); $allNotifications = $notify->getAllNotifications(0, false); // All, including read diff --git a/class/actions_globalnotify.class.php b/class/actions_globalnotify.class.php index eb9658e..a7901b9 100644 --- a/class/actions_globalnotify.class.php +++ b/class/actions_globalnotify.class.php @@ -270,9 +270,15 @@ class ActionsGlobalNotify extends CommonHookActions { global $conf; - // Only check once per minute (cache) + // Get configurable check interval (default 60 seconds) + $checkInterval = getDolGlobalInt('GLOBALNOTIFY_CRON_CHECK_INTERVAL', 60); + if ($checkInterval < 10) { + $checkInterval = 10; + } + + // Only check based on configured interval (cache) $lastCheck = getDolGlobalInt('GLOBALNOTIFY_CRON_LASTCHECK'); - if ($lastCheck > (time() - 60)) { + if ($lastCheck > (time() - $checkInterval)) { return; } dolibarr_set_const($this->db, 'GLOBALNOTIFY_CRON_LASTCHECK', time(), 'chaine', 0, '', $conf->entity); diff --git a/core/modules/modGlobalNotify.class.php b/core/modules/modGlobalNotify.class.php index f45f1ee..9aed673 100644 --- a/core/modules/modGlobalNotify.class.php +++ b/core/modules/modGlobalNotify.class.php @@ -42,7 +42,7 @@ class modGlobalNotify extends DolibarrModules $this->descriptionlong = "Provides a unified notification bell in the top bar that collects and displays alerts from any module (cron errors, warnings, action required, etc.)"; $this->editor_name = 'Data IT Solution'; $this->editor_url = 'https://data-it-solution.de'; - $this->version = '1.2.0'; + $this->version = '1.3.0'; $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); $this->picto = 'bell';