feat: integrate with flysystem for xml data
This commit is contained in:
@@ -7,6 +7,8 @@ use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\NotificationResponse;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\Entity\User;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
@@ -28,6 +30,7 @@ class ApiClient
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly ResponseParser $responseParser,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly FilesystemOperator $xmlDump,
|
||||
array $options
|
||||
) {
|
||||
$this->config = $this->resolveOptions($options);
|
||||
@@ -173,11 +176,12 @@ class ApiClient
|
||||
|
||||
private function dumpXmlToFile(string $type, string $requestId, string $body): void
|
||||
{
|
||||
if (false === file_exists($this->config['target_folder_dumps'])) {
|
||||
mkdir($this->config['target_folder_dumps']);
|
||||
$filename = $requestId.'_'.$type.'.xml';
|
||||
try {
|
||||
$this->xmlDump->write($filename, $body);
|
||||
} catch (FilesystemException $e) {
|
||||
$this->logger->error('Unable to dump XML file '.$e->getMessage());
|
||||
}
|
||||
|
||||
file_put_contents($this->config['target_folder_dumps'].'/'.$requestId.'_'.$type.'.xml', $body);
|
||||
}
|
||||
|
||||
private function createKey(string $username, string $password, string $type): string
|
||||
@@ -199,9 +203,8 @@ class ApiClient
|
||||
$optionsResolver->setDefaults([
|
||||
'max_retries' => 25,
|
||||
'debug' => false,
|
||||
'target_folder_dumps' => '/var/www/html/var/bpn',
|
||||
]);
|
||||
|
||||
return $optionsResolver->resolve($options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user