diff --git a/public/typo3conf/ext/ep_products/Classes/Command/ExportCommandController.php b/public/typo3conf/ext/ep_products/Classes/Command/ExportCommandController.php new file mode 100644 index 00000000..58e08a37 --- /dev/null +++ b/public/typo3conf/ext/ep_products/Classes/Command/ExportCommandController.php @@ -0,0 +1,164 @@ +, dreipunktnull + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +use EP\EpProducts\CsvFormatter\FacebookCatalogCsvFormatter; +use EP\EpProducts\CsvFormatter\GoogleBusinessFeedCsvFormatter; +use EP\EpProducts\Domain\Model\Reseller; +use EP\EpProducts\Domain\Repository\ResellerRepository; +use EP\EpProducts\Service\ResellerDataService; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Serializer\Encoder\XmlEncoder; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; +use Symfony\Component\Serializer\Serializer; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; + +class ExportCommandController extends Command +{ + /** + * @var array + */ + protected static $imageDimensions = [ + 'facebook' => [ + 'width' => '1080', + 'maxHeight' => '1080', + 'cropVariant' => 'facebook', + ], + 'google' => [ + 'width' => '1200', + 'maxHeight' => '1200', + 'cropVariant' => 'google', + ] + ]; + + /** + * @var ResellerRepository + */ + protected $resellerRepository; + + /** + * @var ResellerDataService + */ + protected $resellerDataService; + + public function __construct(string $name = null) + { + parent::__construct($name); + + /** @var ObjectManager $objectManager */ + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $this->resellerRepository = $objectManager->get(ResellerRepository::class); + $this->resellerDataService = $objectManager->get(ResellerDataService::class); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @throws \Doctrine\DBAL\DBALException + */ + public function execute(InputInterface $input, OutputInterface $output) + { + $resellers = $this->resellerRepository->findAll(); + $destinationFolder = sprintf( + '%s/fileadmin/reseller', + \TYPO3\CMS\Core\Core\Environment::getPublicPath() + ); + if (!mkdir($destinationFolder, 0755) && !is_dir($destinationFolder)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $destinationFolder)); + } + foreach ($resellers as $reseller) { + /** @var Reseller $reseller */ + $output->writeln('Exporting XML for ' . $reseller->getName()); + $this->exportXml($reseller, $destinationFolder); + $output->writeln('Exporting CSV (Facebook) for ' . $reseller->getName()); + $this->exportCsv($reseller, 'facebook', $destinationFolder); + $output->writeln('Exporting CSV (Google) for ' . $reseller->getName()); + $this->exportCsv($reseller, 'google', $destinationFolder); + } + } + + /** + * @param Reseller $reseller + * @param string $destinationFolder + * @throws \Doctrine\DBAL\DBALException + */ + protected function exportXml(Reseller $reseller, $destinationFolder) + { + $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' => false ] + ); + $filename = sprintf( + '%s/export_%s.xml', + $destinationFolder, + $reseller->getCode() + ); + @unlink($filename); + file_put_contents($filename, $xml); + } + + /** + * @param Reseller $reseller + * @param string $type + * @param string $destinationFolder + * @throws \Doctrine\DBAL\DBALException + */ + protected function exportCsv(Reseller $reseller, $type, $destinationFolder) + { + $data = $this->resellerDataService->preprocessAll( + $reseller, + static::$imageDimensions[$type], + $type + ); + if ($type === 'google') { + $csv = GoogleBusinessFeedCsvFormatter::format($data); + } else { + $csv = FacebookCatalogCsvFormatter::format($data); + } + $filename = sprintf( + '%s/export_%s_%s.csv', + $destinationFolder, + $reseller->getCode(), + $type + ); + @unlink($filename); + $fileHandle = fopen($filename, 'wb'); + foreach ($csv as $row) { + fputcsv($fileHandle, $row); + } + fclose($fileHandle); + } +} diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php index adef05fb..6f42df06 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php @@ -27,59 +27,26 @@ namespace EP\EpProducts\Controller; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use EP\EpProducts\CsvFormatter\FacebookCatalogCsvFormatter; -use EP\EpProducts\CsvFormatter\GoogleBusinessFeedCsvFormatter; use EP\EpProducts\Domain\Model\Product; use EP\EpProducts\Domain\Model\Reseller; 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; class ResellerController extends ActionController { - /** - * @var array - */ - protected static $imageDimensions = [ - 'facebook' => [ - 'width' => '1080', - 'maxHeight' => '1080', - 'cropVariant' => 'facebook', - ], - 'google' => [ - 'width' => '1200', - 'maxHeight' => '1200', - 'cropVariant' => 'google', - ] - ]; - /** * @var ResellerDataService */ 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'); } /** @@ -100,7 +67,7 @@ class ResellerController extends ActionController /** * @param Reseller $reseller * @param Product $product - + * @throws \Doctrine\DBAL\DBALException * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException */ @@ -115,97 +82,9 @@ class ResellerController extends ActionController ); } - $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); - } + $productData = $this->resellerDataService->preprocessSingle($product, $reseller); $this->view->assign('reseller', $reseller); $this->view->assign('productData', $productData); } - - /** - * @param Reseller $reseller - * @return void - * @throws \Doctrine\DBAL\DBALException - */ - public function xmlAction(Reseller $reseller) - { - $cacheKey = sprintf('reseller_export_xml_full_%d', $reseller->getUid()); - 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' => false ] - ); - $this->cache->set($cacheKey, $xml, [], 3600); - } - - $filename = sprintf('export_%s_%s.xml', $reseller->getCode(), date('Y-m-d')); - - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Content-Description: File Transfer'); - header('Content-type: text/xml'); - header('Content-Disposition: attachment; filename=' . $filename); - header('Expires: 0'); - header('Pragma: public'); - - echo $xml; - - exit(); - } - - /** - * @param Reseller $reseller - * @param string $type - * @throws \Doctrine\DBAL\DBALException - * @throws InvalidArgumentValueException - */ - public function csvAction(Reseller $reseller, $type = 'facebook') - { - if (!array_key_exists($type, static::$imageDimensions)) { - throw new InvalidArgumentValueException(); - } - - $cacheKey = sprintf('reseller_export_csv_%s_%d', $type, $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')); - - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Content-Description: File Transfer'); - header('Content-type: text/csv'); - header('Content-Disposition: attachment; filename=' . $filename); - header('Expires: 0'); - header('Pragma: public'); - - $fileHandle = fopen('php://output', 'wb'); - - foreach ($csv as $row) { - fputcsv($fileHandle, $row); - } - - fclose($fileHandle); - - exit(); - } - } diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Reseller.php b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Reseller.php index fdb9efbf..7fbc41d8 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Reseller.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Reseller.php @@ -2,6 +2,7 @@ namespace EP\EpProducts\Domain\Model; +use TYPO3\CMS\Extbase\Annotation\ORM\Lazy; use TYPO3\CMS\Extbase\Persistence\ObjectStorage; /*************************************************************** @@ -49,6 +50,7 @@ class Reseller extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EP\EpProducts\Domain\Model\Product> + * @Lazy() */ protected $products; diff --git a/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php b/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php index 74a74015..2d5e970e 100644 --- a/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php +++ b/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php @@ -68,10 +68,13 @@ class SerializationUtility foreach ($images as $file) { $image = $file->getOriginalResource(); - if (!\is_array($processingInstructions)) { + if (TYPO3_MODE === 'BE') { + $hostname = 'www.ep-reisen.de'; + } else { $hostname = GeneralUtility::getIndpEnv('HTTP_HOST'); - - $data[] = 'https://' . $hostname . '/' . $image->getOriginalFile()->getPublicUrl(); + } + if (!\is_array($processingInstructions)) { + $imageUrl = $image->getOriginalFile()->getPublicUrl(); } else { $imageService = static::getImageService(); $cropString = $image->getProperty('crop'); @@ -80,8 +83,9 @@ class SerializationUtility $cropArea = $cropVariantCollection->getCropArea($cropVariant); $processingInstructions['crop'] = $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image); $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); - $data[] = $imageService->getImageUri($processedImage, true); + $imageUrl = $processedImage->getPublicUrl(); } + $data[] = sprintf('https://%s/%s', $hostname, $imageUrl); } return $data; diff --git a/public/typo3conf/ext/ep_products/Configuration/Commands.php b/public/typo3conf/ext/ep_products/Configuration/Commands.php new file mode 100644 index 00000000..81b68e78 --- /dev/null +++ b/public/typo3conf/ext/ep_products/Configuration/Commands.php @@ -0,0 +1,7 @@ + [ + 'class' => \EP\EpProducts\Command\ExportCommandController::class, + ], +]; diff --git a/public/typo3conf/ext/ep_products/ext_localconf.php b/public/typo3conf/ext/ep_products/ext_localconf.php index 305b561e..384126c2 100644 --- a/public/typo3conf/ext/ep_products/ext_localconf.php +++ b/public/typo3conf/ext/ep_products/ext_localconf.php @@ -293,10 +293,10 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\EP\EpProducts\T 'EP.' . $_EXTKEY, 'reseller', [ - 'Reseller' => 'list,xml,copypaste,csv', + 'Reseller' => 'list,copypaste', ], [ - 'Reseller' => 'list,xml,copypaste,csv', + 'Reseller' => 'list,copypaste', ] ); @@ -370,11 +370,3 @@ $GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpProducts']['Controller']['writerConf ]; $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; -} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Reseller/List.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Reseller/List.html index 95e32d83..25e4debb 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Reseller/List.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Reseller/List.html @@ -11,11 +11,17 @@

{reseller.name}

Gesamtexport XML

- Export XML + + Export XML +

Gesamtexport CSV (Facebook)

- Export CSV + + Export CSV (Google) +

Gesamtexport CSV (Google)

- Export CSV + + Export CSV (Facebook) +

Einzelexport für Copy&Paste