fix: fail gracefully when remote XML data cannot be read during sync
This commit is contained in:
@@ -63,13 +63,12 @@ class BpnXmlSyncCommand extends Command
|
||||
$force = $input->getOption('force');
|
||||
$dryRun = $input->getOption('dry-run');
|
||||
|
||||
try {
|
||||
$remoteInfo = $this->readRemoteInfo();
|
||||
} catch (FilesystemException|\InvalidArgumentException $e) {
|
||||
$io->error(sprintf('Failed to read remote info: %s', $e->getMessage()));
|
||||
$this->logger->error('XML sync failed: could not read remote info', ['exception' => $e]);
|
||||
$remoteInfo = $this->readRemoteInfo();
|
||||
|
||||
return Command::FAILURE;
|
||||
if (null === $remoteInfo) {
|
||||
$io->warning('Remote info unavailable - will retry on next scheduled run');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$io->text(sprintf(
|
||||
@@ -127,11 +126,19 @@ class BpnXmlSyncCommand extends Command
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function readRemoteInfo(): XmlExportInfo
|
||||
private function readRemoteInfo(): ?XmlExportInfo
|
||||
{
|
||||
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
|
||||
try {
|
||||
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
|
||||
|
||||
return XmlExportInfo::fromString($content);
|
||||
return XmlExportInfo::fromString($content);
|
||||
} catch (FilesystemException|\InvalidArgumentException $e) {
|
||||
$this->logger->warning('Could not read remote info file, likely being updated', [
|
||||
'exception' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function readLocalInfo(): ?XmlExportInfo
|
||||
|
||||
Reference in New Issue
Block a user