diff --git a/modules/aggiornamenti/database.php b/modules/aggiornamenti/database.php index 74c13e3c9..2d1219008 100644 --- a/modules/aggiornamenti/database.php +++ b/modules/aggiornamenti/database.php @@ -133,12 +133,13 @@ $info = Update::getDatabaseStructure(); $results = integrity_diff($data, $info); $results_added = integrity_diff($info, $data); + $contents = file_get_contents(base_dir().'/settings.json'); -$data = json_decode($contents, true); +$data_settings = json_decode($contents, true); $settings = Update::getSettings(); -$results_settings = settings_diff($data, $settings); -$results_settings_added = settings_diff($settings, $data); +$results_settings = settings_diff($data_settings, $settings); +$results_settings_added = settings_diff($settings, $data_settings); // Schermata di visualizzazione degli errori if (!empty($results) || !empty($results_added) || !empty($results_settings) || !empty($results_settings_added)) { @@ -178,19 +179,37 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || ! '; - foreach ($errors as $name => $diff) { + $query = ''; + $null = ''; + if (array_key_exists('key', $diff)) { + if ($diff['key']['expected'] == '') { + $query = 'Chiave non prevista'; + } else { + $query = 'Chiave mancante'; + } + } else { + $query .= 'ALTER TABLE `'.$table.'` CHANGE `'.$name.'` `'.$name.'` '.$data[$table][$name]['type']; + if ($data[$table][$name]['null'] == 'NO') { + $null = 'NOT NULL'; + } else { + $null = 'NULL'; + } + $query .= str_replace('DEFAULT_GENERATED', ' ', $data[$table][$name]['extra']).' '.$null.' DEFAULT '.$data[$table][$name]['default'].';'; + } + echo ' '.$name.' - '.json_encode($diff).' + '.$query.' '; + } - + echo ' '; @@ -215,7 +234,6 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || ! '.($name ?: $diff['expected']['title']).' - QUERY DA ESEGUIRE:
ALTER TABLE '.$table.' ADD CONSTRAINT '.$name.' FOREIGN KEY ('.$diff['expected']['column'].') REFERENCES '.$diff['expected']['referenced_table'].'(`'.$diff['expected']['referenced_column'].'`) ON DELETE '.$diff['expected']['delete_rule'].' ON UPDATE '.$diff['expected']['update_rule'].'; '; @@ -230,74 +248,88 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || ! if (!empty($results_added)) { foreach ($results_added as $table => $errors) { + if ($results[$table] && array_keys($results[$table]) != array_keys($errors)) { + echo ' +

'.$table.'

'; + + if (array_key_exists('current', $errors) && $errors['current'] == null) { + echo ' +
'.tr('Tabella assente').'
'; + continue; + } + + $foreign_keys = $errors['foreign_keys'] ?: []; + unset($errors['foreign_keys']); + + if (!empty($errors)) { + echo ' + + + + + + + + + '; + + foreach ($errors as $name => $diff) { + $query = ''; + if ((!isset($results[$table][$name]))) { + if (isset($diff['key'])) { + if ($diff['key']['expected'] == '') { + $query = 'Chiave non prevista'; + } else { + $query = 'Chiave mancante'; + } + } else { + $query = 'Campo non previsto'; + } + + echo ' + + + + '; + } + } echo ' -

'.$table.'

'; - - if (array_key_exists('current', $errors) && $errors['current'] == null) { - echo ' -
'.tr('Tabella assente').'
'; - continue; - } - - $foreign_keys = $errors['foreign_keys'] ?: []; - unset($errors['foreign_keys']); - - if (!empty($errors)) { - echo ' -
'.tr('Colonna').''.tr('Conflitto').'
+ '.$name.' + + '.$query.' +
- - - - - - - - '; - - foreach ($errors as $name => $diff) { - echo ' - - - - '; + +
'.tr('Colonna').''.tr('Conflitto').'
- '.$name.' - - Campo non previsto -
'; } - echo ' - - '; - } - - if (!empty($foreign_keys)) { - echo ' - - - - - - - - - '; - - foreach ($foreign_keys as $name => $diff) { + if (!empty($foreign_keys)) { echo ' - - - - '; - } +
'.tr('Foreign keys').''.tr('Conflitto').'
- '.$name.' - - Chiave esterna non prevista -
+ + + + + + - echo ' - -
'.tr('Foreign keys').''.tr('Conflitto').'
'; + '; + + foreach ($foreign_keys as $name => $diff) { + echo ' + + + '.$name.' + + + Chiave esterna non prevista + + '; + } + + echo ' + + '; + } } } }