From a92832f0690b1b726a22b932c4773fcf938a28d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 28 Mar 2025 09:20:46 +0100 Subject: [PATCH] feat: integrate with flysystem for xml data --- .env | 1 + composer.json | 2 + composer.lock | 536 ++++++++++++++++++++++++++++++- config/bundles.php | 1 + config/packages/flysystem.yaml | 17 + config/services.yaml | 4 +- deploy.php | 2 - src/BusProNet/ApiClient.php | 15 +- src/Command/BpnImportCommand.php | 29 +- symfony.lock | 13 + xmlexport/.gitignore | 2 - 11 files changed, 601 insertions(+), 21 deletions(-) create mode 100644 config/packages/flysystem.yaml delete mode 100644 xmlexport/.gitignore diff --git a/.env b/.env index 6e238a8..8d9add8 100644 --- a/.env +++ b/.env @@ -58,6 +58,7 @@ APP_BPN_CRM_ID_TEAMER=1070 APP_DEFAULT_EMAIL_FROM=team@ep-reisen.de APP_DEFAULT_EMAIL_TO=team@ep-reisen.de +XML_EXPORT_PATH="%kernel.project_dir%/var/xmlexport" ###> symfony/mailjet-mailer ### # MAILER_DSN=mailjet+api://PUBLIC_KEY:PRIVATE_KEY@api.mailjet.com diff --git a/composer.json b/composer.json index b0c00fa..61468bb 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,8 @@ "flagception/flagception-bundle": "^6.0", "knplabs/knp-menu-bundle": "^3.2", "knplabs/knp-paginator-bundle": "^6.2", + "league/flysystem-bundle": "^3.4", + "league/flysystem-sftp-v3": "^3.29", "liip/imagine-bundle": "^2.11", "maennchen/zipstream-php": "^3.1", "nelmio/security-bundle": "^3.0", diff --git a/composer.lock b/composer.lock index 88d921a..9b3afd5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0bd1cb4a8201fb9558138001813bec5a", + "content-hash": "6b642cc934ca08eb66d76d03fa59acf7", "packages": [ { "name": "beberlei/doctrineextensions", @@ -2093,6 +2093,313 @@ }, "time": "2025-03-02T16:36:05+00:00" }, + { + "name": "league/flysystem", + "version": "3.29.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem.git", + "reference": "edc1bb7c86fab0776c3287dbd19b5fa278347319" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/edc1bb7c86fab0776c3287dbd19b5fa278347319", + "reference": "edc1bb7c86fab0776c3287dbd19b5fa278347319", + "shasum": "" + }, + "require": { + "league/flysystem-local": "^3.0.0", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2" + }, + "conflict": { + "async-aws/core": "<1.19.0", + "async-aws/s3": "<1.14.0", + "aws/aws-sdk-php": "3.209.31 || 3.210.0", + "guzzlehttp/guzzle": "<7.0", + "guzzlehttp/ringphp": "<1.1.1", + "phpseclib/phpseclib": "3.0.15", + "symfony/http-client": "<5.2" + }, + "require-dev": { + "async-aws/s3": "^1.5 || ^2.0", + "async-aws/simple-s3": "^1.1 || ^2.0", + "aws/aws-sdk-php": "^3.295.10", + "composer/semver": "^3.0", + "ext-fileinfo": "*", + "ext-ftp": "*", + "ext-mongodb": "^1.3", + "ext-zip": "*", + "friendsofphp/php-cs-fixer": "^3.5", + "google/cloud-storage": "^1.23", + "guzzlehttp/psr7": "^2.6", + "microsoft/azure-storage-blob": "^1.1", + "mongodb/mongodb": "^1.2", + "phpseclib/phpseclib": "^3.0.36", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.11|^10.0", + "sabre/dav": "^4.6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "File storage abstraction for PHP", + "keywords": [ + "WebDAV", + "aws", + "cloud", + "file", + "files", + "filesystem", + "filesystems", + "ftp", + "s3", + "sftp", + "storage" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem/issues", + "source": "https://github.com/thephpleague/flysystem/tree/3.29.1" + }, + "time": "2024-10-08T08:58:34+00:00" + }, + { + "name": "league/flysystem-bundle", + "version": "3.4.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-bundle.git", + "reference": "6493f7f2ab49bc5817e4b064b9b971d93faabc12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-bundle/zipball/6493f7f2ab49bc5817e4b064b9b971d93faabc12", + "reference": "6493f7f2ab49bc5817e4b064b9b971d93faabc12", + "shasum": "" + }, + "require": { + "league/flysystem": "^3.0", + "php": ">=8.0", + "symfony/config": "^5.4 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", + "symfony/deprecation-contracts": "^2.1 || ^3", + "symfony/http-kernel": "^5.4 || ^6.0 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.0 || ^7.0" + }, + "require-dev": { + "doctrine/mongodb-odm": "^2.0", + "league/flysystem-async-aws-s3": "^3.1", + "league/flysystem-aws-s3-v3": "^3.1", + "league/flysystem-azure-blob-storage": "^3.1", + "league/flysystem-ftp": "^3.1", + "league/flysystem-google-cloud-storage": "^3.1", + "league/flysystem-gridfs": "^3.28", + "league/flysystem-memory": "^3.1", + "league/flysystem-read-only": "^3.15", + "league/flysystem-sftp-v3": "^3.1", + "league/flysystem-webdav": "^3.29", + "symfony/dotenv": "^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0", + "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "League\\FlysystemBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Titouan Galopin", + "email": "galopintitouan@gmail.com" + } + ], + "description": "Symfony bundle integrating Flysystem into Symfony applications", + "keywords": [ + "Flysystem", + "bundle", + "filesystem", + "symfony" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem-bundle/issues", + "source": "https://github.com/thephpleague/flysystem-bundle/tree/3.4.0" + }, + "time": "2025-01-23T18:07:31+00:00" + }, + { + "name": "league/flysystem-local", + "version": "3.29.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-local.git", + "reference": "e0e8d52ce4b2ed154148453d321e97c8e931bd27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/e0e8d52ce4b2ed154148453d321e97c8e931bd27", + "reference": "e0e8d52ce4b2ed154148453d321e97c8e931bd27", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "league/flysystem": "^3.0.0", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\Local\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "Local filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "file", + "files", + "filesystem", + "local" + ], + "support": { + "source": "https://github.com/thephpleague/flysystem-local/tree/3.29.0" + }, + "time": "2024-08-09T21:24:39+00:00" + }, + { + "name": "league/flysystem-sftp-v3", + "version": "3.29.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-sftp-v3.git", + "reference": "ce9b209e2fbe33122c755ffc18eb4d5bd256f252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-sftp-v3/zipball/ce9b209e2fbe33122c755ffc18eb4d5bd256f252", + "reference": "ce9b209e2fbe33122c755ffc18eb4d5bd256f252", + "shasum": "" + }, + "require": { + "league/flysystem": "^3.0.14", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2", + "phpseclib/phpseclib": "^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\PhpseclibV3\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "SFTP filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "file", + "files", + "filesystem", + "sftp" + ], + "support": { + "source": "https://github.com/thephpleague/flysystem-sftp-v3/tree/3.29.0" + }, + "time": "2024-08-14T19:35:54+00:00" + }, + { + "name": "league/mime-type-detection", + "version": "1.16.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/mime-type-detection.git", + "reference": "2d6702ff215bf922936ccc1ad31007edc76451b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/2d6702ff215bf922936ccc1ad31007edc76451b9", + "reference": "2d6702ff215bf922936ccc1ad31007edc76451b9", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.2", + "phpstan/phpstan": "^0.12.68", + "phpunit/phpunit": "^8.5.8 || ^9.3 || ^10.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\MimeTypeDetection\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "Mime-type detection for Flysystem", + "support": { + "issues": "https://github.com/thephpleague/mime-type-detection/issues", + "source": "https://github.com/thephpleague/mime-type-detection/tree/1.16.0" + }, + "funding": [ + { + "url": "https://github.com/frankdejonge", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/league/flysystem", + "type": "tidelift" + } + ], + "time": "2024-09-21T08:32:55+00:00" + }, { "name": "liip/imagine-bundle", "version": "2.13.3", @@ -2655,6 +2962,123 @@ }, "time": "2022-07-25T07:51:47+00:00" }, + { + "name": "paragonie/constant_time_encoding", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/paragonie/constant_time_encoding.git", + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/df1e7fde177501eee2037dd159cf04f5f301a512", + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512", + "shasum": "" + }, + "require": { + "php": "^8" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "vimeo/psalm": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "ParagonIE\\ConstantTime\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com", + "role": "Maintainer" + }, + { + "name": "Steve 'Sc00bz' Thomas", + "email": "steve@tobtu.com", + "homepage": "https://www.tobtu.com", + "role": "Original Developer" + } + ], + "description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)", + "keywords": [ + "base16", + "base32", + "base32_decode", + "base32_encode", + "base64", + "base64_decode", + "base64_encode", + "bin2hex", + "encoding", + "hex", + "hex2bin", + "rfc4648" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/constant_time_encoding/issues", + "source": "https://github.com/paragonie/constant_time_encoding" + }, + "time": "2024-05-08T12:36:18+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v9.99.100", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "shasum": "" + }, + "require": { + "php": ">= 7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/random_compat/issues", + "source": "https://github.com/paragonie/random_compat" + }, + "time": "2020-10-15T08:29:30+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -2830,6 +3254,116 @@ }, "time": "2024-11-09T15:12:26+00:00" }, + { + "name": "phpseclib/phpseclib", + "version": "3.0.43", + "source": { + "type": "git", + "url": "https://github.com/phpseclib/phpseclib.git", + "reference": "709ec107af3cb2f385b9617be72af8cf62441d02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/709ec107af3cb2f385b9617be72af8cf62441d02", + "reference": "709ec107af3cb2f385b9617be72af8cf62441d02", + "shasum": "" + }, + "require": { + "paragonie/constant_time_encoding": "^1|^2|^3", + "paragonie/random_compat": "^1.4|^2.0|^9.99.99", + "php": ">=5.6.1" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "ext-dom": "Install the DOM extension to load XML formatted public keys.", + "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", + "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", + "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", + "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." + }, + "type": "library", + "autoload": { + "files": [ + "phpseclib/bootstrap.php" + ], + "psr-4": { + "phpseclib3\\": "phpseclib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jim Wigginton", + "email": "terrafrost@php.net", + "role": "Lead Developer" + }, + { + "name": "Patrick Monnerat", + "email": "pm@datasphere.ch", + "role": "Developer" + }, + { + "name": "Andreas Fischer", + "email": "bantu@phpbb.com", + "role": "Developer" + }, + { + "name": "Hans-Jürgen Petrich", + "email": "petrich@tronic-media.com", + "role": "Developer" + }, + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "role": "Developer" + } + ], + "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", + "homepage": "http://phpseclib.sourceforge.net", + "keywords": [ + "BigInteger", + "aes", + "asn.1", + "asn1", + "blowfish", + "crypto", + "cryptography", + "encryption", + "rsa", + "security", + "sftp", + "signature", + "signing", + "ssh", + "twofish", + "x.509", + "x509" + ], + "support": { + "issues": "https://github.com/phpseclib/phpseclib/issues", + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.43" + }, + "funding": [ + { + "url": "https://github.com/terrafrost", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpseclib", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib", + "type": "tidelift" + } + ], + "time": "2024-12-14T21:12:59+00:00" + }, { "name": "phpstan/phpdoc-parser", "version": "1.33.0", diff --git a/config/bundles.php b/config/bundles.php index 2029c8c..6cd191c 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -20,4 +20,5 @@ return [ Nelmio\SecurityBundle\NelmioSecurityBundle::class => ['all' => true], Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true], Flagception\Bundle\FlagceptionBundle\FlagceptionBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], ]; diff --git a/config/packages/flysystem.yaml b/config/packages/flysystem.yaml new file mode 100644 index 0000000..021018c --- /dev/null +++ b/config/packages/flysystem.yaml @@ -0,0 +1,17 @@ +# Read the documentation at https://github.com/thephpleague/flysystem-bundle/blob/master/docs/1-getting-started.md +flysystem: + storages: + xml_export.storage: + adapter: 'local' + options: + directory: '%env(resolve:XML_EXPORT_PATH)%' + xml_dump.storage: + adapter: 'local' + options: + directory: '%kernel.project_dir%/var/bpn' +# adapter: 'sftp' +# options: +# host: '%env(SFTP_XML_EXPORT_HOST)%' +# port: '%env(int:SFTP_XML_EXPORT_PORT)%' +# username: '%env(SFTP_XML_EXPORT_USER)%' +# password: '%env(SFTP_XML_EXPORT_PASSWORD)%' diff --git a/config/services.yaml b/config/services.yaml index 94d841f..b658485 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -34,6 +34,8 @@ services: $tempDir: '%kernel.project_dir%/temp' $logger: '@monolog.logger.myep' $destinations: '%destinations%' + $xmlExport: '@xml_export.storage' + $xmlDump: '@xml_dump.storage' App\: resource: '../src/' @@ -53,7 +55,6 @@ services: App\Command\BpnImportCommand: arguments: $connection: '@doctrine.dbal.default_connection' - $xmlFilesPath: '%kernel.project_dir%/xmlexport' App\Command\GenerateThumbnailsCommand: arguments: @@ -69,7 +70,6 @@ services: bpn_api_ip: '%env(APP_BPN_IP)%' bpn_api_port: '%env(APP_BPN_PORT)%' debug: '%env(bool:APP_BPN_DEBUG)%' - target_folder_dumps: '%kernel.project_dir%/var/bpn' App\BusProNet\ResponseParser: arguments: diff --git a/deploy.php b/deploy.php index f5c04a1..5419cc6 100644 --- a/deploy.php +++ b/deploy.php @@ -10,7 +10,6 @@ add('shared_dirs', [ 'uploads', 'var/log', 'var/sessions', - 'xmlexport', ]); add('shared_files', [ @@ -52,7 +51,6 @@ $rsyncOptions = [ 'temp/*', 'tests/', 'uploads/', - 'xmlexport/', 'var/', ], 'exclude-file' => false, diff --git a/src/BusProNet/ApiClient.php b/src/BusProNet/ApiClient.php index 5d8483f..b6eee77 100644 --- a/src/BusProNet/ApiClient.php +++ b/src/BusProNet/ApiClient.php @@ -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); } -} \ No newline at end of file +} diff --git a/src/Command/BpnImportCommand.php b/src/Command/BpnImportCommand.php index 26abe69..a7bf608 100644 --- a/src/Command/BpnImportCommand.php +++ b/src/Command/BpnImportCommand.php @@ -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) { diff --git a/symfony.lock b/symfony.lock index f9d7378..ab93bf9 100644 --- a/symfony.lock +++ b/symfony.lock @@ -44,6 +44,19 @@ "knplabs/knp-paginator-bundle": { "version": "v6.2.0" }, + "league/flysystem-bundle": { + "version": "3.4", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.0", + "ref": "913dc3d7a5a1af0d2b044c5ac3a16e2f851d7380" + }, + "files": [ + "config/packages/flysystem.yaml", + "var/storage/.gitignore" + ] + }, "liip/imagine-bundle": { "version": "2.11", "recipe": { diff --git a/xmlexport/.gitignore b/xmlexport/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/xmlexport/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore