Adjust date import to changes in xml upload

This commit is contained in:
Björn Fromme
2020-07-10 15:39:28 +02:00
parent ca2dd2ed78
commit 900aa785c1
3 changed files with 34 additions and 31 deletions
@@ -80,15 +80,11 @@ class DateCommandController extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'); $path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport');
if ($this->dateImportService->checkActiveUpload($path)) { $count = $this->dateImportService->import($path);
$output->writeln('Import cancelled due to active file upload.'); $output->writeln(sprintf('%d rows imported.', $count ));
} else { $settings = $this->getSettings();
$count = $this->dateImportService->import($path); $resellerPageUid = $settings['resellerExportPageUid'];
$output->writeln(sprintf('%d rows imported.', $count )); $this->cacheService->clearPageCache($resellerPageUid);
$settings = $this->getSettings();
$resellerPageUid = $settings['resellerExportPageUid'];
$this->cacheService->clearPageCache($resellerPageUid);
}
} }
/** /**
@@ -125,7 +125,7 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface
$this->importPickups(); $this->importPickups();
$this->createTempTables(); $this->createTempTables();
$this->logger->info('starting product import'); $this->logger->info('starting product import');
$dateCount = $this->parseXmlFilesInFolder($path); $dateCount = $this->parseXmlFilesForProducts($path);
$this->clearTables(); $this->clearTables();
$this->copyTables(); $this->copyTables();
$this->clearTempTables(); $this->clearTempTables();
@@ -144,20 +144,30 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface
return count(glob($tempFile)) > 0; return count(glob($tempFile)) > 0;
} }
/** public function parseXmlFilesForProducts($path)
* @param string $path
* @return int
*/
public function parseXmlFilesInFolder($path)
{ {
$dateCount = 0; $xmlPath = sprintf('%s/Produkte.xml', $path);
$folder = opendir($path);
while (($fileName = readdir($folder)) !== false) { if (!file_exists($xmlPath)) {
if (strpos($fileName, 'Ziel') === 0) { $this->logger->error('product list xml not found');
$filePath = $path . '/' . $fileName; return 0;
$dateCount += $this->parseProductXmlFile($filePath);
}
} }
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; return $dateCount;
} }
@@ -167,7 +177,12 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface
*/ */
public function parseProductXmlFile($file) 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 */ /** @var \SimpleXMLElement $xmlData */
if (!$xmlData = simplexml_load_string(file_get_contents($file))) { if (!$xmlData = simplexml_load_string(file_get_contents($file))) {
libxml_clear_errors(); libxml_clear_errors();
@@ -28,7 +28,6 @@ namespace EP\EpProducts\Task;
***************************************************************/ ***************************************************************/
use EP\EpProducts\Service\DateImportService; use EP\EpProducts\Service\DateImportService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Scheduler\Task\AbstractTask; use TYPO3\CMS\Scheduler\Task\AbstractTask;
@@ -42,13 +41,6 @@ class ImportDatesTask extends AbstractTask
/** @var \EP\EpProducts\Service\DateImportService $importService */ /** @var \EP\EpProducts\Service\DateImportService $importService */
$importService = $objectManager->get(DateImportService::class); $importService = $objectManager->get(DateImportService::class);
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'); $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); $importService->import($path);
return true; return true;
} }