diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php index f9da37ae..ca83c0f6 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php @@ -35,6 +35,8 @@ use EP\EpProducts\Service\ResellerDataService; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException; @@ -61,13 +63,23 @@ class ResellerController extends ActionController */ protected $resellerDataService; + /** + * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface + */ + protected $cache; + /** * @param ResellerDataService $resellerDataService + * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException */ public function __construct(ResellerDataService $resellerDataService) { parent::__construct(); + $this->resellerDataService = $resellerDataService; + /** @var CacheManager $cacheManager */ + $cacheManager = GeneralUtility::makeInstance(CacheManager::class); + $this->cache = $cacheManager->getCache('ep_products_reseller'); } /** @@ -103,7 +115,11 @@ class ResellerController extends ActionController ); } - $productData = $this->resellerDataService->preprocessSingle($product, $reseller); + $cacheKey = sprintf('reseller_export_cp_%d_%d', $product->getUid(), $reseller->getUid()); + if (($productData = $this->cache->get($cacheKey)) === false) { + $productData = $this->resellerDataService->preprocessSingle($product, $reseller); + $this->cache->set($cacheKey, $productData, [], 3600); + } $this->view->assign('reseller', $reseller); $this->view->assign('productData', $productData); @@ -111,16 +127,25 @@ class ResellerController extends ActionController /** * @param Reseller $reseller - * @return bool + * @return void + * @throws \Doctrine\DBAL\DBALException */ public function xmlAction(Reseller $reseller) { - $data = $this->resellerDataService->preprocessAll($reseller); + $cacheKey = sprintf('reseller_export_xml_full_%d', $reseller->getUid()); - $encoders = [new XmlEncoder('products')]; - $normalizers = [new ObjectNormalizer()]; - - $serializer = new Serializer($normalizers, $encoders); + if (($xml = $this->cache->get($cacheKey)) === false) { + $data = $this->resellerDataService->preprocessAll($reseller); + $encoders = [new XmlEncoder('products')]; + $normalizers = [new ObjectNormalizer()]; + $serializer = new Serializer($normalizers, $encoders); + $xml = $serializer->serialize( + $data, + 'xml', + [ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ] + ); + $this->cache->set($cacheKey, $xml, [], 3600); + } $filename = sprintf('export_%s_%s.xml', $reseller->getCode(), date('Y-m-d')); @@ -131,11 +156,7 @@ class ResellerController extends ActionController header('Expires: 0'); header('Pragma: public'); - echo $serializer->serialize( - $data, - 'xml', - [ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ] - ); + echo $xml; exit(); } @@ -152,11 +173,21 @@ class ResellerController extends ActionController throw new InvalidArgumentValueException(); } - $data = $this->resellerDataService->preprocessAll( - $reseller, - static::$imageDimensions[$type], - $type - ); + $cacheKey = sprintf('reseller_export_csv_full_%d', $reseller->getUid()); + + if (($csv = $this->cache->get($cacheKey)) === false) { + $data = $this->resellerDataService->preprocessAll( + $reseller, + static::$imageDimensions[$type], + $type + ); + if ($type === 'google') { + $csv = GoogleBusinessFeedCsvFormatter::format($data); + } else { + $csv = FacebookCatalogCsvFormatter::format($data); + } + $this->cache->set($cacheKey, $csv, [], 3600); + } $filename = sprintf('export_%s_%s.csv', $reseller->getCode(), date('Y-m-d')); @@ -169,12 +200,6 @@ class ResellerController extends ActionController $fileHandle = fopen('php://output', 'wb'); - if ($type === 'google') { - $csv = GoogleBusinessFeedCsvFormatter::format($data); - } else { - $csv = FacebookCatalogCsvFormatter::format($data); - } - foreach ($csv as $row) { fputcsv($fileHandle, $row); } diff --git a/public/typo3conf/ext/ep_products/ext_localconf.php b/public/typo3conf/ext/ep_products/ext_localconf.php index 8c2fc6e0..305b561e 100644 --- a/public/typo3conf/ext/ep_products/ext_localconf.php +++ b/public/typo3conf/ext/ep_products/ext_localconf.php @@ -1,4 +1,5 @@