Skip to content

Commit 5dab6c4

Browse files
committed
fix: svuota cache hooks
1 parent e483561 commit 5dab6c4

3 files changed

Lines changed: 77 additions & 44 deletions

File tree

modules/stato_servizi/actions.php

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,70 @@
293293
break;
294294

295295
case 'svuota-cache-hooks':
296-
// Svuota cache hooks
297-
$database->table('zz_cache')
298-
->update(['expire_at' => Carbon::now()->subMinutes(1)]);
296+
try {
297+
// 1. Sblocca tutti gli hooks che potrebbero essere bloccati
298+
$unlocked_hooks = $database->table('zz_hooks')
299+
->update([
300+
'processing_at' => null,
301+
'processing_token' => null
302+
]);
303+
304+
// 2. Invalida tutte le cache degli hooks impostando la scadenza nel passato
305+
$cache_affected = $database->table('zz_cache')
306+
->update(['expire_at' => Carbon::now()->subMinutes(1)]);
307+
308+
// 3. Svuota il contenuto delle cache specifiche degli hooks
309+
$hook_caches = [
310+
'Informazioni su Services',
311+
'Spazio utilizzato',
312+
'Ultima versione di OpenSTAManager disponibile',
313+
'Ricevute Elettroniche',
314+
'Ultima esecuzione del cron'
315+
];
299316

300-
// Messaggio informativo
301-
flash()->info(tr('Cache hooks svuotata!', []));
317+
$content_cleared = 0;
318+
foreach ($hook_caches as $cache_name) {
319+
$cache = Cache::where('name', $cache_name)->first();
320+
if ($cache) {
321+
$cache->content = null;
322+
$cache->expire_at = Carbon::now()->subMinutes(1);
323+
$cache->save();
324+
$content_cleared++;
325+
}
326+
}
302327

303-
echo json_encode([]);
328+
// 4. Rimuovi fisicamente le cache scadute (solo quelle temporanee)
329+
$deleted_rows = $database->table('zz_cache')
330+
->where('expire_at', '<', Carbon::now())
331+
->whereNull('valid_time')
332+
->delete();
333+
334+
// Messaggio informativo
335+
flash()->info(tr('Cache hooks svuotata con successo! Hooks sbloccati: _HOOKS_, Cache invalidate: _CACHE_, Contenuti svuotati: _CONTENT_', [
336+
'_HOOKS_' => $unlocked_hooks,
337+
'_CACHE_' => $cache_affected,
338+
'_CONTENT_' => $content_cleared
339+
]));
340+
341+
$result = [
342+
'success' => true,
343+
'unlocked_hooks' => $unlocked_hooks,
344+
'cache_affected' => $cache_affected,
345+
'content_cleared' => $content_cleared,
346+
'deleted_rows' => $deleted_rows
347+
];
348+
} catch (\Exception $e) {
349+
flash()->error(tr('Errore durante lo svuotamento della cache: _ERROR_', [
350+
'_ERROR_' => $e->getMessage()
351+
]));
352+
353+
$result = [
354+
'success' => false,
355+
'error' => $e->getMessage()
356+
];
357+
}
358+
359+
echo json_encode($result);
304360
break;
305361

306362
case 'disabilita-hook':

modules/stato_servizi/edit.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,7 @@
320320
</div>
321321
</div>
322322
323-
<div class="card card-info card-outline mb-4">
324-
<div class="card-header">
325-
<div class="card-title">
326-
<i class="fa fa-history mr-2"></i>'.tr('Ultime operazioni').'
327-
</div>
328-
</div>
329323
330-
<div class="card-body p-0" id="operazioni">
331-
</div>
332-
</div>
333324
334325
</div>
335326
</div>
@@ -499,39 +490,13 @@ function caricaElencoSessioni() {
499490
});
500491
}
501492
502-
function caricaElencoOperazioni() {
503-
let container = $("#operazioni");
504-
505-
localLoading(container, true);
506-
return $.get("'.$structure->fileurl('elenco-operazioni.php').'?id_module='.$id_module.'", function(data) {
507-
container.html(data);
508-
localLoading(container, false);
509-
510-
init();
511-
});
512-
}
513-
514-
function caricaAltreOperazioni(offset, limit) {
515-
let container = $("#operazioni");
516-
517-
// Mostra loading
518-
localLoading(container, true);
519-
520-
$.get("'.$structure->fileurl('elenco-operazioni.php').'?id_module='.$id_module.'&offset=" + offset + "&limit=" + limit, function(data) {
521-
// Sostituisci completamente il contenuto del container
522-
container.html(data);
523-
localLoading(container, false);
524493
525-
init();
526-
});
527-
}
528494
529495
$(document).ready(function() {
530496
caricaElencoModuli();
531497
caricaElencoWidget();
532498
caricaElencoHooks();
533499
caricaElencoSessioni();
534-
caricaElencoOperazioni();
535500
536501
init();
537502
});

modules/stato_servizi/elenco-hooks.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
}
100100

101101
echo '<tr><td colspan="3" class="text-right p-3"><button type="button" class="btn btn-sm btn-danger" onclick="svuotaCacheHooks(this)">
102-
<i class="fa fa-trash mr-1" title="'.tr('Svuota cache degli hooks').'"></i>'.tr('Svuota cache').'</button>
102+
<i class="fa fa-refresh mr-1" title="'.tr('Svuota cache e sblocca hooks').'"></i>'.tr('Svuota cache e sblocca hooks').'</button>
103103
</td></tr>';
104104

105105
echo '
@@ -112,8 +112,8 @@
112112
113113
function svuotaCacheHooks(button){
114114
swal({
115-
title: "'.tr('Svuota la cache degli hooks', []).'",
116-
html: "'.tr('Sei sicuro di voler svuotare la cache degli hooks?', []).'",
115+
title: "'.tr('Svuota cache e sblocca hooks', []).'",
116+
html: "'.tr('Questa operazione svuoterà la cache di tutti gli hooks e li sbloccherà. Sei sicuro di voler continuare?', []).'",
117117
type: "warning",
118118
showCancelButton: true,
119119
confirmButtonText: "'.tr('Continua').'"
@@ -130,6 +130,18 @@ function svuotaCacheHooks(button){
130130
},
131131
success: function (response) {
132132
buttonRestore(button, restore);
133+
134+
if (response.success) {
135+
// Ricarica la pagina per mostrare i cambiamenti
136+
caricaElencoHooks();
137+
} else {
138+
swal({
139+
type: "error",
140+
title: "'.tr('Errore').'",
141+
text: response.error || "'.tr('Errore durante lo svuotamento della cache').'",
142+
});
143+
}
144+
133145
renderMessages();
134146
},
135147
error: function() {

0 commit comments

Comments
 (0)