Implement cache for reseller data exports
This commit is contained in:
@@ -35,6 +35,8 @@ use EP\EpProducts\Service\ResellerDataService;
|
|||||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||||
use Symfony\Component\Serializer\Serializer;
|
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\Controller\ActionController;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException;
|
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException;
|
||||||
|
|
||||||
@@ -61,13 +63,23 @@ class ResellerController extends ActionController
|
|||||||
*/
|
*/
|
||||||
protected $resellerDataService;
|
protected $resellerDataService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
|
||||||
|
*/
|
||||||
|
protected $cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ResellerDataService $resellerDataService
|
* @param ResellerDataService $resellerDataService
|
||||||
|
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
||||||
*/
|
*/
|
||||||
public function __construct(ResellerDataService $resellerDataService)
|
public function __construct(ResellerDataService $resellerDataService)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->resellerDataService = $resellerDataService;
|
$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('reseller', $reseller);
|
||||||
$this->view->assign('productData', $productData);
|
$this->view->assign('productData', $productData);
|
||||||
@@ -111,16 +127,25 @@ class ResellerController extends ActionController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Reseller $reseller
|
* @param Reseller $reseller
|
||||||
* @return bool
|
* @return void
|
||||||
|
* @throws \Doctrine\DBAL\DBALException
|
||||||
*/
|
*/
|
||||||
public function xmlAction(Reseller $reseller)
|
public function xmlAction(Reseller $reseller)
|
||||||
{
|
{
|
||||||
$data = $this->resellerDataService->preprocessAll($reseller);
|
$cacheKey = sprintf('reseller_export_xml_full_%d', $reseller->getUid());
|
||||||
|
|
||||||
$encoders = [new XmlEncoder('products')];
|
if (($xml = $this->cache->get($cacheKey)) === false) {
|
||||||
$normalizers = [new ObjectNormalizer()];
|
$data = $this->resellerDataService->preprocessAll($reseller);
|
||||||
|
$encoders = [new XmlEncoder('products')];
|
||||||
$serializer = new Serializer($normalizers, $encoders);
|
$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'));
|
$filename = sprintf('export_%s_%s.xml', $reseller->getCode(), date('Y-m-d'));
|
||||||
|
|
||||||
@@ -131,11 +156,7 @@ class ResellerController extends ActionController
|
|||||||
header('Expires: 0');
|
header('Expires: 0');
|
||||||
header('Pragma: public');
|
header('Pragma: public');
|
||||||
|
|
||||||
echo $serializer->serialize(
|
echo $xml;
|
||||||
$data,
|
|
||||||
'xml',
|
|
||||||
[ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ]
|
|
||||||
);
|
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@@ -152,11 +173,21 @@ class ResellerController extends ActionController
|
|||||||
throw new InvalidArgumentValueException();
|
throw new InvalidArgumentValueException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->resellerDataService->preprocessAll(
|
$cacheKey = sprintf('reseller_export_csv_full_%d', $reseller->getUid());
|
||||||
$reseller,
|
|
||||||
static::$imageDimensions[$type],
|
if (($csv = $this->cache->get($cacheKey)) === false) {
|
||||||
$type
|
$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'));
|
$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');
|
$fileHandle = fopen('php://output', 'wb');
|
||||||
|
|
||||||
if ($type === 'google') {
|
|
||||||
$csv = GoogleBusinessFeedCsvFormatter::format($data);
|
|
||||||
} else {
|
|
||||||
$csv = FacebookCatalogCsvFormatter::format($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($csv as $row) {
|
foreach ($csv as $row) {
|
||||||
fputcsv($fileHandle, $row);
|
fputcsv($fileHandle, $row);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (!defined('TYPO3_MODE')) {
|
if (!defined('TYPO3_MODE')) {
|
||||||
die('Access denied.');
|
die('Access denied.');
|
||||||
}
|
}
|
||||||
@@ -369,3 +370,11 @@ $GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpProducts']['Controller']['writerConf
|
|||||||
];
|
];
|
||||||
|
|
||||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['teamSlug'] = \EP\EpProducts\Updates\TeamSlugUpdater::class;
|
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['teamSlug'] = \EP\EpProducts\Updates\TeamSlugUpdater::class;
|
||||||
|
|
||||||
|
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['ep_products_reseller'])) {
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['ep_products_reseller'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['ep_products_reseller']['backend'])) {
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['ep_products_reseller']['backend'] = \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user