fix: controlli database

This commit is contained in:
valentina 2024-11-05 16:54:48 +01:00
parent 467ebaea56
commit 1c74007dc4
1 changed files with 125 additions and 122 deletions

View File

@ -77,7 +77,6 @@ $effettua_controllo = filter('effettua_controllo');
if (empty($effettua_controllo)) {
echo '
<div id="righe_controlli">
</div>
<div class="alert alert-info" id="card-loading">
@ -143,25 +142,26 @@ $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)) {
if (!empty($results)) {
if ($results) {
echo '
<p>'.tr("Segue l'elenco delle tabelle del database che presentano una struttura diversa rispetto a quella prevista nella versione ufficiale del gestionale").'.</p>
<div class="alert alert-warning">
<i class="fa fa-warning"></i>
'.tr('Attenzione: questa funzionalità può presentare dei risultati falsamente positivi, sulla base del contenuto del file _FILE_ e la versione di _MYSQL_VERSION_ di _DBMS_TYPE_ rilevata a sistema', [
<p>'.tr("Segue l'elenco delle tabelle del database che presentano una struttura diversa rispetto a quella prevista nella versione ufficiale del gestionale").'.</p>
<div class="alert alert-warning">
<i class="fa fa-warning"></i>
'.tr('Attenzione: questa funzionalità può presentare dei risultati falsamente positivi, sulla base del contenuto del file _FILE_ e la versione di _MYSQL_VERSION_ di _DBMS_TYPE_ rilevata a sistema', [
'_FILE_' => '<b>'.$file_to_check_database.'</b>',
'_MYSQL_VERSION_' => '<b>'.$database->getMySQLVersion().'</b>',
'_DBMS_TYPE_' => '<b>'.$database->getType().'</b>',
]).'.
</div>';
</div>';
foreach ($results as $table => $errors) {
echo '
<h3>'.$table.'</h3>';
<h3>'.$table.'</h3>';
if (array_key_exists('current', $errors) && $errors['current'] == null) {
echo '
<div class="alert alert-danger" ><i class="fa fa-times"></i> '.tr('Tabella assente').'</div>';
<div class="alert alert-danger" ><i class="fa fa-times"></i> '.tr('Tabella assente').'
</div>';
continue;
}
@ -170,15 +170,15 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
if (!empty($errors)) {
echo '
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<tbody>';
<tbody>';
foreach ($errors as $name => $diff) {
$query = '';
$null = '';
@ -202,62 +202,63 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
}
echo '
<tr class="bg-warning" >
<td>
'.$name.'
</td>
<td>
'.$query.';
</td>
</tr>';
<tr class="bg-warning" >
<td>
'.$name.'
</td>
<td>
'.$query.';
</td>
</tr>';
}
echo '
</tbody>
</table>';
</tbody>
</table>';
}
if (!empty($foreign_keys)) {
echo '
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<tbody>';
<tbody>';
foreach ($foreign_keys as $name => $diff) {
echo '
<tr class="bg-warning" >
<td>
'.($name ?: $diff['expected']['title']).'
</td>
<td>
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'].';
</td>
</tr>';
<tr class="bg-warning" >
<td>
'.($name ?: $diff['expected']['title']).'
</td>
<td>
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'].';
</td>
</tr>';
}
echo '
</tbody>
</table>';
</tbody>
</table>';
}
}
}
if (!empty($results_added)) {
if ($results_added) {
foreach ($results_added as $table => $errors) {
if ($results[$table] && array_keys($results[$table]) != array_keys($errors)) {
if (($results[$table] && array_keys($results[$table]) != array_keys($errors)) || (empty($results[$table]) && !empty($errors))) {
echo '
<h3>'.$table.'</h3>';
<h3>'.$table.'</h3>';
if (array_key_exists('current', $errors) && $errors['current'] == null) {
echo '
<div class="alert alert-danger" ><i class="fa fa-times"></i> '.tr('Tabella assente').'</div>';
<div class="alert alert-danger" ><i class="fa fa-times"></i> '.tr('Tabella assente').'
</div>';
continue;
}
@ -266,15 +267,15 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
if (!empty($errors)) {
echo '
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<tbody>';
<tbody>';
foreach ($errors as $name => $diff) {
$query = '';
@ -290,64 +291,65 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
}
echo '
<tr class="bg-info" >
<td>
'.$name.'
</td>
<td>
'.$query.'
</td>
</tr>';
<tr class="bg-info" >
<td>
'.$name.'
</td>
<td>
'.$query.'
</td>
</tr>';
}
}
echo '
</tbody>
</table>';
</tbody>
</table>';
}
if (!empty($foreign_keys)) {
echo '
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<table class="table table-bordered">
<thead>
<tr>
<th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th>
</tr>
</thead>
<tbody>';
<tbody>';
foreach ($foreign_keys as $name => $diff) {
echo '
<tr class="bg-info" >
<td>
'.$name.'
</td>
<td>
Chiave esterna non prevista
</td>
</tr>';
<tr class="bg-info" >
<td>
'.$name.'
</td>
<td>
Chiave esterna non prevista
</td>
</tr>';
}
echo '
</tbody>
</table>';
</tbody>
</table>';
}
}
}
}
if (!empty($results_settings)) {
if ($results_settings) {
echo '
<table class="table table-bordered">
<thead>
<h3>Problemi impostazioni</h3>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th>
<th>'.tr('Valore atteso').'</th>
</tr>
</thead>
<thead>
<h3>Problemi impostazioni</h3>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th>
<th>'.tr('Valore atteso').'</th>
</tr>
</thead>
<tbody>';
foreach ($results_settings as $key => $setting) {
if (!$setting['current']) {
@ -356,44 +358,45 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
$class = 'warning';
}
echo '
<tr class="bg-'.$class.'" >
<td>
'.$key.'
</td>
<td>
'.($setting['current'] ?: '⚠️ Impostazione mancante').'
</td>
<td>
'.$setting['expected'].'
</td>
</tr>';
<tr class="bg-'.$class.'" >
<td>
'.$key.'
</td>
<td>
'.($setting['current'] ?: '⚠️ Impostazione mancante').'
</td>
<td>
'.$setting['expected'].'
</td>
</tr>';
}
echo '
</tbody>
</table>';
}
if (!empty($results_settings_added)) {
if ($results_settings_added) {
echo '
<table class="table table-bordered">
<thead>
<h3>Impostazioni non previste</h3>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th>
</tr>
</thead>
<thead>
<h3>Impostazioni non previste</h3>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th>
</tr>
</thead>
<tbody>';
foreach ($results_settings_added as $key => $setting) {
if ($setting['current'] == null) {
echo '
<tr class="bg-info" >
<td>
'.$key.'
</td>
<td>
'.$setting['expected'].'
</td>
</tr>';
<tr class="bg-info" >
<td>
'.$key.'
</td>
<td>
'.$setting['expected'].'
</td>
</tr>';
}
}
echo '
@ -403,6 +406,6 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
} else {
echo '
<div class="alert alert-info">
<i class="fa fa-info-circle"></i> '.tr('Il database non presenta problemi di integrità').'.
<i class="fa fa-info-circle"></i> '.tr('Il database non presenta problemi di integrità').'.
</div>';
}