fix: Auto-dismiss cron notifications for disabled jobs

- Add cleanupDisabledCronNotifications() method
- Automatically mark notifications as read when cronjob is disabled
- Fixes issue where "Cron-Job verpasst" kept reappearing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-03-03 12:09:42 +01:00
parent 197d87c663
commit b4a6f534ba
11 changed files with 65 additions and 3 deletions

8
CHANGELOG.md Normal file → Executable file
View file

@ -2,6 +2,14 @@
Alle wesentlichen Änderungen an diesem Projekt werden in dieser Datei dokumentiert.
## [1.4.0] - 2026-03-03
### Neu
- **Automatisches Entfernen von Cron-Notifications**: Benachrichtigungen für deaktivierte Cronjobs werden automatisch als gelesen markiert und verschwinden aus dem Widget
### Verbessert
- Deaktivieren eines Cronjobs ermöglicht jetzt das Schließen der zugehörigen "Cron-Job verpasst"-Meldung
## [1.3.0] - 2026-02-23
### Neu

0
README.md Normal file → Executable file
View file

0
admin/setup.php Normal file → Executable file
View file

0
ajax/action.php Normal file → Executable file
View file

58
class/actions_globalnotify.class.php Normal file → Executable file
View file

@ -283,6 +283,11 @@ class ActionsGlobalNotify extends CommonHookActions
}
dolibarr_set_const($this->db, 'GLOBALNOTIFY_CRON_LASTCHECK', time(), 'chaine', 0, '', $conf->entity);
$notify = new GlobalNotify($this->db);
// Clean up: Remove notifications for disabled cronjobs
$this->cleanupDisabledCronNotifications($notify);
// Find all stuck cron jobs (processing=1 for more than 30 minutes)
$sql = "SELECT rowid, label, module_name, datelastrun, processing
FROM ".MAIN_DB_PREFIX."cronjob
@ -295,8 +300,6 @@ class ActionsGlobalNotify extends CommonHookActions
return;
}
$notify = new GlobalNotify($this->db);
while ($obj = $this->db->fetch_object($resql)) {
$module = !empty($obj->module_name) ? strtolower($obj->module_name) : 'cron';
$lastRun = $this->db->jdate($obj->datelastrun);
@ -367,6 +370,57 @@ class ActionsGlobalNotify extends CommonHookActions
}
}
/**
* Remove cron notifications for disabled cronjobs
* This ensures users can dismiss notifications by disabling the cronjob
*
* @param GlobalNotify $notify GlobalNotify instance
*/
private function cleanupDisabledCronNotifications($notify)
{
global $conf;
$existing = $notify->getModuleNotifications('cron');
if (empty($existing)) {
return;
}
// Get all disabled cronjobs
$disabledJobs = array();
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."cronjob WHERE status != 1";
$resql = $this->db->query($sql);
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$disabledJobs[$obj->rowid] = $obj->label;
}
}
if (empty($disabledJobs)) {
return;
}
// Mark notifications for disabled jobs as read
$changed = false;
foreach ($existing as &$notif) {
if (!empty($notif['read'])) {
continue;
}
// Check if notification is about a disabled job
foreach ($disabledJobs as $jobId => $jobLabel) {
if (strpos($notif['message'], $jobLabel) !== false || strpos($notif['title'], $jobLabel) !== false) {
$notif['read'] = true;
$changed = true;
break;
}
}
}
if ($changed) {
$key = 'GLOBALNOTIFY_CRON';
dolibarr_set_const($this->db, $key, json_encode($existing), 'chaine', 0, '', $conf->entity);
}
}
/**
* Check BankImport module for issues
*/

0
class/globalnotify.class.php Normal file → Executable file
View file

2
core/modules/modGlobalNotify.class.php Normal file → Executable file
View file

@ -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.3.0';
$this->version = '1.4.0';
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->picto = 'bell';

0
css/globalnotify.css Normal file → Executable file
View file

0
js/globalnotify.js Normal file → Executable file
View file

0
langs/de_DE/globalnotify.lang Normal file → Executable file
View file

0
langs/en_US/globalnotify.lang Normal file → Executable file
View file