feat: adjust xml dump reader command to new filename format

This commit is contained in:
Björn Fromme
2026-01-10 11:31:24 +01:00
parent 168c128b1d
commit 28b62f5071
+40 -4
View File
@@ -49,17 +49,22 @@ class ReadXmlDumpCommand extends Command
return Command::FAILURE; return Command::FAILURE;
} }
$filename = $requestId.'_'.$type.'.xml';
try { try {
if (false === $this->xmlDump->fileExists($filename)) { $files = $this->findMatchingFiles($requestId, $type);
$io->warning(sprintf('Dump file "%s" not found. It may have been cleaned up.', $filename));
if (0 === count($files)) {
$io->warning(sprintf('No dump files found for request ID "%s". They may have been cleaned up.', $requestId));
return Command::FAILURE; return Command::FAILURE;
} }
foreach ($files as $filename) {
if (count($files) > 1) {
$io->section($filename);
}
$content = $this->xmlDump->read($filename); $content = $this->xmlDump->read($filename);
$output->writeln($content); $output->writeln($content);
}
return Command::SUCCESS; return Command::SUCCESS;
} catch (FilesystemException $e) { } catch (FilesystemException $e) {
@@ -68,4 +73,35 @@ class ReadXmlDumpCommand extends Command
return Command::FAILURE; return Command::FAILURE;
} }
} }
/**
* Finds dump files matching the given request ID and type.
*
* Supports both exact matches (e.g., "abc123_1") and base ID matches (e.g., "abc123")
* which will return all files with counter suffixes.
*
* @return string[]
*
* @throws FilesystemException
*/
private function findMatchingFiles(string $requestId, string $type): array
{
$exactMatch = $requestId.'_'.$type.'.xml';
if ($this->xmlDump->fileExists($exactMatch)) {
return [$exactMatch];
}
$pattern = '/^'.preg_quote($requestId, '/').'_\d+_'.$type.'\.xml$/';
$matches = [];
foreach ($this->xmlDump->listContents('.') as $item) {
if ($item->isFile() && 1 === preg_match($pattern, $item->path())) {
$matches[] = $item->path();
}
}
sort($matches);
return $matches;
}
} }