From f66a51b911fa937a2789d46f47b861e0f009a62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Tue, 2 Oct 2018 18:38:37 +0200 Subject: [PATCH] Reduce redundant data when importing daytrips --- .../Classes/Service/DateImportService.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/web/typo3conf/ext/ep_products/Classes/Service/DateImportService.php b/web/typo3conf/ext/ep_products/Classes/Service/DateImportService.php index bf65a612..61569e75 100644 --- a/web/typo3conf/ext/ep_products/Classes/Service/DateImportService.php +++ b/web/typo3conf/ext/ep_products/Classes/Service/DateImportService.php @@ -88,6 +88,13 @@ class DateImportService implements SingletonInterface */ protected $cacheService; + /** + * @var array + */ + static protected $cache = [ + 'datesAdded' => [], + ]; + /** * @param ConfigurationManagerInterface $configurationManager * @param CacheService $cacheService @@ -272,7 +279,16 @@ class DateImportService implements SingletonInterface $dateCount = 0; foreach ($xmlDate->hotel as $xmlHotel) { + $hotelCode = (string) $xmlHotel->attributes()['code']; $date = $this->createDateRecord($product, $xmlDate); + $key = $hotelCode . $date['date_start']; + + // Import daytrip dates only once per hotel as room information is taken + // from contingents + if ($product['daytrip'] && \in_array($key, static::$cache['datesAdded'], true)) { + continue; + } + if ($this->parseHotel($xmlHotel, $date) !== false) { $this->db->insert( 'tx_epproducts_domain_model_date_temp', @@ -286,6 +302,8 @@ class DateImportService implements SingletonInterface ); $dateCount++; } + + static::$cache['datesAdded'][] = $key; } $this->db->update( 'tx_epproducts_domain_model_product',