fix: delete unavailable files during xml sync
addresses #869chrmp4
This commit is contained in:
@@ -106,7 +106,7 @@ class BpnXmlSyncCommand extends Command
|
||||
$io->section('Syncing files');
|
||||
|
||||
try {
|
||||
$syncedCount = $this->syncFiles($io);
|
||||
$syncResult = $this->syncFiles($io);
|
||||
} catch (FilesystemException $e) {
|
||||
$io->error(sprintf('Sync failed: %s', $e->getMessage()));
|
||||
$this->logger->error('XML sync failed during file transfer', ['exception' => $e]);
|
||||
@@ -117,9 +117,14 @@ class BpnXmlSyncCommand extends Command
|
||||
$this->invalidateCaches();
|
||||
$io->text(sprintf('Invalidated %d cache keys', count(self::CACHE_KEYS_TO_INVALIDATE)));
|
||||
|
||||
$io->success(sprintf('Synced %d files', $syncedCount));
|
||||
$io->success(sprintf(
|
||||
'Sync complete: %d files updated, %d files deleted',
|
||||
$syncResult['updated'],
|
||||
$syncResult['deleted']
|
||||
));
|
||||
$this->logger->info('XML sync completed', [
|
||||
'files_synced' => $syncedCount,
|
||||
'files_updated' => $syncResult['updated'],
|
||||
'files_deleted' => $syncResult['deleted'],
|
||||
'remote_timestamp' => $remoteInfo->lastTransfer->format('c'),
|
||||
]);
|
||||
|
||||
@@ -159,17 +164,25 @@ class BpnXmlSyncCommand extends Command
|
||||
/**
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
private function syncFiles(SymfonyStyle $io): int
|
||||
private function syncFiles(SymfonyStyle $io): array
|
||||
{
|
||||
$files = $this->xmlSource
|
||||
$remoteFiles = $this->xmlSource
|
||||
->listContents('.')
|
||||
->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
|
||||
->map(fn (StorageAttributes $attributes) => $attributes->path())
|
||||
->toArray();
|
||||
|
||||
$io->progressStart(count($files));
|
||||
$localFiles = $this->xmlExport
|
||||
->listContents('.')
|
||||
->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
|
||||
->map(fn (StorageAttributes $attributes) => $attributes->path())
|
||||
->toArray();
|
||||
|
||||
foreach ($files as $path) {
|
||||
$filesToDelete = array_diff($localFiles, $remoteFiles);
|
||||
|
||||
$io->progressStart(count($remoteFiles));
|
||||
|
||||
foreach ($remoteFiles as $path) {
|
||||
$content = $this->xmlSource->read($path);
|
||||
$this->xmlExport->write($path, $content);
|
||||
$io->progressAdvance();
|
||||
@@ -177,7 +190,14 @@ class BpnXmlSyncCommand extends Command
|
||||
|
||||
$io->progressFinish();
|
||||
|
||||
return count($files);
|
||||
foreach ($filesToDelete as $path) {
|
||||
$this->xmlExport->delete($path);
|
||||
}
|
||||
|
||||
return [
|
||||
'updated' => count($remoteFiles),
|
||||
'deleted' => count($filesToDelete),
|
||||
];
|
||||
}
|
||||
|
||||
private function invalidateCaches(): void
|
||||
|
||||
Reference in New Issue
Block a user