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)) { if (empty($effettua_controllo)) {
echo ' echo '
<div id="righe_controlli"> <div id="righe_controlli">
</div> </div>
<div class="alert alert-info" id="card-loading"> <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 // Schermata di visualizzazione degli errori
if (!empty($results) || !empty($results_added) || !empty($results_settings) || !empty($results_settings_added)) { if (!empty($results) || !empty($results_added) || !empty($results_settings) || !empty($results_settings_added)) {
if (!empty($results)) { if ($results) {
echo ' 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> <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"> <div class="alert alert-warning">
<i class="fa fa-warning"></i> <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', [ '.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>', '_FILE_' => '<b>'.$file_to_check_database.'</b>',
'_MYSQL_VERSION_' => '<b>'.$database->getMySQLVersion().'</b>', '_MYSQL_VERSION_' => '<b>'.$database->getMySQLVersion().'</b>',
'_DBMS_TYPE_' => '<b>'.$database->getType().'</b>', '_DBMS_TYPE_' => '<b>'.$database->getType().'</b>',
]).'. ]).'.
</div>'; </div>';
foreach ($results as $table => $errors) { foreach ($results as $table => $errors) {
echo ' echo '
<h3>'.$table.'</h3>'; <h3>'.$table.'</h3>';
if (array_key_exists('current', $errors) && $errors['current'] == null) { if (array_key_exists('current', $errors) && $errors['current'] == null) {
echo ' 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; continue;
} }
@ -170,15 +170,15 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
if (!empty($errors)) { if (!empty($errors)) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>'.tr('Colonna').'</th> <th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th> <th>'.tr('Conflitto').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($errors as $name => $diff) { foreach ($errors as $name => $diff) {
$query = ''; $query = '';
$null = ''; $null = '';
@ -202,62 +202,63 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
} }
echo ' echo '
<tr class="bg-warning" > <tr class="bg-warning" >
<td> <td>
'.$name.' '.$name.'
</td> </td>
<td> <td>
'.$query.'; '.$query.';
</td> </td>
</tr>'; </tr>';
} }
echo ' echo '
</tbody> </tbody>
</table>'; </table>';
} }
if (!empty($foreign_keys)) { if (!empty($foreign_keys)) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>'.tr('Foreign keys').'</th> <th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th> <th>'.tr('Conflitto').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($foreign_keys as $name => $diff) { foreach ($foreign_keys as $name => $diff) {
echo ' echo '
<tr class="bg-warning" > <tr class="bg-warning" >
<td> <td>
'.($name ?: $diff['expected']['title']).' '.($name ?: $diff['expected']['title']).'
</td> </td>
<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'].'; 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> </td>
</tr>'; </tr>';
} }
echo ' echo '
</tbody> </tbody>
</table>'; </table>';
} }
} }
} }
if (!empty($results_added)) { if ($results_added) {
foreach ($results_added as $table => $errors) { 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 ' echo '
<h3>'.$table.'</h3>'; <h3>'.$table.'</h3>';
if (array_key_exists('current', $errors) && $errors['current'] == null) { if (array_key_exists('current', $errors) && $errors['current'] == null) {
echo ' 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; continue;
} }
@ -266,15 +267,15 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
if (!empty($errors)) { if (!empty($errors)) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>'.tr('Colonna').'</th> <th>'.tr('Colonna').'</th>
<th>'.tr('Conflitto').'</th> <th>'.tr('Conflitto').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($errors as $name => $diff) { foreach ($errors as $name => $diff) {
$query = ''; $query = '';
@ -290,64 +291,65 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
} }
echo ' echo '
<tr class="bg-info" > <tr class="bg-info" >
<td> <td>
'.$name.' '.$name.'
</td> </td>
<td> <td>
'.$query.' '.$query.'
</td> </td>
</tr>'; </tr>';
} }
} }
echo ' echo '
</tbody> </tbody>
</table>'; </table>';
} }
if (!empty($foreign_keys)) { if (!empty($foreign_keys)) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th>'.tr('Foreign keys').'</th> <th>'.tr('Foreign keys').'</th>
<th>'.tr('Conflitto').'</th> <th>'.tr('Conflitto').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($foreign_keys as $name => $diff) { foreach ($foreign_keys as $name => $diff) {
echo ' echo '
<tr class="bg-info" > <tr class="bg-info" >
<td> <td>
'.$name.' '.$name.'
</td> </td>
<td> <td>
Chiave esterna non prevista Chiave esterna non prevista
</td> </td>
</tr>'; </tr>';
} }
echo ' echo '
</tbody> </tbody>
</table>'; </table>';
} }
} }
} }
} }
if (!empty($results_settings)) { if ($results_settings) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<h3>Problemi impostazioni</h3> <h3>Problemi impostazioni</h3>
<tr> <tr>
<th>'.tr('Nome').'</th> <th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th> <th>'.tr('Valore attuale').'</th>
<th>'.tr('Valore atteso').'</th> <th>'.tr('Valore atteso').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($results_settings as $key => $setting) { foreach ($results_settings as $key => $setting) {
if (!$setting['current']) { if (!$setting['current']) {
@ -356,44 +358,45 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
$class = 'warning'; $class = 'warning';
} }
echo ' echo '
<tr class="bg-'.$class.'" > <tr class="bg-'.$class.'" >
<td> <td>
'.$key.' '.$key.'
</td> </td>
<td> <td>
'.($setting['current'] ?: '⚠️ Impostazione mancante').' '.($setting['current'] ?: '⚠️ Impostazione mancante').'
</td> </td>
<td> <td>
'.$setting['expected'].' '.$setting['expected'].'
</td> </td>
</tr>'; </tr>';
} }
echo ' echo '
</tbody> </tbody>
</table>'; </table>';
} }
if (!empty($results_settings_added)) {
if ($results_settings_added) {
echo ' echo '
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<h3>Impostazioni non previste</h3> <h3>Impostazioni non previste</h3>
<tr> <tr>
<th>'.tr('Nome').'</th> <th>'.tr('Nome').'</th>
<th>'.tr('Valore attuale').'</th> <th>'.tr('Valore attuale').'</th>
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($results_settings_added as $key => $setting) { foreach ($results_settings_added as $key => $setting) {
if ($setting['current'] == null) { if ($setting['current'] == null) {
echo ' echo '
<tr class="bg-info" > <tr class="bg-info" >
<td> <td>
'.$key.' '.$key.'
</td> </td>
<td> <td>
'.$setting['expected'].' '.$setting['expected'].'
</td> </td>
</tr>'; </tr>';
} }
} }
echo ' echo '
@ -403,6 +406,6 @@ if (!empty($results) || !empty($results_added) || !empty($results_settings) || !
} else { } else {
echo ' echo '
<div class="alert alert-info"> <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>'; </div>';
} }