Skip to content

Commit 19483b4

Browse files
committed
feat: gestita l'assenza dei file di configurazione (modules.json, views.json, mysql.json)
visualizzando lo stato di warning nelle relative card della schermata aggiornamenti
1 parent 2713ca8 commit 19483b4

2 files changed

Lines changed: 24 additions & 28 deletions

File tree

modules/aggiornamenti/database.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ function settings_diff($expected, $current)
130130
break;
131131
}
132132

133-
$contents = file_get_contents(base_dir().'/'.$file_to_check_database);
134-
$data = json_decode($contents, true);
133+
if (file_exists(base_dir().'/'.$file_to_check_database)) {
134+
$contents = file_get_contents(base_dir().'/'.$file_to_check_database);
135+
$data = json_decode($contents, true);
136+
} else {
137+
$data = [];
138+
}
135139

136140
if (empty($data)) {
137141
echo '

modules/aggiornamenti/edit.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,26 @@ function highlightDifferences($current, $expected) {
240240
$custom_modules_not_standard = function_exists('customModulesNotStandard') ? customModulesNotStandard() : [];
241241

242242
// Verifica se mancano i file di riferimento per viste e moduli
243-
$views_file_missing = !empty($custom_views_not_standard)
244-
&& count($custom_views_not_standard) === 1
245-
&& isset($custom_views_not_standard[0]['reason'])
246-
&& $custom_views_not_standard[0]['reason'] === 'File views.json assente';
247-
248-
$modules_file_missing = !empty($custom_modules_not_standard)
249-
&& count($custom_modules_not_standard) === 1
250-
&& isset($custom_modules_not_standard[0]['reason'])
251-
&& $custom_modules_not_standard[0]['reason'] === 'File modules.json assente';
243+
$views_file_missing = !file_exists(base_dir().'/views.json');
244+
$modules_file_missing = !file_exists(base_dir().'/modules.json');
245+
246+
// Verifica se manca il file di riferimento per il database
247+
$file_to_check_database = 'mysql.json';
248+
if ($database->getType() === 'MariaDB') {
249+
$file_to_check_database = 'mariadb_10_x.json';
250+
} elseif ($database->getType() === 'MySQL') {
251+
$mysql_min_version = '8.0.0';
252+
$mysql_max_version = '8.3.99';
253+
$file_to_check_database = ((version_compare($database->getMySQLVersion(), $mysql_min_version, '>=') && version_compare($database->getMySQLVersion(), $mysql_max_version, '<=')) ? 'mysql.json' : 'mysql_8_3.json');
254+
}
255+
$database_file_missing = !file_exists(base_dir().'/'.$file_to_check_database);
252256

253257
// Determina se ci sono errori per ogni sezione
254258
$has_file_errors = !empty($custom_files) || !empty($checksum_errors);
255259
$has_table_errors = !empty($tables);
256260
$has_view_errors = !empty($custom_views_not_standard) || $views_file_missing;
257261
$has_module_errors = !empty($custom_modules_not_standard) || $modules_file_missing;
258-
$has_field_errors = !empty($custom_fields);
262+
$has_field_errors = !empty($custom_fields) || $database_file_missing;
259263
$has_any_errors = !empty($custom) || $has_file_errors || $has_table_errors || $has_view_errors || $has_module_errors || $has_field_errors;
260264

261265
$customizations_card_class = $has_any_errors ? 'card-warning' : 'card-success';
@@ -424,7 +428,7 @@ function highlightDifferences($current, $expected) {
424428
// Determina il colore della card in base all'avviso più grave
425429
$view_card_color = 'success';
426430
$view_icon = 'fa-check-circle';
427-
if ($view_warning_count > 0) {
431+
if ($view_warning_count > 0 || $views_file_missing) {
428432
$view_card_color = 'warning';
429433
$view_icon = 'fa-exclamation-circle';
430434
} elseif ($view_dark_count > 0) {
@@ -563,7 +567,7 @@ function highlightDifferences($current, $expected) {
563567
// Determina il colore della card in base all'avviso più grave
564568
$module_card_color = 'success';
565569
$module_icon = 'fa-check-circle';
566-
if ($module_warning_count > 0) {
570+
if ($module_warning_count > 0 || $modules_file_missing) {
567571
$module_card_color = 'warning';
568572
$module_icon = 'fa-exclamation-circle';
569573
} elseif ($module_info_count > 0) {
@@ -681,16 +685,7 @@ function highlightDifferences($current, $expected) {
681685
$database_info_count = 0;
682686

683687
try {
684-
$file_to_check_database = 'mysql.json';
685-
if ($database->getType() === 'MariaDB') {
686-
$file_to_check_database = 'mariadb_10_x.json';
687-
} elseif ($database->getType() === 'MySQL') {
688-
$mysql_min_version = '8.0.0';
689-
$mysql_max_version = '8.3.99';
690-
$file_to_check_database = ((version_compare($database->getMySQLVersion(), $mysql_min_version, '>=') && version_compare($database->getMySQLVersion(), $mysql_max_version, '<=')) ? 'mysql.json' : 'mysql_8_3.json');
691-
}
692-
693-
if (file_exists(base_dir().'/'.$file_to_check_database)) {
688+
if (!$database_file_missing) {
694689
$contents = file_get_contents(base_dir().'/'.$file_to_check_database);
695690
$data = json_decode($contents, true);
696691

@@ -791,14 +786,11 @@ function highlightDifferences($current, $expected) {
791786
// Silenzio gli errori
792787
}
793788

794-
$database_card_color = $database_has_errors ? 'warning' : 'success';
795-
$database_icon = $database_has_errors ? 'fa-exclamation-circle' : 'fa-check-circle';
796-
797789
// Determina il colore in base all'avviso più grave
798790
if ($database_danger_count > 0) {
799791
$database_card_color = 'danger';
800792
$database_icon = 'fa-exclamation-circle';
801-
} elseif ($database_warning_count > 0) {
793+
} elseif ($database_warning_count > 0 || $database_file_missing) {
802794
$database_card_color = 'warning';
803795
$database_icon = 'fa-exclamation-circle';
804796
} elseif ($database_info_count > 0) {

0 commit comments

Comments
 (0)