From 900aa785c13dd485ad9ecd153c9ab66cc661ea16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 10 Jul 2020 15:39:28 +0200 Subject: [PATCH] Adjust date import to changes in xml upload --- .../Classes/Command/DateCommandController.php | 14 +++--- .../Classes/Service/DateImportService.php | 43 +++++++++++++------ .../Classes/Task/ImportDatesTask.php | 8 ---- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php b/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php index aae1efdb..89b930db 100644 --- a/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php +++ b/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php @@ -80,15 +80,11 @@ class DateCommandController extends Command public function execute(InputInterface $input, OutputInterface $output) { $path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'); - if ($this->dateImportService->checkActiveUpload($path)) { - $output->writeln('Import cancelled due to active file upload.'); - } else { - $count = $this->dateImportService->import($path); - $output->writeln(sprintf('%d rows imported.', $count )); - $settings = $this->getSettings(); - $resellerPageUid = $settings['resellerExportPageUid']; - $this->cacheService->clearPageCache($resellerPageUid); - } + $count = $this->dateImportService->import($path); + $output->writeln(sprintf('%d rows imported.', $count )); + $settings = $this->getSettings(); + $resellerPageUid = $settings['resellerExportPageUid']; + $this->cacheService->clearPageCache($resellerPageUid); } /** diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php index 1978cbd3..0f99a3b9 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateImportService.php @@ -125,7 +125,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface $this->importPickups(); $this->createTempTables(); $this->logger->info('starting product import'); - $dateCount = $this->parseXmlFilesInFolder($path); + $dateCount = $this->parseXmlFilesForProducts($path); $this->clearTables(); $this->copyTables(); $this->clearTempTables(); @@ -144,20 +144,30 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface return count(glob($tempFile)) > 0; } - /** - * @param string $path - * @return int - */ - public function parseXmlFilesInFolder($path) + public function parseXmlFilesForProducts($path) { - $dateCount = 0; - $folder = opendir($path); - while (($fileName = readdir($folder)) !== false) { - if (strpos($fileName, 'Ziel') === 0) { - $filePath = $path . '/' . $fileName; - $dateCount += $this->parseProductXmlFile($filePath); - } + $xmlPath = sprintf('%s/Produkte.xml', $path); + + if (!file_exists($xmlPath)) { + $this->logger->error('product list xml not found'); + return 0; } + + libxml_use_internal_errors(true); + /** @var \SimpleXMLElement $xmlData */ + if (!$xmlData = simplexml_load_string(file_get_contents($xmlPath))) { + libxml_clear_errors(); + return 0; + } + + $dateCount = 0; + + foreach ($xmlData->produkte[0]->children() as $xmlProdukt) { + $busProId = (int)$xmlProdukt->attributes()['id']; + $xmlFile = sprintf('%s/Ziel_%d.xml', $path, $busProId); + $dateCount += $this->parseProductXmlFile($xmlFile); + } + return $dateCount; } @@ -167,7 +177,12 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface */ public function parseProductXmlFile($file) { - libxml_use_internal_errors (true); + if (!file_exists($file)) { + $this->logger->error('product xml not found', ['file' => $file]); + return 0; + } + + libxml_use_internal_errors(true); /** @var \SimpleXMLElement $xmlData */ if (!$xmlData = simplexml_load_string(file_get_contents($file))) { libxml_clear_errors(); diff --git a/public/typo3conf/ext/ep_products/Classes/Task/ImportDatesTask.php b/public/typo3conf/ext/ep_products/Classes/Task/ImportDatesTask.php index 4012193b..ee2c21c2 100644 --- a/public/typo3conf/ext/ep_products/Classes/Task/ImportDatesTask.php +++ b/public/typo3conf/ext/ep_products/Classes/Task/ImportDatesTask.php @@ -28,7 +28,6 @@ namespace EP\EpProducts\Task; ***************************************************************/ use EP\EpProducts\Service\DateImportService; -use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Scheduler\Task\AbstractTask; @@ -42,13 +41,6 @@ class ImportDatesTask extends AbstractTask /** @var \EP\EpProducts\Service\DateImportService $importService */ $importService = $objectManager->get(DateImportService::class); $path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'); - if ($importService->checkActiveUpload($path)) { - $message = GeneralUtility::makeInstance(FlashMessage::class, 'Import aborted due to active file upload', '', FlashMessage::WARNING); - $flashMessageService = $objectManager->get(\TYPO3\CMS\Core\Messaging\FlashMessageService::class); - $messageQueue = $flashMessageService->getMessageQueueByIdentifier(); - $messageQueue->addMessage($message); - return false; - } $importService->import($path); return true; }