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.
This commit is contained in:
2026-07-06 15:17:04 -04:00
parent 709044efef
commit 5f65e1a339
2 changed files with 62 additions and 70 deletions

View File

@ -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';

View File

@ -157,14 +157,12 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
<div class="legend">
<span class="ss-ok">Données alignées</span>
<span class="ss-warn">Écarts (manque / en trop / contenu)</span>
<span class="ss-warn">Il en manque X</span>
<span class="ss-bad">Il y en a X en trop</span>
<span class="ss-warn">Contenu différent</span>
<span class="ss-schema">Structures non alignées</span>
<span class="ss-muted">Table absente / connexion</span>
</div>
<p class="count-hint" style="margin:-8px 0 16px;">
Compteur : <strong>cible · source</strong> (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.
</p>
<table>
<thead>
@ -250,9 +248,19 @@ if ($strDetailTable !== '' && $strDetailEnv !== '') {
<div class="detail-box">
<h2>Détails — <?php echo ssEsc($tabDef['label'] ?? $strDetailTable); ?> → <?php echo ssEsc($tabEnv['label'] ?? $strDetailEnv); ?></h2>
<p>
Manquantes : <?php echo count($tabCmp['missing_keys']); ?> —
Différences : <?php echo count($tabCmp['diff_keys']); ?> —
En trop : <?php echo count($tabCmp['extra_keys']); ?>
<?php
$intDelta = (int)$tabCmp['target_count'] - (int)$tabCmp['source_count'];
if ($intDelta < 0) {
echo 'Il en manque ' . abs($intDelta) . ' (cible ' . (int)$tabCmp['target_count']
. ' · source ' . (int)$tabCmp['source_count'] . ')';
} elseif ($intDelta > 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'] . ')';
}
?>
<?php if ($tabCmp['status'] === 'schema_mismatch') {
$tabSchemaDiff = array(
'missing_in_target' => isset($tabCmp['schema_missing_cols']) ? $tabCmp['schema_missing_cols'] : array(),