From 45365a48722a4d17ef0d2a9a7db1ad64cc3c06f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sat, 26 Jun 2021 15:20:13 +0200 Subject: [PATCH 1/2] Use hotel uid in groups.swiss export command, code cleanup --- .../Classes/Command/GroupsSwissCommand.php | 8 ++--- .../Repository/ContingentRepository.php | 33 +++++++++---------- .../Classes/Service/GroupsSwissService.php | 23 +++++-------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Command/GroupsSwissCommand.php b/public/typo3conf/ext/ep_products/Classes/Command/GroupsSwissCommand.php index 9d4686b7..10ab024d 100644 --- a/public/typo3conf/ext/ep_products/Classes/Command/GroupsSwissCommand.php +++ b/public/typo3conf/ext/ep_products/Classes/Command/GroupsSwissCommand.php @@ -58,12 +58,12 @@ class GroupsSwissCommand extends Command $this->addArgument( 'hotel', InputArgument::REQUIRED, - 'E&P hotel code' + 'E&P hotel uid' ); $this->addArgument( 'house', InputArgument::REQUIRED, - 'House number' + 'Groups.swiss house number' ); $this->addArgument( 'key', @@ -74,11 +74,11 @@ class GroupsSwissCommand extends Command public function execute(InputInterface $input, OutputInterface $output) { - $hotelCode = $input->getArgument('hotel'); + $hotelUid = $input->getArgument('hotel'); $houseNumber = $input->getArgument('house'); $apiKey = $input->getArgument('key'); - $success = $this->groupsSwissService->publishContingents($hotelCode, $houseNumber, $apiKey); + $success = $this->groupsSwissService->publishContingents($hotelUid, $houseNumber, $apiKey); return $success ? 1 : 0; } diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php index 04458b57..380d5d56 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php @@ -27,7 +27,9 @@ namespace EP\EpProducts\Domain\Repository; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use CalendR\Event\EventInterface; use CalendR\Event\Provider\ProviderInterface; +use Doctrine\DBAL\DBALException; use EP\EpProducts\Domain\Model\Contingent; use EP\EpProducts\Domain\Model\Hotel; use EP\EpProducts\Domain\Model\Product; @@ -37,23 +39,22 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa { /** - * @param \DateTime $dateFrom - * @param \DateTime $dateTo + * @param \DateTime $begin + * @param \DateTime|null $end * @param array $options - * @return \CalendR\Event\EventInterface[] - * @throws \Doctrine\DBAL\DBALException + * @return EventInterface[] + * @throws DBALException */ - public function getEvents(\DateTime $dateFrom, \DateTime $dateTo = null, array $options = []) + public function getEvents(\DateTime $begin, \DateTime $end = null, array $options = []): array { $optionsResolver = new OptionsResolver(); - $optionsResolver->setRequired(['hotelCode']); - $optionsResolver->setDefined(['hotel']); - $optionsResolver->setDefaults(['hotel' => null]); + $optionsResolver->setRequired(['hotel']); $optionsResolver->setAllowedTypes('hotel', Hotel::class); $resolvedOptions = $optionsResolver->resolve($options); + /** @var Hotel $hotel */ $hotel = $resolvedOptions['hotel']; - $hotelCode = $resolvedOptions['hotelCode']; + $hotelCode = $hotel->getCode(); $qb = $this->getDbConnection()->createQueryBuilder(); @@ -63,14 +64,14 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa ->where('hotel_code = :hotelCode') ->andWhere('date >= :dateFrom') ->setParameter('hotelCode', $hotelCode) - ->setParameter('dateFrom', $dateFrom->format('Y-m-d')) + ->setParameter('dateFrom', $begin->format('Y-m-d')) ->orderBy('date') ; - if (null !== $dateTo) { + if (null !== $end) { $qb ->andWhere('date <= :dateTo') - ->setParameter('dateTo', $dateTo->format('Y-m-d')) + ->setParameter('dateTo', $end->format('Y-m-d')) ; } @@ -101,9 +102,7 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa foreach ($dates as $row) { - if ($hotel) { - $row['hotel'] = $hotel; - } + $row['hotel'] = $hotel; $events[] = Contingent::fromArray($row); } @@ -114,7 +113,7 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa * @param Hotel $hotel * @param Product $product * @return array - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function getAvailableContingents(Hotel $hotel, Product $product) { @@ -147,7 +146,7 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa * @param Hotel $hotel * @param Product $product * @return array - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function getAvailableRooms(\DateTime $dateFrom, \DateTime $dateTo, Hotel $hotel, Product $product) { diff --git a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php index 87f64ea3..9954bc0e 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php @@ -37,8 +37,6 @@ use Psr\Log\LoggerAwareTrait; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use TYPO3\CMS\Core\SingletonInterface; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Extbase\Configuration\Exception; class GroupsSwissService implements SingletonInterface, LoggerAwareInterface { @@ -62,26 +60,22 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface /** * @param HotelRepository $hotelRepository * @param ContingentRepository $contingentRepository - * @param ConfigurationManagerInterface $configurationManager */ - public function __construct( - HotelRepository $hotelRepository, - ContingentRepository $contingentRepository, - ConfigurationManagerInterface $configurationManager - ) { + public function __construct(HotelRepository $hotelRepository, ContingentRepository $contingentRepository) + { $this->hotelRepository = $hotelRepository; $this->contingentRepository = $contingentRepository; $this->httpClient = HttpClient::create(); } - public function publishContingents(string $hotelCode, int $houseNumber, string $apiKey): bool + public function publishContingents(int $hotelUid, int $houseNumber, string $apiKey): bool { $range = Period::after(new \DateTime('now'), '1 year'); - $result = $this->hotelRepository->findByCode($hotelCode); + $result = $this->hotelRepository->findByIdentifier($hotelUid); if (null === $result) { - $this->logger->error(sprintf('Hotel with code %s not found', $hotelCode)); + $this->logger->error(sprintf('Hotel with uid %d not found', $hotelUid)); return false; } @@ -92,11 +86,12 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface $events = $this->contingentRepository->getEvents( \DateTime::createFromImmutable($range->getStartDate()), \DateTime::createFromImmutable($range->getEndDate()), - ['hotel' => $hotel, 'hotelCode' => $hotelCode] + ['hotel' => $hotel] ); } catch (DBALException $e) { - $events = []; + $this->logger->error(sprintf('No dates found for hotel with uid %d', $hotelUid)); + return false; } $this->resetChart($range, $apiKey, $houseNumber); @@ -134,7 +129,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface */ protected function generateChart(array $events, $apiKey, $houseNumber): void { - $itemCount = 0; $item = null; $status = null; @@ -151,7 +145,6 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface $statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2; $this->addItem($item, $statusCode, $apiKey, $houseNumber); $item = null; - $itemCount++; } } } From 36e8e7d92dcd153021278e77cf51daf5670dd5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sat, 26 Jun 2021 15:21:40 +0200 Subject: [PATCH 2/2] Update project dependencies --- composer.lock | 71 ++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/composer.lock b/composer.lock index 2dab0840..3d1de818 100644 --- a/composer.lock +++ b/composer.lock @@ -1296,28 +1296,29 @@ }, { "name": "kigkonsult/icalcreator", - "version": "v2.30.5", + "version": "v2.39", "source": { "type": "git", "url": "https://github.com/iCalcreator/iCalcreator.git", - "reference": "e98cf1d28df690ac1029fe10db0d8dabe0d4ff5b" + "reference": "f6bde4e517ac508db6b78d003de71894fde5e718" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/iCalcreator/iCalcreator/zipball/e98cf1d28df690ac1029fe10db0d8dabe0d4ff5b", - "reference": "e98cf1d28df690ac1029fe10db0d8dabe0d4ff5b", + "url": "https://api.github.com/repos/iCalcreator/iCalcreator/zipball/f6bde4e517ac508db6b78d003de71894fde5e718", + "reference": "f6bde4e517ac508db6b78d003de71894fde5e718", "shasum": "" }, "require": { "ext-openssl": "*", "ext-simplexml": "*", "ext-zlib": "*", - "php": ">=5.6" + "php": ">=7.0" }, "require-dev": { - "phpcompatibility/php-compatibility": "9.3.5", - "phpunit/phpunit": "6.5.13", - "squizlabs/php_codesniffer": "3.5.5" + "phpcompatibility/php-compatibility": ">=9.3.5", + "phpstan/phpstan": ">=0.9.3", + "phpunit/phpunit": ">=6.5.13", + "squizlabs/php_codesniffer": ">=3.5.5" }, "type": "library", "autoload": { @@ -1334,7 +1335,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "lgpl-3.0" + "LGPL-3.0-or-later" ], "authors": [ { @@ -1365,7 +1366,7 @@ ], "support": { "issues": "https://github.com/iCalcreator/iCalcreator/issues", - "source": "https://github.com/iCalcreator/iCalcreator/tree/v2.30.5" + "source": "https://github.com/iCalcreator/iCalcreator/tree/v2.39" }, "funding": [ { @@ -1373,7 +1374,7 @@ "type": "other" } ], - "time": "2021-05-12T15:50:20+00:00" + "time": "2021-06-21T10:09:46+00:00" }, { "name": "league/csv", @@ -2280,16 +2281,16 @@ }, { "name": "symfony/asset", - "version": "v5.3.0", + "version": "v5.3.2", "source": { "type": "git", "url": "https://github.com/symfony/asset.git", - "reference": "4c8d354b8931788f2b07953cfe6846e5cda27637" + "reference": "29a4d5e6e39ffe16cea394fd5041d7a638bd580d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/asset/zipball/4c8d354b8931788f2b07953cfe6846e5cda27637", - "reference": "4c8d354b8931788f2b07953cfe6846e5cda27637", + "url": "https://api.github.com/repos/symfony/asset/zipball/29a4d5e6e39ffe16cea394fd5041d7a638bd580d", + "reference": "29a4d5e6e39ffe16cea394fd5041d7a638bd580d", "shasum": "" }, "require": { @@ -2333,7 +2334,7 @@ "description": "Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/asset/tree/v5.3.0" + "source": "https://github.com/symfony/asset/tree/v5.3.2" }, "funding": [ { @@ -2349,7 +2350,7 @@ "type": "tidelift" } ], - "time": "2021-05-26T17:43:10+00:00" + "time": "2021-06-06T08:05:27+00:00" }, { "name": "symfony/cache", @@ -2966,16 +2967,16 @@ }, { "name": "symfony/http-foundation", - "version": "v5.3.1", + "version": "v5.3.2", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "8827b90cf8806e467124ad476acd15216c2fceb6" + "reference": "7b6dd714d95106b831aaa7f3c9c612ab886516bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/8827b90cf8806e467124ad476acd15216c2fceb6", - "reference": "8827b90cf8806e467124ad476acd15216c2fceb6", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/7b6dd714d95106b831aaa7f3c9c612ab886516bd", + "reference": "7b6dd714d95106b831aaa7f3c9c612ab886516bd", "shasum": "" }, "require": { @@ -3019,7 +3020,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v5.3.1" + "source": "https://github.com/symfony/http-foundation/tree/v5.3.2" }, "funding": [ { @@ -3035,7 +3036,7 @@ "type": "tidelift" } ], - "time": "2021-06-02T09:32:00+00:00" + "time": "2021-06-12T10:15:17+00:00" }, { "name": "symfony/inflector", @@ -4313,16 +4314,16 @@ }, { "name": "symfony/string", - "version": "v5.3.0", + "version": "v5.3.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "a9a0f8b6aafc5d2d1c116dcccd1573a95153515b" + "reference": "0732e97e41c0a590f77e231afc16a327375d50b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/a9a0f8b6aafc5d2d1c116dcccd1573a95153515b", - "reference": "a9a0f8b6aafc5d2d1c116dcccd1573a95153515b", + "url": "https://api.github.com/repos/symfony/string/zipball/0732e97e41c0a590f77e231afc16a327375d50b0", + "reference": "0732e97e41c0a590f77e231afc16a327375d50b0", "shasum": "" }, "require": { @@ -4376,7 +4377,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.3.0" + "source": "https://github.com/symfony/string/tree/v5.3.2" }, "funding": [ { @@ -4392,20 +4393,20 @@ "type": "tidelift" } ], - "time": "2021-05-26T17:43:10+00:00" + "time": "2021-06-06T09:51:56+00:00" }, { "name": "symfony/var-exporter", - "version": "v5.3.0", + "version": "v5.3.2", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "7a7c9dd972541f78e7815c03c0bae9f81e0e9dbb" + "reference": "df663fb63bdcd7298373cbd431165ab031706cb2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/7a7c9dd972541f78e7815c03c0bae9f81e0e9dbb", - "reference": "7a7c9dd972541f78e7815c03c0bae9f81e0e9dbb", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/df663fb63bdcd7298373cbd431165ab031706cb2", + "reference": "df663fb63bdcd7298373cbd431165ab031706cb2", "shasum": "" }, "require": { @@ -4449,7 +4450,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v5.3.0" + "source": "https://github.com/symfony/var-exporter/tree/v5.3.2" }, "funding": [ { @@ -4465,7 +4466,7 @@ "type": "tidelift" } ], - "time": "2021-05-26T17:40:38+00:00" + "time": "2021-06-09T10:57:10+00:00" }, { "name": "symfony/web-link",