diff --git a/php/inc_fx_static_sync.php b/php/inc_fx_static_sync.php index 9beaccc..356566f 100644 --- a/php/inc_fx_static_sync.php +++ b/php/inc_fx_static_sync.php @@ -249,6 +249,52 @@ function fxStaticSyncWriteAllowed($strEnvId) { return $strEnvId !== 'client_prod'; } +/** Environnements client : confirmation renforcée (nom de BD à retaper). */ +function fxStaticSyncRequiresDbConfirm($strEnvId) { + return ($strEnvId === 'client_preprod' || $strEnvId === 'client_prod'); +} + +function fxStaticSyncResolveDataStatus(array $tabCmp) { + $intMissing = count($tabCmp['missing_keys']); + $intExtra = count($tabCmp['extra_keys']); + $intDiff = count($tabCmp['diff_keys']); + + if ($intMissing === 0 && $intExtra === 0 && $intDiff === 0) { + return 'ok'; + } + if ($intMissing > 0 && $intExtra > 0) { + return 'mixed'; + } + if ($intExtra > 0) { + return 'extra_rows'; + } + if ($intMissing > 0) { + return 'missing_rows'; + } + + return 'content_diff'; +} + +/** Résumé lisible des écarts de données (toujours affiché quand status !== ok). */ +function fxStaticSyncFormatDataDiffSummary(array $tabCmp) { + $tabParts = array(); + $intMissing = count($tabCmp['missing_keys']); + $intExtra = count($tabCmp['extra_keys']); + $intDiff = count($tabCmp['diff_keys']); + + if ($intMissing > 0) { + $tabParts[] = 'manque ' . $intMissing; + } + if ($intExtra > 0) { + $tabParts[] = 'en trop ' . $intExtra; + } + if ($intDiff > 0) { + $tabParts[] = 'contenu diff. ' . $intDiff; + } + + return implode(' · ', $tabParts); +} + /** * @return array status: ok|content_diff|missing_rows|extra_rows|missing_table|schema_mismatch|no_connection|error */ @@ -287,14 +333,11 @@ function fxStaticSyncCompareTable(array $tabSourceData, array $tabTargetData, ar } } - $strStatus = 'ok'; - if (count($tabExtra) > 0) { - $strStatus = 'extra_rows'; - } elseif (count($tabMissing) > 0) { - $strStatus = 'missing_rows'; - } elseif (count($tabDiff) > 0) { - $strStatus = 'content_diff'; - } + $strStatus = fxStaticSyncResolveDataStatus(array( + 'missing_keys' => $tabMissing, + 'extra_keys' => $tabExtra, + 'diff_keys' => $tabDiff, + )); return array( 'status' => $strStatus, @@ -514,16 +557,26 @@ function fxStaticSyncCopyTable($objSource, $objTarget, $strTable, array $tabDef ); } -function fxStaticSyncStatusLabel($strStatus) { +function fxStaticSyncStatusLabel($strStatus, array $tabCmp = null) { + if ($strStatus === 'ok') { + return 'Données alignées'; + } + if (is_array($tabCmp) && $strStatus !== 'schema_mismatch' && $strStatus !== 'missing_table' && $strStatus !== 'no_connection') { + $strSummary = fxStaticSyncFormatDataDiffSummary($tabCmp); + if ($strSummary !== '') { + return 'Écarts : ' . $strSummary; + } + } + switch ($strStatus) { - case 'ok': - return 'Données alignées'; case 'content_diff': return 'Contenu différent'; case 'missing_rows': return 'Lignes manquantes'; case 'extra_rows': return 'Lignes en trop'; + case 'mixed': + return 'Manque et en trop'; case 'missing_table': return 'Table absente'; case 'schema_mismatch': @@ -541,6 +594,7 @@ function fxStaticSyncStatusClass($strStatus) { return 'ss-ok'; case 'content_diff': case 'missing_rows': + case 'mixed': return 'ss-warn'; case 'extra_rows': return 'ss-bad'; diff --git a/php/sync_static_db.php b/php/sync_static_db.php index 75174ce..f1f1662 100644 --- a/php/sync_static_db.php +++ b/php/sync_static_db.php @@ -42,7 +42,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } elseif (!fxStaticSyncWriteAllowed($strEnvId)) { $strFlash = 'Sync désactivée vers client prod — comparaison seule.'; $strFlashType = 'bad'; + } elseif (fxStaticSyncRequiresDbConfirm($strEnvId)) { + $strConfirmDb = trim($_POST['confirm_db'] ?? ''); + $strExpectedDb = $tabEnv['config']['db'] ?? ''; + if ($strConfirmDb !== $strExpectedDb) { + $strFlash = 'Sync annulée — nom de base incorrect (attendu : ' . $strExpectedDb . ').'; + $strFlashType = 'bad'; + } else { + $blnDbConfirmed = true; + } } else { + $blnDbConfirmed = true; + } + + if (!empty($blnDbConfirmed)) { $tabConnections = fxStaticSyncOpenConnections(); $objSource = $tabConnections['dev_preprod']; $objTarget = $tabConnections[$strEnvId]; @@ -59,8 +72,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $strFlash .= ' Vérification : aligné.'; $strFlashType = 'ok'; } else { - $strFlash .= ' ATTENTION — après sync, statut : ' - . fxStaticSyncStatusLabel($tabVerify['status']) . '.'; + $strFlash .= ' ATTENTION — après sync : ' + . fxStaticSyncStatusLabel($tabVerify['status'], $tabVerify) . '.'; $strFlashType = 'bad'; } } else { @@ -108,8 +121,9 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') { .ss-bad { background: #f8d7da; color: #721c24; } .ss-muted { background: #e9ecef; color: #495057; } .ss-schema { background: #fde2e2; color: #7f1d1d; border: 1px solid #f5c2c2; } - .badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 0.82rem; font-weight: 600; } + .badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 0.82rem; font-weight: 600; max-width: 100%; line-height: 1.35; } .count { font-size: 0.82rem; color: #444; margin-top: 4px; } + .count-hint { font-size: 0.78rem; color: #666; } .btn { display: inline-block; margin-top: 6px; padding: 4px 10px; font-size: 0.82rem; border: 1px solid #888; background: #fff; border-radius: 4px; cursor: pointer; text-decoration: none; color: #222; } .btn:hover { background: #f0f0f0; } .btn-sync { border-color: #2e6da4; color: #1a4f7a; } @@ -128,8 +142,9 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
DELETE puis recopie complète depuis dev préprod.
- Ne pas utiliser vers client prod (bouton désactivé).
- Si le statut indique Structures non alignées, aligner les structures via Navicat — aucune sync possible tant que ce n'est pas réglé.
+ Client prod : lecture seule (aucun bouton Sync).
+ Client préprod : confirmation avec le nom exact de la base.
+ Structures non alignées : corriger via Navicat avant toute sync.
Source de vérité : dev préprod ().
@@ -142,11 +157,14 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
+ Compteur : cible · source (lignes dans l'environnement comparé · lignes en dev préprod). + Les écarts détaillent combien de clés manquent, sont en trop ou diffèrent — indépendamment du total. +
|
- / ligne(s)
+ Cible · Source
&detail_env=">Détails
-
+
+ Lecture seule
|
@@ -243,7 +269,10 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {