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++; } } }