From 5f65e1a33941d12deb27610b29d30bc5634e44f2 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 6 Jul 2026 15:17:04 -0400 Subject: [PATCH] Refactor data synchronization functions for improved clarity and status reporting This commit renames and refines several functions related to data synchronization, enhancing the clarity of status reporting. The `fxStaticSyncResolveDataStatus` function is replaced with `fxStaticSyncFinalizeCompareResult`, which consolidates status determination logic. Additionally, user feedback is improved in the synchronization process, with clearer messages regarding data discrepancies and alignment. These changes aim to streamline the synchronization workflow and enhance overall user experience. --- php/inc_fx_static_sync.php | 108 ++++++++++++++++--------------------- php/sync_static_db.php | 24 ++++++--- 2 files changed, 62 insertions(+), 70 deletions(-) diff --git a/php/inc_fx_static_sync.php b/php/inc_fx_static_sync.php index 356566f..be6f367 100644 --- a/php/inc_fx_static_sync.php +++ b/php/inc_fx_static_sync.php @@ -254,45 +254,31 @@ 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'; +function fxStaticSyncFinalizeCompareResult(array $tabCmp) { + if (in_array($tabCmp['status'], array('missing_table', 'schema_mismatch', 'no_connection'), true)) { + return $tabCmp; } - return 'content_diff'; -} + $intMissingKeys = count($tabCmp['missing_keys']); + $intExtraKeys = count($tabCmp['extra_keys']); + $intDiffKeys = count($tabCmp['diff_keys']); -/** 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; + if ($intMissingKeys === 0 && $intExtraKeys === 0 && $intDiffKeys === 0) { + $tabCmp['status'] = 'ok'; + return $tabCmp; } - return implode(' · ', $tabParts); + $intDelta = (int)$tabCmp['target_count'] - (int)$tabCmp['source_count']; + + if ($intDelta < 0) { + $tabCmp['status'] = 'missing_rows'; + } elseif ($intDelta > 0) { + $tabCmp['status'] = 'extra_rows'; + } else { + $tabCmp['status'] = 'content_diff'; + } + + return $tabCmp; } /** @@ -333,14 +319,8 @@ function fxStaticSyncCompareTable(array $tabSourceData, array $tabTargetData, ar } } - $strStatus = fxStaticSyncResolveDataStatus(array( - 'missing_keys' => $tabMissing, - 'extra_keys' => $tabExtra, - 'diff_keys' => $tabDiff, - )); - - return array( - 'status' => $strStatus, + return fxStaticSyncFinalizeCompareResult(array( + 'status' => 'pending', 'source_count' => $tabSourceData['count'], 'target_count' => $tabTargetData['count'], 'missing_keys' => $tabMissing, @@ -348,7 +328,7 @@ function fxStaticSyncCompareTable(array $tabSourceData, array $tabTargetData, ar 'diff_keys' => $tabDiff, 'schema_missing_cols' => isset($tabSchemaInfo['missing_in_target']) ? $tabSchemaInfo['missing_in_target'] : array(), 'schema_extra_cols' => isset($tabSchemaInfo['extra_in_target']) ? $tabSchemaInfo['extra_in_target'] : array(), - ); + )); } function fxStaticSyncDbLastError($objDb) { @@ -558,31 +538,36 @@ function fxStaticSyncCopyTable($objSource, $objTarget, $strTable, array $tabDef } 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 '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 'ok': + return 'Données alignées'; case 'missing_table': return 'Table absente'; case 'schema_mismatch': return 'Structures non alignées'; case 'no_connection': return 'Connexion impossible'; + } + + if (is_array($tabCmp)) { + $intDelta = (int)$tabCmp['target_count'] - (int)$tabCmp['source_count']; + if ($intDelta < 0) { + return 'Il en manque ' . abs($intDelta); + } + if ($intDelta > 0) { + return 'Il y en a ' . $intDelta . ' en trop'; + } + + return 'Contenu différent'; + } + + switch ($strStatus) { + case 'content_diff': + return 'Contenu différent'; + case 'missing_rows': + return 'Il en manque'; + case 'extra_rows': + return 'Il y en a en trop'; default: return 'Erreur'; } @@ -594,7 +579,6 @@ 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 f1f1662..7379c33 100644 --- a/php/sync_static_db.php +++ b/php/sync_static_db.php @@ -157,14 +157,12 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
Données alignées - Écarts (manque / en trop / contenu) + Il en manque X + Il y en a X en trop + Contenu différent Structures non alignées Table absente / connexion
-

- 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. -

@@ -250,9 +248,19 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {

Détails —

- Manquantes : — - Différences : — - En trop : + 0) { + echo 'Il y en a ' . $intDelta . ' en trop (cible ' . (int)$tabCmp['target_count'] + . ' · source ' . (int)$tabCmp['source_count'] . ')'; + } else { + echo 'Même nombre de lignes, contenu différent (cible ' . (int)$tabCmp['target_count'] + . ' · source ' . (int)$tabCmp['source_count'] . ')'; + } + ?> isset($tabCmp['schema_missing_cols']) ? $tabCmp['schema_missing_cols'] : array(),