|
293 | 293 | break; |
294 | 294 |
|
295 | 295 | 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 | + ]; |
299 | 316 |
|
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 | + } |
302 | 327 |
|
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); |
304 | 360 | break; |
305 | 361 |
|
306 | 362 | case 'disabilita-hook': |
|
0 commit comments