Add enhanced data synchronization functions and improve user feedback
This commit introduces new functions for confirming database names during synchronization, enhancing safety when syncing to production environments. The `fxStaticSyncResolveDataStatus` and `fxStaticSyncFormatDataDiffSummary` functions are added to provide clearer status reporting and summaries of data discrepancies. Additionally, the synchronization process is refined to improve user feedback, including clearer messages regarding data alignment and discrepancies. These changes aim to enhance the robustness and clarity of the database synchronization workflow.
This commit is contained in:
@ -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';
|
||||
|
||||
Reference in New Issue
Block a user