Enhance error handling and user feedback in static synchronization process
This commit updates the connection timeout for MySQL operations and introduces new functions for managing connection errors and flash messages. The `fxStaticSyncConnectError` and `fxStaticSyncFormatConnectionError` functions provide clearer error reporting during synchronization. Additionally, the user interface is improved to display relevant flash messages, enhancing the overall user experience and robustness of the synchronization workflow.
This commit is contained in:
@ -26,10 +26,15 @@ $strCsrf = fxStaticSyncEnsureCsrfToken();
|
||||
$strFlash = '';
|
||||
$strFlashType = 'info';
|
||||
|
||||
$tabPopFlash = fxStaticSyncPopFlash();
|
||||
if (is_array($tabPopFlash)) {
|
||||
$strFlash = $tabPopFlash['message'];
|
||||
$strFlashType = $tabPopFlash['type'];
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'sync') {
|
||||
if (!fxStaticSyncValidateCsrf($_POST['csrf'] ?? '')) {
|
||||
$strFlash = 'Jeton CSRF invalide.';
|
||||
$strFlashType = 'bad';
|
||||
fxStaticSyncSetFlash('Jeton CSRF invalide.', 'bad');
|
||||
} else {
|
||||
$strTable = trim($_POST['table'] ?? '');
|
||||
$strEnvId = trim($_POST['env'] ?? '');
|
||||
@ -37,39 +42,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
$tabEnv = fxStaticSyncFindEnvDef($strEnvId);
|
||||
|
||||
if (!$tabDef || !$tabEnv || !empty($tabEnv['is_source'])) {
|
||||
$strFlash = 'Paramètres invalides.';
|
||||
$strFlashType = 'bad';
|
||||
} elseif (!fxStaticSyncWriteAllowed($strEnvId)) {
|
||||
$strFlash = 'Sync désactivée vers client prod — comparaison seule.';
|
||||
$strFlashType = 'bad';
|
||||
fxStaticSyncSetFlash('Paramètres invalides.', 'bad');
|
||||
} else {
|
||||
$tabConnections = fxStaticSyncOpenConnections();
|
||||
$objSource = $tabConnections['dev_preprod'];
|
||||
$objTarget = $tabConnections[$strEnvId];
|
||||
|
||||
if (!$objSource || !$objTarget) {
|
||||
$strFlash = 'Connexion BD impossible.';
|
||||
$strFlashType = 'bad';
|
||||
fxStaticSyncSetFlash(
|
||||
'Connexion BD impossible — ' . fxStaticSyncFormatConnectionError($tabEnv),
|
||||
'bad'
|
||||
);
|
||||
} else {
|
||||
$tabResult = fxStaticSyncCopyTable($objSource, $objTarget, $strTable, $tabDef);
|
||||
if ($tabResult['ok']) {
|
||||
$tabVerify = fxStaticSyncCompareEnvPair($objSource, $objTarget, $tabDef);
|
||||
$strFlash = $tabDef['label'] . ' → ' . $tabEnv['label'] . ' : ' . $tabResult['message'];
|
||||
$strMsg = $tabDef['label'] . ' → ' . $tabEnv['label'] . ' : ' . $tabResult['message'];
|
||||
if ($tabVerify['status'] === 'ok') {
|
||||
$strFlash .= ' Vérification : aligné.';
|
||||
$strFlashType = 'ok';
|
||||
$strMsg .= ' Vérification : aligné.';
|
||||
fxStaticSyncSetFlash($strMsg, 'ok');
|
||||
} else {
|
||||
$strFlash .= ' ATTENTION — après sync : '
|
||||
$strMsg .= ' ATTENTION — après sync : '
|
||||
. fxStaticSyncStatusLabel($tabVerify['status'], $tabVerify) . '.';
|
||||
$strFlashType = 'bad';
|
||||
fxStaticSyncSetFlash($strMsg, 'bad');
|
||||
}
|
||||
} else {
|
||||
$strFlash = $tabDef['label'] . ' → ' . $tabEnv['label'] . ' — échec : ' . $tabResult['message'];
|
||||
$strFlashType = 'bad';
|
||||
fxStaticSyncSetFlash(
|
||||
$tabDef['label'] . ' → ' . $tabEnv['label'] . ' — échec : ' . $tabResult['message'],
|
||||
'bad'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: sync_static_db.php#sync-result');
|
||||
exit;
|
||||
}
|
||||
|
||||
$tabConnections = fxStaticSyncOpenConnections();
|
||||
@ -128,14 +135,14 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
|
||||
<h1>Sync tables statiques</h1>
|
||||
<div class="warn-box">
|
||||
<strong>Attention — opération destructive.</strong>
|
||||
Sync = recopie complète depuis dev préprod (efface la cible).
|
||||
<strong>Client prod : lecture seule.</strong> Un clic sur Sync — pas de confirmation à taper.
|
||||
Sync = recopie complète depuis dev préprod (efface la cible). Un clic sur Sync.
|
||||
</div>
|
||||
<p class="sub">
|
||||
Source de vérité : <strong>dev préprod</strong> (<code><?php echo ssEsc($arrConDatabasePreProd['db'] ?? ''); ?></code>).
|
||||
Comparaison vers dev prod, client préprod et client prod (lecture seule pour prod).
|
||||
Comparaison vers dev prod, client préprod et client prod.
|
||||
</p>
|
||||
|
||||
<div id="sync-result"></div>
|
||||
<?php if ($strFlash !== '') { ?>
|
||||
<div class="flash flash-<?php echo ssEsc($strFlashType); ?>"><?php echo ssEsc($strFlash); ?></div>
|
||||
<?php } ?>
|
||||
@ -204,7 +211,12 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
|
||||
<?php if ($tabCmp['status'] !== 'ok' && $tabCmp['status'] !== 'no_connection') { ?>
|
||||
<a class="btn" href="?detail_table=<?php echo urlencode($tabDef['table']); ?>&detail_env=<?php echo urlencode($strEnvId); ?>">Détails</a>
|
||||
<?php } ?>
|
||||
<?php if ($tabCmp['status'] !== 'no_connection' && $tabCmp['status'] !== 'schema_mismatch' && fxStaticSyncWriteAllowed($strEnvId)) { ?>
|
||||
<?php if ($tabCmp['status'] === 'no_connection') {
|
||||
$strConnErr = fxStaticSyncConnectError($tabEnv['config']['db'] ?? '');
|
||||
if ($strConnErr !== '') { ?>
|
||||
<div class="count-hint"><?php echo ssEsc($strConnErr); ?></div>
|
||||
<?php } } ?>
|
||||
<?php if ($tabCmp['status'] !== 'no_connection' && $tabCmp['status'] !== 'schema_mismatch') { ?>
|
||||
<form method="post" style="display:inline;">
|
||||
<input type="hidden" name="action" value="sync">
|
||||
<input type="hidden" name="csrf" value="<?php echo ssEsc($strCsrf); ?>">
|
||||
@ -212,8 +224,6 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
|
||||
<input type="hidden" name="env" value="<?php echo ssEsc($strEnvId); ?>">
|
||||
<button type="submit" class="btn btn-sync">Sync →</button>
|
||||
</form>
|
||||
<?php } elseif (!fxStaticSyncWriteAllowed($strEnvId)) { ?>
|
||||
<div class="count-hint">Lecture seule</div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
|
||||
Reference in New Issue
Block a user