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)
{
$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);
}
/**
@@ -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();
@@ -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;
}