Adjust date import to changes in xml upload
This commit is contained in:
@@ -80,16 +80,12 @@ 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)) {
|
|
||||||
$output->writeln('Import cancelled due to active file upload.');
|
|
||||||
} else {
|
|
||||||
$count = $this->dateImportService->import($path);
|
$count = $this->dateImportService->import($path);
|
||||||
$output->writeln(sprintf('%d rows imported.', $count ));
|
$output->writeln(sprintf('%d rows imported.', $count ));
|
||||||
$settings = $this->getSettings();
|
$settings = $this->getSettings();
|
||||||
$resellerPageUid = $settings['resellerExportPageUid'];
|
$resellerPageUid = $settings['resellerExportPageUid'];
|
||||||
$this->cacheService->clearPageCache($resellerPageUid);
|
$this->cacheService->clearPageCache($resellerPageUid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
|||||||
@@ -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)
|
|
||||||
{
|
{
|
||||||
|
$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;
|
$dateCount = 0;
|
||||||
$folder = opendir($path);
|
|
||||||
while (($fileName = readdir($folder)) !== false) {
|
foreach ($xmlData->produkte[0]->children() as $xmlProdukt) {
|
||||||
if (strpos($fileName, 'Ziel') === 0) {
|
$busProId = (int)$xmlProdukt->attributes()['id'];
|
||||||
$filePath = $path . '/' . $fileName;
|
$xmlFile = sprintf('%s/Ziel_%d.xml', $path, $busProId);
|
||||||
$dateCount += $this->parseProductXmlFile($filePath);
|
$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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user