feat: integrate with flysystem for xml data

This commit is contained in:
Björn Fromme
2025-03-28 09:20:46 +01:00
parent 42b7c2b546
commit a92832f069
11 changed files with 601 additions and 21 deletions
+21 -8
View File
@@ -5,13 +5,15 @@ namespace App\Command;
use App\BusProNet\DataProvider\HotelDataProvider;
use App\BusProNet\DataProvider\PickupDataProvider;
use Doctrine\DBAL\Connection;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\StorageAttributes;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
#[AsCommand(
name: 'app:bpn-import',
@@ -24,7 +26,7 @@ class BpnImportCommand extends Command
private readonly HotelDataProvider $hotelDataProvider,
private readonly PickupDataProvider $pickupDataProvider,
private readonly LoggerInterface $logger,
private readonly string $xmlFilesPath
private readonly FilesystemOperator $xmlExport,
) {
parent::__construct();
}
@@ -34,10 +36,17 @@ class BpnImportCommand extends Command
$io = new SymfonyStyle($input, $output);
// Get all xml files
$xmlFiles = (new Finder())
->name('Ziel_*.xml')
->in($this->xmlFilesPath)
;
try {
$xmlFiles = $this
->xmlExport
->listContents('.')
->filter(fn(StorageAttributes $attributes) => $attributes->isFile() && str_starts_with($attributes->path(), 'Ziel_'))
->toArray();
} catch (FilesystemException $e) {
$io->error('Unable to list XML files');
return Command::FAILURE;
}
$totalCount = count($xmlFiles);
@@ -53,9 +62,13 @@ class BpnImportCommand extends Command
// Iterate over xml files
foreach ($xmlFiles as $xmlFile) {
// Load xml file into simplexml object
$xml = simplexml_load_file($xmlFile);
try {
$xml = simplexml_load_string($this->xmlExport->read($xmlFile->path()));
} catch (FilesystemException $e) {
$io->warning('Unable to read XML file '.$xmlFile->path());
continue;
}
// Iterate over all destinations
foreach ($xml->xpath('reise/termin') as $destinationXml) {