feat: import xml export from buspro over sftp

This commit is contained in:
2026-09-03 10:39:38 +02:00
parent df1e38b008
commit 357c43eead
4 changed files with 47 additions and 12 deletions
+23 -4
View File
@@ -39,7 +39,7 @@ class BpnImportCommand extends Command
try {
$xmlFiles = $this
->xmlExport
->listContents('.')
->listContents('')
->filter(fn (StorageAttributes $attributes) => $attributes->isFile() && str_starts_with($attributes->path(), 'Ziel_'))
->toArray();
} catch (FilesystemException $e) {
@@ -59,14 +59,23 @@ class BpnImportCommand extends Command
$io->info('Found '.$totalCount.' XML files');
$addedCount = 0;
$updatedCount = 0;
$warnings = [];
$progressBar = $io->createProgressBar($totalCount);
$progressBar->setFormat(" %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%\n %message%");
$progressBar->setMessage('Starting');
$progressBar->start();
// Iterate over xml files
foreach ($xmlFiles as $xmlFile) {
$progressBar->setMessage($xmlFile->path());
// Load xml file into simplexml object
try {
$xml = simplexml_load_string($this->xmlExport->read($xmlFile->path()));
} catch (FilesystemException $e) {
$io->warning('Unable to read XML file '.$xmlFile->path());
$warnings[] = 'Unable to read XML file '.$xmlFile->path();
$progressBar->advance();
continue;
}
@@ -84,7 +93,7 @@ class BpnImportCommand extends Command
$pickupBusProId = (int) $pickupXml->attributes()['idbuspro'];
if ($pickupBusProId) {
if (null === $pickup = $this->pickupDataProvider->get($pickupBusProId)) {
$io->warning('Pickup with busProId '.$pickupBusProId.' not found');
$warnings[] = 'Pickup with busProId '.$pickupBusProId.' not found';
continue;
}
@@ -101,7 +110,7 @@ class BpnImportCommand extends Command
foreach ($destinationXml->xpath('hotel') as $hotelXml) {
$hotelBusProId = (int) $hotelXml->attributes()['idbuspro'];
if (null === $hotel = $this->hotelDataProvider->get($hotelBusProId)) {
$io->warning('Hotel with busProId '.$hotelBusProId.' not found');
$warnings[] = 'Hotel with busProId '.$hotelBusProId.' not found';
continue;
}
@@ -146,6 +155,16 @@ class BpnImportCommand extends Command
}
}
}
$progressBar->advance();
}
$progressBar->setMessage('Done');
$progressBar->finish();
$io->newLine(2);
if ($warnings) {
$io->warning(array_unique($warnings));
}
$logMessage = 'Added '.$addedCount.' and updated '.$updatedCount.' destinations';