Merge branch 'develop' into feature/stimulus
This commit is contained in:
@@ -66,8 +66,7 @@ class ContingentCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
public function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexportzimmer');
|
$count = $this->contingentImportService->import();
|
||||||
$count = $this->contingentImportService->import($path);
|
|
||||||
$output->writeln(sprintf('%d rows imported.', $count ));
|
$output->writeln(sprintf('%d rows imported.', $count ));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
|
|||||||
use LoggerAwareTrait;
|
use LoggerAwareTrait;
|
||||||
use DbConnectionTrait;
|
use DbConnectionTrait;
|
||||||
|
|
||||||
const ROOMCODE_STATUS = 'BelKal';
|
public const XML_PATH = 'fileadmin/xmlexportzimmer';
|
||||||
|
public const ROOMCODE_STATUS = 'BelKal';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
@@ -83,15 +84,14 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
|
||||||
* @return int
|
* @return int
|
||||||
* @throws \Doctrine\DBAL\DBALException
|
* @throws \Doctrine\DBAL\DBALException
|
||||||
*/
|
*/
|
||||||
public function import($path)
|
public function import()
|
||||||
{
|
{
|
||||||
$this->createTempTable();
|
$this->createTempTable();
|
||||||
$this->logger->info('starting product import');
|
$this->logger->info('starting product import');
|
||||||
$contingentCount = $this->parseXmlFilesInFolder($path);
|
$contingentCount = $this->parseXmlFilesInFolder();
|
||||||
$this->clearTable();
|
$this->clearTable();
|
||||||
$this->copyTable();
|
$this->copyTable();
|
||||||
$this->clearTempTable();
|
$this->clearTempTable();
|
||||||
@@ -109,35 +109,47 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function parseXmlFilesInFolder($path)
|
public function parseXmlFilesInFolder()
|
||||||
{
|
{
|
||||||
$dateCount = 0;
|
$dateCount = 0;
|
||||||
|
$path = GeneralUtility::getFileAbsFileName(self::XML_PATH);
|
||||||
$folder = opendir($path);
|
$folder = opendir($path);
|
||||||
while (($fileName = readdir($folder)) !== false) {
|
while (($fileName = readdir($folder)) !== false) {
|
||||||
if (strpos($fileName, 'HotelZimmer') === 0) {
|
if (strpos($fileName, 'HotelZimmer') === 0) {
|
||||||
$filePath = $path . '/' . $fileName;
|
$dateCount += $this->parseContingentXmlFile($path, $fileName);
|
||||||
$dateCount += $this->parseContingentXmlFile($filePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dateCount;
|
return $dateCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $file
|
* @param string $fileName
|
||||||
* @return int
|
* @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);
|
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();
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
return $this->parseContingent($xmlData);
|
|
||||||
|
return $xmlData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,9 +191,9 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
|
|||||||
protected function parseContingent(\SimpleXMLElement $xmlContingent)
|
protected function parseContingent(\SimpleXMLElement $xmlContingent)
|
||||||
{
|
{
|
||||||
$hotelCode = (string) $xmlContingent['code'];
|
$hotelCode = (string) $xmlContingent['code'];
|
||||||
$sql = 'SELECT h.uid uid
|
$sql = 'SELECT h.uid uid
|
||||||
FROM tx_epproducts_domain_model_hotel h
|
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)
|
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
|
WHERE h.deleted = 0 AND h.hidden = 0 AND h.code = :code OR m.code = :code
|
||||||
LIMIT 0,1';
|
LIMIT 0,1';
|
||||||
$hotelData = $this->db->fetchAssoc($sql, ['code' => $hotelCode]);
|
$hotelData = $this->db->fetchAssoc($sql, ['code' => $hotelCode]);
|
||||||
@@ -192,14 +204,22 @@ class ContingentImportService implements SingletonInterface, LoggerAwareInterfac
|
|||||||
return 0;
|
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)) {
|
if (empty($xmlContingent->kapazitaeten)) {
|
||||||
$this->logger->warning('hotel has no contingents', ['code' => $hotelCode]);
|
$this->logger->warning('hotel has no contingents', ['code' => $hotelCode]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hotelData['busProId'] = (string) $xmlContingent['idbuspro'];
|
|
||||||
$hotelData['code'] = $hotelCode;
|
|
||||||
$roomTypes = $this->parseRoomTypes($xmlContingent->unterbringungen);
|
$roomTypes = $this->parseRoomTypes($xmlContingent->unterbringungen);
|
||||||
|
|
||||||
return $this->parseRooms($xmlContingent->kapazitaeten, $hotelData, $roomTypes);
|
return $this->parseRooms($xmlContingent->kapazitaeten, $hotelData, $roomTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ class ImportContingentsTask extends AbstractTask
|
|||||||
/** @var \EP\EpProducts\Service\ContingentImportService $importService */
|
/** @var \EP\EpProducts\Service\ContingentImportService $importService */
|
||||||
$importService = $objectManager->get(ContingentImportService::class);
|
$importService = $objectManager->get(ContingentImportService::class);
|
||||||
if ($importService->isImportRequired()) {
|
if ($importService->isImportRequired()) {
|
||||||
$path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexportzimmer');
|
$importService->import();
|
||||||
$importService->import($path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user