Merge branch 'develop' into feature/stimulus

This commit is contained in:
Björn Fromme
2021-08-23 16:13:25 +02:00
3 changed files with 39 additions and 21 deletions
@@ -66,8 +66,7 @@ class ContingentCommand extends Command
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexportzimmer');
$count = $this->contingentImportService->import($path);
$count = $this->contingentImportService->import();
$output->writeln(sprintf('%d rows imported.', $count ));
return 0;
@@ -41,7 +41,8 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
use LoggerAwareTrait;
use DbConnectionTrait;
const ROOMCODE_STATUS = 'BelKal';
public const XML_PATH = 'fileadmin/xmlexportzimmer';
public const ROOMCODE_STATUS = 'BelKal';
/**
* @var string[]
@@ -83,15 +84,14 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
}
/**
* @param string $path
* @return int
* @throws \Doctrine\DBAL\DBALException
*/
public function import($path)
public function import()
{
$this->createTempTable();
$this->logger->info('starting product import');
$contingentCount = $this->parseXmlFilesInFolder($path);
$contingentCount = $this->parseXmlFilesInFolder();
$this->clearTable();
$this->copyTable();
$this->clearTempTable();
@@ -109,35 +109,47 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
}
/**
* @param string $path
* @return int
*/
public function parseXmlFilesInFolder($path)
public function parseXmlFilesInFolder()
{
$dateCount = 0;
$path = GeneralUtility::getFileAbsFileName(self::XML_PATH);
$folder = opendir($path);
while (($fileName = readdir($folder)) !== false) {
if (strpos($fileName, 'HotelZimmer') === 0) {
$filePath = $path . '/' . $fileName;
$dateCount += $this->parseContingentXmlFile($filePath);
$dateCount += $this->parseContingentXmlFile($path, $fileName);
}
}
return $dateCount;
}
/**
* @param string $file
* @param string $fileName
* @return int
*/
public function parseContingentXmlFile($file)
public function parseContingentXmlFile($path, $fileName)
{
$filePath = sprintf('%s/%s', $path , $fileName);
if (null === $xmlData = $this->loadXmlFile($filePath)) {
return 0;
}
return $this->parseContingent($xmlData);
}
public function loadXmlFile($file): ?\SimpleXMLElement
{
libxml_use_internal_errors (true);
/** @var \SimpleXMLElement $xmlData */
if (!$xmlData = simplexml_load_string(file_get_contents($file))) {
libxml_clear_errors();
return 0;
return null;
}
return $this->parseContingent($xmlData);
return $xmlData;
}
/**
@@ -179,9 +191,9 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
protected function parseContingent(\SimpleXMLElement $xmlContingent)
{
$hotelCode = (string) $xmlContingent['code'];
$sql = 'SELECT h.uid uid
FROM tx_epproducts_domain_model_hotel h
LEFT JOIN tx_epproducts_domain_model_matchcode m ON (h.uid = m.entity AND m.entity_type = "hotel" AND m.deleted = 0)
$sql = 'SELECT h.uid uid
FROM tx_epproducts_domain_model_hotel h
LEFT JOIN tx_epproducts_domain_model_matchcode m ON (h.uid = m.entity AND m.entity_type = "hotel" AND m.deleted = 0)
WHERE h.deleted = 0 AND h.hidden = 0 AND h.code = :code OR m.code = :code
LIMIT 0,1';
$hotelData = $this->db->fetchAssoc($sql, ['code' => $hotelCode]);
@@ -192,14 +204,22 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
return 0;
}
$hotelData['busProId'] = (string) $xmlContingent['idbuspro'];
$hotelData['code'] = (string) $xmlContingent['code'];
if ($xmlContingent->idbuspro_kontingent_aus) {
$linkedProductId = (int)$xmlContingent->idbuspro_kontingent_aus;
$path = GeneralUtility::getFileAbsFileName(self::XML_PATH);
$xmlContingent = $this->loadXmlFile(sprintf('%s/HotelZimmer_%d.xml', $path, $linkedProductId));
}
if (empty($xmlContingent->kapazitaeten)) {
$this->logger->warning('hotel has no contingents', ['code' => $hotelCode]);
return 0;
}
$hotelData['busProId'] = (string) $xmlContingent['idbuspro'];
$hotelData['code'] = $hotelCode;
$roomTypes = $this->parseRoomTypes($xmlContingent->unterbringungen);
return $this->parseRooms($xmlContingent->kapazitaeten, $hotelData, $roomTypes);
}
@@ -41,8 +41,7 @@ class ImportContingentsTask extends AbstractTask
/** @var \EP\EpProducts\Service\ContingentImportService $importService */
$importService = $objectManager->get(ContingentImportService::class);
if ($importService->isImportRequired()) {
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexportzimmer');
$importService->import($path);
$importService->import();
}
return true;