From dac2537ac09811d96dc5b01d872b0b0bae994d7a Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 6 Oct 2022 17:08:18 +0200 Subject: [PATCH] Introduzione Hooks disponibili in stato dei servizi --- modules/stato_servizi/actions.php | 49 ++++- modules/stato_servizi/edit.php | 28 ++- modules/stato_servizi/elenco-hooks.php | 195 ++++++++++++++++++ modules/stato_servizi/elenco-widget.php | 2 +- .../widgets/spazio_utilizzato.php | 2 +- src/Util/FileSystem.php | 5 +- 6 files changed, 274 insertions(+), 7 deletions(-) create mode 100644 modules/stato_servizi/elenco-hooks.php diff --git a/modules/stato_servizi/actions.php b/modules/stato_servizi/actions.php index 8259f6153..a2c38b2fd 100755 --- a/modules/stato_servizi/actions.php +++ b/modules/stato_servizi/actions.php @@ -267,6 +267,48 @@ switch (filter('op')) { break; + case 'disabilita-hook': + $id = filter('id'); + + // Abilitazione del widget indicato + $database->table('zz_hooks') + ->where('id', '=', $id) + ->update(['enabled' => 0]); + + // Messaggio informativo + $hook = $database->table('zz_hooks') + ->where('id', '=', $id) + ->first(); + flash()->info(tr('Hook "_NAME_" disabilitato!', [ + '_NAME_' => $hook->name, + ])); + + echo json_encode([]); + + break; + + case 'abilita-hook': + $id = filter('id'); + + // Abilitazione del widget indicato + $database->table('zz_hooks') + ->where('id', '=', $id) + ->update(['enabled' => 1]); + + // Messaggio informativo + $hook = $database->table('zz_hooks') + ->where('id', '=', $id) + ->first(); + flash()->info(tr('Hook "_NAME_" abilitato!', [ + '_NAME_' => $hook->name, + ])); + + echo json_encode([]); + + break; + + + case 'sizes': $results = []; @@ -279,13 +321,16 @@ switch (filter('op')) { ]; foreach ($dirs as $dir => $description) { - $size = FileSystem::folderSize($dir, ['htaccess','gitkeep','ini','xml']); + $excluded_extensions = ['htaccess','gitkeep']; + $excluded_dir = [DOCROOT.'\files\impianti', DOCROOT.'\files\importFE', DOCROOT.'\files\importFE']; + + $size = FileSystem::folderSize($dir, array_merge($excluded_extensions,$excluded_dir)); $results[] = [ 'description' => $description, 'size' => $size, 'formattedSize' => FileSystem::formatBytes($size), - 'count' => FileSystem::fileCount($dir, ['htaccess','gitkeep','ini','xml']) ?: 0, + 'count' => FileSystem::fileCount($dir, array_merge($excluded_extensions,$excluded_dir)) ?: 0, 'dbSize' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT SUM(`size`) AS dbsize FROM zz_files')['dbsize'] : 0, 'dbCount' => ($description == 'Allegati') ? $dbo->fetchOne('SELECT COUNT(`id`) AS dbcount FROM zz_files')['dbcount'] : 0, 'dbExtensions' => ($description == 'Allegati') ? $dbo->fetchArray("SELECT SUBSTRING_INDEX(filename, '.', -1) AS extension, COUNT(*) AS num FROM zz_files GROUP BY extension ORDER BY num DESC LIMIT 10") : 0, diff --git a/modules/stato_servizi/edit.php b/modules/stato_servizi/edit.php index 234efed0f..fa9bd9b47 100755 --- a/modules/stato_servizi/edit.php +++ b/modules/stato_servizi/edit.php @@ -264,7 +264,7 @@ echo ' '; -// Widgets +// Widgets + Hooks echo '
@@ -277,6 +277,18 @@ echo '
+ +
+
+

+ '.tr('Hooks disponibili').' +

+
+ +
+
+
+
@@ -422,9 +434,23 @@ function caricaElencoWidget() { }); } +function caricaElencoHooks() { + let container = $("#hook"); + + localLoading(container, true); + return $.get("'.$structure->fileurl('elenco-hooks.php').'?id_module='.$id_module.'", function(data) { + container.html(data); + localLoading(container, false); + + init(); + }); +} + + $(document).ready(function() { caricaElencoModuli(); caricaElencoWidget(); + caricaElencoHooks(); init(); }); diff --git a/modules/stato_servizi/elenco-hooks.php b/modules/stato_servizi/elenco-hooks.php new file mode 100644 index 000000000..f48cfc079 --- /dev/null +++ b/modules/stato_servizi/elenco-hooks.php @@ -0,0 +1,195 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +echo ' + + + + + + + + '; + +$hooks = $dbo->fetchArray('SELECT zz_hooks.*, zz_modules.name AS modulo +FROM zz_hooks + INNER JOIN zz_modules ON zz_hooks.id_module = zz_modules.id +ORDER BY `id_module` ASC, `zz_hooks`.`id` ASC'); + +$gruppi = collect($hooks)->groupBy('modulo'); +foreach ($gruppi as $modulo => $hooks) { + echo ' + + + + + + + '; + + foreach ($hooks as $hook) { + + $class = $hook['enabled'] ? 'success' : 'warning'; + $nome_tipo = 'hook'; + + echo ' + + + + + + '; + } + + echo ' + '; +} + +echo ' +
'.tr('Nome').''.tr('Stato').''.tr('Ultima esecuzione').'
'.$modulo.'
+ '.$hook['name'].(!empty($hook['help']) ? ' + ' : '').' + '; + + // Possibilità di disabilitare o abilitare il hook + if ($hook['enabled']) { + echo ' +
+ +
'; + } else { + echo ' +
+ +
'; + } + + echo ' +
'; + + Translator::timestampToLocale($hook['processing_at']); + + echo ' +
+ +'; diff --git a/modules/stato_servizi/elenco-widget.php b/modules/stato_servizi/elenco-widget.php index 218c8d1db..8a4b499e3 100644 --- a/modules/stato_servizi/elenco-widget.php +++ b/modules/stato_servizi/elenco-widget.php @@ -24,7 +24,7 @@ echo ' '.tr('Nome').' - '.tr('Posizione').' + '.tr('Ubicazione').' '.tr('Stato').' '.tr('Posizione').' diff --git a/modules/stato_servizi/widgets/spazio_utilizzato.php b/modules/stato_servizi/widgets/spazio_utilizzato.php index f3b26b93c..08a6027e8 100755 --- a/modules/stato_servizi/widgets/spazio_utilizzato.php +++ b/modules/stato_servizi/widgets/spazio_utilizzato.php @@ -72,7 +72,7 @@ function crea_grafico(values){ if (element.count "+diff+" files non trovati sul disco per allegati.
"); + $("#message").append("
"+diff+" files non trovati per allegati.

"); } } diff --git a/src/Util/FileSystem.php b/src/Util/FileSystem.php index 72513dcd2..2eb2f8211 100755 --- a/src/Util/FileSystem.php +++ b/src/Util/FileSystem.php @@ -71,7 +71,7 @@ class FileSystem if ($path !== false && $path != '' && file_exists($path)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { - if (!in_array($object->getExtension(), $exclusions)) { + if (!in_array($object->getExtension(), $exclusions) && (!in_array($object->getPath(), $exclusions)) ) { $total += $object->getSize(); } } @@ -94,7 +94,8 @@ class FileSystem if ($path !== false && $path != '' && file_exists($path)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { - if (!in_array($object->getExtension(), $exclusions)) { + if (!in_array($object->getExtension(), $exclusions) && (!in_array($object->getPath(), $exclusions)) ) { + ++$total; } }