Skip to content

Commit 050eb9f

Browse files
committed
fix: gestione assenza file modules.json e views.json
1 parent 499e8e0 commit 050eb9f

2 files changed

Lines changed: 82 additions & 28 deletions

File tree

modules/aggiornamenti/edit.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,22 @@ function highlightDifferences($current, $expected) {
203203
$custom_views_not_standard = function_exists('customViewsNotStandard') ? customViewsNotStandard() : [];
204204
$custom_modules_not_standard = function_exists('customModulesNotStandard') ? customModulesNotStandard() : [];
205205

206+
// Verifica se mancano i file di riferimento per viste e moduli
207+
$views_file_missing = !empty($custom_views_not_standard)
208+
&& count($custom_views_not_standard) === 1
209+
&& isset($custom_views_not_standard[0]['reason'])
210+
&& $custom_views_not_standard[0]['reason'] === 'File views.json assente';
211+
212+
$modules_file_missing = !empty($custom_modules_not_standard)
213+
&& count($custom_modules_not_standard) === 1
214+
&& isset($custom_modules_not_standard[0]['reason'])
215+
&& $custom_modules_not_standard[0]['reason'] === 'File modules.json assente';
216+
206217
// Determina se ci sono errori per ogni sezione
207218
$has_file_errors = !empty($custom_files);
208219
$has_table_errors = !empty($tables);
209-
$has_view_errors = !empty($custom_views_not_standard);
210-
$has_module_errors = !empty($custom_modules_not_standard);
220+
$has_view_errors = !empty($custom_views_not_standard) || $views_file_missing;
221+
$has_module_errors = !empty($custom_modules_not_standard) || $modules_file_missing;
211222
$has_field_errors = !empty($custom_fields);
212223
$has_any_errors = !empty($custom) || $has_file_errors || $has_table_errors || $has_view_errors || $has_module_errors || $has_field_errors;
213224

@@ -341,8 +352,9 @@ function highlightDifferences($current, $expected) {
341352
</div>';
342353

343354
// Card Viste
355+
$has_view_data_issues = !empty($custom_views_not_standard) && !$views_file_missing;
344356
$view_icon = $has_view_errors ? 'fa-exclamation-circle' : 'fa-check-circle';
345-
$view_count = $has_view_errors ? count($custom_views_not_standard) : 0;
357+
$view_count = $has_view_data_issues ? count($custom_views_not_standard) : 0;
346358
$view_expand_icon = $has_view_errors ? 'fa-minus' : 'fa-plus';
347359

348360
echo '
@@ -361,7 +373,7 @@ function highlightDifferences($current, $expected) {
361373
</div>
362374
<div class="card-body">';
363375

364-
if ($has_view_errors) {
376+
if ($has_view_data_issues) {
365377
echo '
366378
<div class="table-responsive">
367379
<table class="table table-hover table-striped table-sm">
@@ -441,6 +453,13 @@ function highlightDifferences($current, $expected) {
441453
</tbody>
442454
</table>
443455
</div>';
456+
} elseif ($views_file_missing) {
457+
echo '
458+
<div class="alert alert-warning alert-database">
459+
<i class="fa fa-warning"></i> '.tr('Impossibile effettuare il controllo delle viste in assenza del file _FILE_', [
460+
'_FILE_' => '<b>views.json</b>',
461+
]).'.
462+
</div>';
444463
} else {
445464
echo '
446465
<p class="text-success mb-0">
@@ -453,8 +472,9 @@ function highlightDifferences($current, $expected) {
453472
</div>';
454473

455474
// Card Moduli
475+
$has_module_data_issues = !empty($custom_modules_not_standard) && !$modules_file_missing;
456476
$module_icon = $has_module_errors ? 'fa-exclamation-circle' : 'fa-check-circle';
457-
$module_count = $has_module_errors ? count($custom_modules_not_standard) : 0;
477+
$module_count = $has_module_data_issues ? count($custom_modules_not_standard) : 0;
458478
$module_expand_icon = $has_module_errors ? 'fa-minus' : 'fa-plus';
459479

460480
echo '
@@ -473,7 +493,7 @@ function highlightDifferences($current, $expected) {
473493
</div>
474494
<div class="card-body">';
475495

476-
if ($has_module_errors) {
496+
if ($has_module_data_issues) {
477497
echo '
478498
<div class="table-responsive">
479499
<table class="table table-hover table-striped table-sm">
@@ -546,6 +566,13 @@ function highlightDifferences($current, $expected) {
546566
</tbody>
547567
</table>
548568
</div>';
569+
} elseif ($modules_file_missing) {
570+
echo '
571+
<div class="alert alert-warning alert-database">
572+
<i class="fa fa-warning"></i> '.tr('Impossibile effettuare il controllo dei moduli in assenza del file _FILE_', [
573+
'_FILE_' => '<b>modules.json</b>',
574+
]).'.
575+
</div>';
549576
} else {
550577
echo '
551578
<p class="text-success mb-0">

modules/aggiornamenti/modutil.php

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,29 @@ function customViewsNotStandard()
289289
$standard_views = [];
290290
$views_json_path = base_dir().'/views.json';
291291

292-
if (file_exists($views_json_path)) {
293-
$views_data = json_decode(file_get_contents($views_json_path), true);
294-
295-
if (is_array($views_data)) {
296-
// Il file views.json è organizzato per nome modulo
297-
foreach ($views_data as $module_name => $module_views) {
298-
if (is_array($module_views)) {
299-
foreach ($module_views as $view_name => $view_query) {
300-
$standard_views[$module_name][$view_name] = $view_query;
301-
}
292+
// Se il file non esiste, segnala la mancanza e non marcare tutte le viste come non previste
293+
if (!file_exists($views_json_path)) {
294+
return [
295+
[
296+
'id' => null,
297+
'name' => '',
298+
'module_name' => '',
299+
'module_id' => null,
300+
'reason' => 'File views.json assente',
301+
'current_query' => '',
302+
'expected_query' => '',
303+
],
304+
];
305+
}
306+
307+
$views_data = json_decode(file_get_contents($views_json_path), true);
308+
309+
if (is_array($views_data)) {
310+
// Il file views.json è organizzato per nome modulo
311+
foreach ($views_data as $module_name => $module_views) {
312+
if (is_array($module_views)) {
313+
foreach ($module_views as $view_name => $view_query) {
314+
$standard_views[$module_name][$view_name] = $view_query;
302315
}
303316
}
304317
}
@@ -467,18 +480,32 @@ function customModulesNotStandard()
467480
$standard_modules = [];
468481
$modules_json_path = base_dir().'/modules.json';
469482

470-
if (file_exists($modules_json_path)) {
471-
$modules_data = json_decode(file_get_contents($modules_json_path), true);
472-
473-
if (is_array($modules_data)) {
474-
// Il file modules.json è organizzato per nome modulo
475-
foreach ($modules_data as $module_name => $module_data) {
476-
if (is_array($module_data)) {
477-
$standard_modules[$module_name] = [
478-
'options' => $module_data['options'] ?? '',
479-
'options2' => $module_data['options2'] ?? ''
480-
];
481-
}
483+
// Se il file non esiste, segnala la mancanza e non marcare tutti i moduli come non previsti
484+
if (!file_exists($modules_json_path)) {
485+
return [
486+
[
487+
'id' => null,
488+
'name' => '',
489+
'module_display_name' => '',
490+
'reason' => 'File modules.json assente',
491+
'current_options' => '',
492+
'current_options2' => '',
493+
'expected_options' => '',
494+
'expected_options2' => '',
495+
],
496+
];
497+
}
498+
499+
$modules_data = json_decode(file_get_contents($modules_json_path), true);
500+
501+
if (is_array($modules_data)) {
502+
// Il file modules.json è organizzato per nome modulo
503+
foreach ($modules_data as $module_name => $module_data) {
504+
if (is_array($module_data)) {
505+
$standard_modules[$module_name] = [
506+
'options' => $module_data['options'] ?? '',
507+
'options2' => $module_data['options2'] ?? '',
508+
];
482509
}
483510
}
484511
}

0 commit comments

Comments
 (0)