fix: collect dataset transfer failures instead of breaking execution
This commit is contained in:
@@ -66,7 +66,7 @@ class BpnXmlSyncCommand extends Command
|
||||
$totalSyncedCount = 0;
|
||||
$totalDeletedCount = 0;
|
||||
$hasSyncedFiles = false;
|
||||
$hasFailures = false;
|
||||
$failedDatasets = [];
|
||||
$travelSynced = false;
|
||||
$travelRemoteTimestamp = null;
|
||||
$snapshotResult = null;
|
||||
@@ -76,7 +76,7 @@ class BpnXmlSyncCommand extends Command
|
||||
$targetResult = $this->syncTarget($target, $force, $dryRun, $io, $output);
|
||||
|
||||
if ($targetResult['failed']) {
|
||||
$hasFailures = true;
|
||||
$failedDatasets[] = $targetResult['dataset'];
|
||||
}
|
||||
|
||||
if (false === $targetResult['synced']) {
|
||||
@@ -109,10 +109,6 @@ class BpnXmlSyncCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasFailures) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($dryRun) {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
@@ -136,14 +132,38 @@ class BpnXmlSyncCommand extends Command
|
||||
$successMessage .= sprintf(', orphaned deleted: %d', $orphanedDeleted);
|
||||
}
|
||||
|
||||
$io->success($successMessage);
|
||||
$this->logger->info('XML sync completed', [
|
||||
if ([] !== $failedDatasets) {
|
||||
$successMessage .= sprintf(', failed datasets: %s', implode(', ', $failedDatasets));
|
||||
}
|
||||
|
||||
$logContext = [
|
||||
'files_updated' => $totalSyncedCount,
|
||||
'files_deleted' => $totalDeletedCount,
|
||||
'snapshots_processed' => $snapshotResult?->processed,
|
||||
'snapshots_failed' => $snapshotResult?->failed,
|
||||
'orphaned_deleted' => $orphanedDeleted,
|
||||
'remote_timestamp' => $travelRemoteTimestamp,
|
||||
'failed_datasets' => $failedDatasets,
|
||||
];
|
||||
|
||||
if ([] !== $failedDatasets) {
|
||||
$io->warning($successMessage);
|
||||
$this->logger->warning('XML sync completed with dataset errors', $logContext);
|
||||
} else {
|
||||
$io->success($successMessage);
|
||||
$this->logger->info('XML sync completed', $logContext);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
if ([] !== $failedDatasets) {
|
||||
$io->warning(sprintf(
|
||||
'Sync completed with errors for: %s',
|
||||
implode(', ', $failedDatasets),
|
||||
));
|
||||
$this->logger->warning('XML sync completed with dataset errors', [
|
||||
'failed_datasets' => $failedDatasets,
|
||||
]);
|
||||
|
||||
return Command::SUCCESS;
|
||||
@@ -155,7 +175,7 @@ class BpnXmlSyncCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{synced: bool, failed: bool, updated: int, deleted: int, travelSynced: bool, remoteTimestamp: ?string}
|
||||
* @return array{dataset: string, synced: bool, failed: bool, updated: int, deleted: int, travelSynced: bool, remoteTimestamp: ?string}
|
||||
*/
|
||||
private function syncTarget(
|
||||
BpnXmlSyncTarget $target,
|
||||
@@ -175,6 +195,7 @@ class BpnXmlSyncCommand extends Command
|
||||
));
|
||||
|
||||
return [
|
||||
'dataset' => $datasetName,
|
||||
'synced' => false,
|
||||
'failed' => false,
|
||||
'updated' => 0,
|
||||
@@ -201,6 +222,7 @@ class BpnXmlSyncCommand extends Command
|
||||
]);
|
||||
|
||||
return [
|
||||
'dataset' => $datasetName,
|
||||
'synced' => false,
|
||||
'failed' => false,
|
||||
'updated' => 0,
|
||||
@@ -214,6 +236,7 @@ class BpnXmlSyncCommand extends Command
|
||||
$io->note(sprintf('[%s] Sync required (dry-run mode, no files downloaded)', $datasetName));
|
||||
|
||||
return [
|
||||
'dataset' => $datasetName,
|
||||
'synced' => false,
|
||||
'failed' => false,
|
||||
'updated' => 0,
|
||||
@@ -244,6 +267,7 @@ class BpnXmlSyncCommand extends Command
|
||||
]);
|
||||
|
||||
return [
|
||||
'dataset' => $datasetName,
|
||||
'synced' => false,
|
||||
'failed' => true,
|
||||
'updated' => 0,
|
||||
@@ -279,6 +303,7 @@ class BpnXmlSyncCommand extends Command
|
||||
]);
|
||||
|
||||
return [
|
||||
'dataset' => $datasetName,
|
||||
'synced' => true,
|
||||
'failed' => false,
|
||||
'updated' => $syncResult['updated'],
|
||||
|
||||
Reference in New Issue
Block a user