Skip to content

Commit 0ba91d3

Browse files
committed
fix: avviso cron non configurato
1 parent 7f2b8ff commit 0ba91d3

2 files changed

Lines changed: 62 additions & 16 deletions

File tree

include/init/requirements.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,47 @@
412412
];
413413
}
414414

415+
// Controllo stato cron
416+
$cron_check = [];
417+
if ($database->isInstalled()) {
418+
try {
419+
$ultima_esecuzione = $database->fetchOne('SELECT content FROM zz_cache WHERE name = "Ultima esecuzione del cron"');
420+
421+
if (!$ultima_esecuzione || !$ultima_esecuzione['content']) {
422+
$cron_status = 0;
423+
$cron_description = tr('Il cron non è stato configurato correttamente. Sembra che il cron di OpenSTAManager non sia in esecuzione.<br><br>È necessario configurare il cron di sistema in modo che esegua periodicamente il file cron.php di OpenSTAManager con il seguente comando:<br><br><code>php _DOCUMENT_ROOT_/cron.php</code><br><br>La frequenza suggerita è di 10 minuti, ma può essere adattata alle tue esigenze. Se invii molte newsletter, per esempio, è consigliato inserire 1 minuto come frequenza.', [
424+
'_DOCUMENT_ROOT_' => $_SERVER['DOCUMENT_ROOT'] ?? base_dir(),
425+
]);
426+
} else {
427+
$data_ultima_esecuzione = new DateTime($ultima_esecuzione['content']);
428+
$ora_attuale = new DateTime();
429+
$ore_trascorse = $ora_attuale->diff($data_ultima_esecuzione)->h + $ora_attuale->diff($data_ultima_esecuzione)->days * 24;
430+
431+
if ($ore_trascorse > 1) {
432+
$cron_status = 0;
433+
$data_formattata = $data_ultima_esecuzione->format('d/m/Y H:i:s');
434+
$cron_description = tr('Sembra che il cron di OpenSTAManager non sia in esecuzione (ultima esecuzione il _DATA_).<br><br>È necessario configurare il cron di sistema in modo che esegua periodicamente il file cron.php di OpenSTAManager con il seguente comando:<br><br><code>php _DOCUMENT_ROOT_/cron.php</code><br><br>La frequenza suggerita è di 10 minuti, ma può essere adattata alle tue esigenze. Se invii molte newsletter, per esempio, è consigliato inserire 1 minuto come frequenza.', [
435+
'_DATA_' => $data_formattata,
436+
'_DOCUMENT_ROOT_' => $_SERVER['DOCUMENT_ROOT'] ?? base_dir(),
437+
]);
438+
} else {
439+
$cron_status = 1;
440+
$cron_description = tr('Il cron è stato eseguito di recente');
441+
}
442+
}
443+
} catch (Exception $e) {
444+
$cron_status = 0;
445+
$cron_description = tr('Errore nel controllo dello stato del cron');
446+
}
447+
448+
$cron_check[] = [
449+
'name' => 'cron_status',
450+
'description' => $cron_description,
451+
'status' => $cron_status,
452+
'type' => tr('Servizio'),
453+
];
454+
}
455+
415456
$requirements = [
416457
tr('Apache (_INTERFACE_)', [
417458
'_INTERFACE_' => $php_interface,
@@ -428,6 +469,11 @@
428469
tr('Configurazioni') => $config,
429470
];
430471

472+
// Aggiunta controllo cron se disponibile
473+
if (!empty($cron_check)) {
474+
$requirements[tr('Servizi di sistema')] = $cron_check;
475+
}
476+
431477
if (!$database->isInstalled() || empty($mysql)) {
432478
unset($requirements[tr('DBMS (_TYPE_)', [
433479
'_TYPE_' => $database->getType(),

modules/stato_servizi/src/CronStatusHook.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Carbon\Carbon;
2323
use Hooks\Manager;
2424
use Models\Cache;
25+
use Models\Module;
2526

2627
/**
2728
* Hook specializzato per il controllo dello stato del cron.
@@ -35,7 +36,10 @@ public function response()
3536
$ultima_esecuzione = Cache::where('name', 'Ultima esecuzione del cron')->first();
3637

3738
if (!$ultima_esecuzione || !$ultima_esecuzione->content) {
38-
$message = tr('Il cron non è stato configurato correttamente');
39+
$document_root = $_SERVER['DOCUMENT_ROOT'] ?? base_dir();
40+
$message = tr('Il cron di OpenSTAManager non è stato configurato.<br><br>È necessario configurare il cron di sistema per eseguire periodicamente il file cron.php con il seguente comando:<br><br><code>php _DOCUMENT_ROOT_/cron.php</code><br><br>Frequenza consigliata: ogni 10 minuti (adattabile in base alle esigenze).', [
41+
'_DOCUMENT_ROOT_' => $document_root,
42+
]);
3943
$show = true;
4044
} else {
4145
// Converte la data dell'ultima esecuzione
@@ -46,33 +50,29 @@ public function response()
4650
$ore_trascorse = $data_ultima_esecuzione->diffInHours($ora_attuale);
4751

4852
if ($ore_trascorse > 1) {
49-
$giorni = floor($ore_trascorse / 24);
50-
$ore_rimanenti = $ore_trascorse % 24;
53+
$data_formattata = $data_ultima_esecuzione->format('d/m/Y H:i:s');
54+
$document_root = $_SERVER['DOCUMENT_ROOT'] ?? base_dir();
5155

52-
if ($giorni > 0) {
53-
$tempo_trascorso = $giorni . ' ' . ($giorni == 1 ? tr('giorno') : tr('giorni'));
54-
if ($ore_rimanenti > 0) {
55-
$tempo_trascorso .= ' e ' . $ore_rimanenti . ' ' . ($ore_rimanenti == 1 ? tr('ora') : tr('ore'));
56-
}
57-
} else {
58-
$tempo_trascorso = $ore_trascorse . ' ' . ($ore_trascorse == 1 ? tr('ora') : tr('ore'));
59-
}
60-
61-
$message = tr('Attenzione: il cron non viene eseguito da _TIME_', [
62-
'_TIME_' => $tempo_trascorso,
56+
$message = tr('Il cron di OpenSTAManager non è in esecuzione (ultima esecuzione: _DATA_).<br><br>Verificare la configurazione del cron di sistema. Il comando da eseguire è:<br><br><code>php _DOCUMENT_ROOT_/cron.php</code><br><br>Frequenza consigliata: ogni 10 minuti. Per invii frequenti di newsletter, impostare 1 minuto.', [
57+
'_DATA_' => $data_formattata,
58+
'_DOCUMENT_ROOT_' => $document_root,
6359
]);
6460
$show = true;
6561
} else {
66-
$message = tr('Il cron è stato eseguito di recente');
62+
$message = tr('Il cron è attivo e funzionante');
6763
$show = false;
6864
}
6965
}
7066

67+
// Ottiene il link al modulo aggiornamenti
68+
$aggiornamenti_module = Module::where('name', 'Aggiornamenti')->first();
69+
$link = $aggiornamenti_module ? base_path().'/controller.php?id_module=' . $aggiornamenti_module->id : base_path().'/controller.php?id_module=' . $this->getModuleId();
70+
7171
return [
7272
'icon' => 'fa fa-clock-o text-danger',
7373
'message' => $message,
7474
'show' => $show,
75-
'link' => base_path().'/controller.php?id_module=' . $this->getModuleId(),
75+
'link' => $link,
7676
];
7777
}
7878

0 commit comments

Comments
 (0)