2019-08-12 07:43:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wrm\Events\Service;
|
|
|
|
|
2022-12-21 13:16:20 +01:00
|
|
|
use Exception;
|
2023-08-10 14:20:37 +02:00
|
|
|
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
|
2021-12-14 16:59:12 +01:00
|
|
|
use TYPO3\CMS\Core\Log\Logger;
|
2021-12-16 09:11:45 +01:00
|
|
|
use TYPO3\CMS\Core\Log\LogManager;
|
2019-08-12 07:43:37 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
2021-01-07 08:58:03 +01:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
|
2023-06-19 10:13:26 +02:00
|
|
|
use Wrm\Events\Caching\CacheManager;
|
2021-01-07 08:58:03 +01:00
|
|
|
use Wrm\Events\Domain\Model\Event;
|
2022-01-27 14:14:02 +01:00
|
|
|
use Wrm\Events\Domain\Model\Import;
|
2021-01-07 08:58:03 +01:00
|
|
|
use Wrm\Events\Domain\Model\Organizer;
|
2021-12-14 16:22:29 +01:00
|
|
|
use Wrm\Events\Domain\Model\Region;
|
2019-08-12 07:43:37 +02:00
|
|
|
use Wrm\Events\Domain\Repository\DateRepository;
|
|
|
|
use Wrm\Events\Domain\Repository\EventRepository;
|
|
|
|
use Wrm\Events\Domain\Repository\OrganizerRepository;
|
2022-07-05 14:08:14 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\CategoriesAssignment;
|
|
|
|
use Wrm\Events\Service\DestinationDataImportService\CategoriesAssignment\Import as CategoryImport;
|
2021-12-15 12:28:06 +01:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DataFetcher;
|
2023-11-06 08:44:03 +01:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DataHandler;
|
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DataHandler\Assignment;
|
2022-04-21 08:07:25 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DatesFactory;
|
2023-08-14 12:09:28 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\Events\CategoriesAssignEvent;
|
2023-08-10 14:20:37 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\Events\EventImportEvent;
|
2023-06-12 11:07:52 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\FilesAssignment;
|
2022-08-02 15:56:18 +02:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\LocationAssignment;
|
2022-11-23 10:59:55 +01:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\Slugger;
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-01-07 08:50:43 +01:00
|
|
|
class DestinationDataImportService
|
|
|
|
{
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2022-01-26 14:16:12 +01:00
|
|
|
* @var Import
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2022-01-26 14:16:12 +01:00
|
|
|
private $import;
|
2021-12-14 16:59:12 +01:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var Event
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $tmpCurrentEvent;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var Logger
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $logger;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var EventRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $eventRepository;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var OrganizerRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $organizerRepository;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var DateRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $dateRepository;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var ConfigurationManager
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $configurationManager;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var ObjectManager
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $objectManager;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var PersistenceManager
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $persistenceManager;
|
|
|
|
|
2021-12-15 12:28:06 +01:00
|
|
|
/**
|
|
|
|
* @var DataFetcher
|
|
|
|
*/
|
|
|
|
private $dataFetcher;
|
|
|
|
|
2022-04-21 08:07:25 +02:00
|
|
|
/**
|
|
|
|
* @var DatesFactory
|
|
|
|
*/
|
|
|
|
private $datesFactory;
|
|
|
|
|
2023-06-12 11:07:52 +02:00
|
|
|
/**
|
|
|
|
* @var FilesAssignment
|
|
|
|
*/
|
|
|
|
private $filesAssignment;
|
|
|
|
|
2022-07-05 14:08:14 +02:00
|
|
|
/**
|
|
|
|
* @var CategoriesAssignment
|
|
|
|
*/
|
|
|
|
private $categoriesAssignment;
|
|
|
|
|
2022-08-02 15:56:18 +02:00
|
|
|
/**
|
|
|
|
* @var LocationAssignment
|
|
|
|
*/
|
|
|
|
private $locationAssignment;
|
|
|
|
|
2022-11-23 10:59:55 +01:00
|
|
|
/**
|
|
|
|
* @var Slugger
|
|
|
|
*/
|
|
|
|
private $slugger;
|
|
|
|
|
2023-06-19 10:13:26 +02:00
|
|
|
/**
|
|
|
|
* @var CacheManager
|
|
|
|
*/
|
|
|
|
private $cacheManager;
|
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
/**
|
|
|
|
* @var DataHandler
|
|
|
|
*/
|
|
|
|
private $dataHandler;
|
|
|
|
|
2023-08-10 14:20:37 +02:00
|
|
|
/**
|
|
|
|
* @var EventDispatcher
|
|
|
|
*/
|
|
|
|
private $eventDispatcher;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* ImportService constructor.
|
2023-07-04 10:21:49 +02:00
|
|
|
*
|
2019-08-12 07:43:37 +02:00
|
|
|
* @param EventRepository $eventRepository
|
|
|
|
* @param OrganizerRepository $organizerRepository
|
|
|
|
* @param DateRepository $dateRepository
|
|
|
|
* @param ConfigurationManager $configurationManager
|
|
|
|
* @param PersistenceManager $persistenceManager
|
|
|
|
* @param ObjectManager $objectManager
|
2021-12-15 12:28:06 +01:00
|
|
|
* @param DataFetcher $dataFetcher
|
2023-06-12 11:07:52 +02:00
|
|
|
* @param FilesAssignment $filesAssignment
|
2022-07-05 14:08:14 +02:00
|
|
|
* @param CategoriesAssignment $categoriesAssignment
|
2022-08-02 15:56:18 +02:00
|
|
|
* @param LocationAssignment $locationAssignment
|
2022-11-23 10:59:55 +01:00
|
|
|
* @param Slugger $slugger
|
2023-06-19 10:13:26 +02:00
|
|
|
* @param CacheManager $cacheManager
|
2023-11-06 08:44:03 +01:00
|
|
|
* @param DataHandler $dataHandler
|
2023-08-10 14:20:37 +02:00
|
|
|
* @param EventDispatcher $eventDispatcher
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
EventRepository $eventRepository,
|
|
|
|
OrganizerRepository $organizerRepository,
|
|
|
|
DateRepository $dateRepository,
|
|
|
|
ConfigurationManager $configurationManager,
|
|
|
|
PersistenceManager $persistenceManager,
|
2019-08-12 15:49:52 +02:00
|
|
|
ObjectManager $objectManager,
|
2022-04-21 08:07:25 +02:00
|
|
|
DataFetcher $dataFetcher,
|
2022-07-05 14:08:14 +02:00
|
|
|
DatesFactory $datesFactory,
|
2023-06-12 11:07:52 +02:00
|
|
|
FilesAssignment $filesAssignment,
|
2022-08-02 15:56:18 +02:00
|
|
|
CategoriesAssignment $categoriesAssignment,
|
2022-11-23 10:59:55 +01:00
|
|
|
LocationAssignment $locationAssignment,
|
2023-06-19 10:13:26 +02:00
|
|
|
Slugger $slugger,
|
2023-08-10 14:20:37 +02:00
|
|
|
CacheManager $cacheManager,
|
2023-11-06 08:44:03 +01:00
|
|
|
DataHandler $dataHandler,
|
2023-08-10 14:20:37 +02:00
|
|
|
EventDispatcher $eventDispatcher
|
2019-08-12 07:43:37 +02:00
|
|
|
) {
|
2021-09-07 09:03:02 +02:00
|
|
|
$this->eventRepository = $eventRepository;
|
|
|
|
$this->organizerRepository = $organizerRepository;
|
|
|
|
$this->dateRepository = $dateRepository;
|
|
|
|
$this->configurationManager = $configurationManager;
|
|
|
|
$this->persistenceManager = $persistenceManager;
|
|
|
|
$this->objectManager = $objectManager;
|
2021-12-15 12:28:06 +01:00
|
|
|
$this->dataFetcher = $dataFetcher;
|
2022-04-21 08:07:25 +02:00
|
|
|
$this->datesFactory = $datesFactory;
|
2023-06-12 11:07:52 +02:00
|
|
|
$this->filesAssignment = $filesAssignment;
|
2022-07-05 14:08:14 +02:00
|
|
|
$this->categoriesAssignment = $categoriesAssignment;
|
2022-08-02 15:56:18 +02:00
|
|
|
$this->locationAssignment = $locationAssignment;
|
2022-11-23 10:59:55 +01:00
|
|
|
$this->slugger = $slugger;
|
2023-06-19 10:13:26 +02:00
|
|
|
$this->cacheManager = $cacheManager;
|
2023-11-06 08:44:03 +01:00
|
|
|
$this->dataHandler = $dataHandler;
|
2023-08-10 14:20:37 +02:00
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
public function import(
|
2022-01-26 14:16:12 +01:00
|
|
|
Import $import
|
2021-12-14 16:59:12 +01:00
|
|
|
): int {
|
2022-01-26 14:16:12 +01:00
|
|
|
$this->import = $import;
|
2019-08-12 15:49:52 +02:00
|
|
|
|
|
|
|
// Get configuration
|
2019-08-12 07:43:37 +02:00
|
|
|
$frameworkConfiguration = $this->configurationManager->getConfiguration(
|
|
|
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
|
|
|
|
);
|
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Set storage pid
|
2019-08-12 07:43:37 +02:00
|
|
|
$persistenceConfiguration = [
|
|
|
|
'persistence' => [
|
2022-01-26 14:16:12 +01:00
|
|
|
'storagePid' => $this->import->getStoragePid(),
|
2019-08-12 07:43:37 +02:00
|
|
|
],
|
|
|
|
];
|
2019-08-12 15:49:52 +02:00
|
|
|
|
|
|
|
// Set Configuration
|
2019-08-12 07:43:37 +02:00
|
|
|
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
|
2019-08-13 11:17:34 +02:00
|
|
|
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
|
2019-10-09 15:03:58 +02:00
|
|
|
$this->logger->info('Starting Destination Data Import Service');
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
try {
|
2022-01-26 14:16:12 +01:00
|
|
|
$data = $this->dataFetcher->fetchSearchResult($import);
|
2022-12-21 13:16:20 +01:00
|
|
|
} catch (Exception $e) {
|
2019-08-13 09:12:30 +02:00
|
|
|
$this->logger->error('Could not receive data.');
|
2019-08-12 07:43:37 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2021-12-14 16:59:12 +01:00
|
|
|
|
2022-01-26 14:16:12 +01:00
|
|
|
return $this->processData($data);
|
2021-12-14 16:59:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processData(array $data): int
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2019-10-09 15:03:58 +02:00
|
|
|
$this->logger->info('Processing json ' . count($data['items']));
|
|
|
|
|
|
|
|
// Get selected region
|
2022-01-27 14:14:02 +01:00
|
|
|
$selectedRegion = $this->import->getRegion();
|
2019-08-12 07:43:37 +02:00
|
|
|
|
|
|
|
foreach ($data['items'] as $event) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->logger->info('Processing event ' . substr($event['title'], 0, 20));
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Event already exists? If not create one!
|
|
|
|
$this->tmpCurrentEvent = $this->getOrCreateEvent($event['global_id'], $event['title']);
|
2023-08-10 14:20:37 +02:00
|
|
|
$existingEvent = clone $this->tmpCurrentEvent;
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2020-10-01 08:34:13 +02:00
|
|
|
// Set language UID
|
|
|
|
$this->tmpCurrentEvent->setLanguageUid(-1);
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set selected Region
|
2021-12-14 16:22:29 +01:00
|
|
|
if ($selectedRegion instanceof Region) {
|
|
|
|
$this->tmpCurrentEvent->setRegion($selectedRegion);
|
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set Title
|
|
|
|
$this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254));
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set Highlight (Is only set in rest if true)
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['highlight'] ?? false) {
|
2019-08-12 07:43:37 +02:00
|
|
|
$this->tmpCurrentEvent->setHighlight($event['highlight']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set Texts
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['texts'] ?? false) {
|
2019-08-13 11:52:34 +02:00
|
|
|
$this->setTexts($event['texts']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2022-08-02 15:56:18 +02:00
|
|
|
$this->tmpCurrentEvent->setLocation(
|
|
|
|
$this->locationAssignment->getLocation($event)
|
|
|
|
);
|
2019-09-23 15:41:41 +02:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set Organizer
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['addresses'] ?? false) {
|
2019-08-13 11:52:34 +02:00
|
|
|
$this->setOrganizer($event['addresses']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2020-10-01 09:45:32 +02:00
|
|
|
// Set Social
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['media_objects'] ?? false) {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->setSocial($event['media_objects']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2020-08-19 11:30:13 +02:00
|
|
|
|
2022-08-02 15:56:18 +02:00
|
|
|
if ($event['web'] ?? false) {
|
|
|
|
$this->tmpCurrentEvent->setWeb($event['web']);
|
|
|
|
}
|
|
|
|
|
2020-10-01 09:45:32 +02:00
|
|
|
// Set Tickets
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['media_objects'] ?? false) {
|
2020-10-01 09:45:32 +02:00
|
|
|
$this->setTickets($event['media_objects']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2020-10-01 09:45:32 +02:00
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
// Set Dates
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['timeIntervals'] ?? false) {
|
2021-09-07 08:36:48 +02:00
|
|
|
$this->setDates(
|
|
|
|
$event['timeIntervals'],
|
2023-06-07 08:56:42 +02:00
|
|
|
(bool)$this->getAttributeValue($event, 'DETAILS_ABGESAGT')
|
2021-09-07 08:36:48 +02:00
|
|
|
);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Set Assets
|
2022-07-13 15:58:05 +02:00
|
|
|
if ($event['media_objects'] ?? false) {
|
2019-08-13 11:52:34 +02:00
|
|
|
$this->setAssets($event['media_objects']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2023-08-10 15:02:05 +02:00
|
|
|
if ($event['source'] ?? false) {
|
|
|
|
$this->setSource($event['source']);
|
|
|
|
}
|
|
|
|
|
2023-08-10 14:20:37 +02:00
|
|
|
$this->eventDispatcher->dispatch(new EventImportEvent(
|
|
|
|
$existingEvent,
|
|
|
|
$this->tmpCurrentEvent
|
|
|
|
));
|
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Update and persist
|
|
|
|
$this->logger->info('Persist database');
|
|
|
|
$this->eventRepository->update($this->tmpCurrentEvent);
|
|
|
|
$this->persistenceManager->persistAll();
|
2023-11-06 08:44:03 +01:00
|
|
|
|
|
|
|
// Apply changes via DataHandler (The new way)
|
|
|
|
$this->logger->info('Apply changes via DataHandler');
|
|
|
|
if ($event['categories'] ?? false) {
|
|
|
|
$this->setCategories($event['categories']);
|
|
|
|
}
|
|
|
|
if ($event['features']) {
|
|
|
|
$this->setFeatures($event['features']);
|
|
|
|
}
|
|
|
|
|
2023-06-15 09:55:15 +02:00
|
|
|
$this->logger->info('Update slugs');
|
|
|
|
$this->slugger->update('tx_events_domain_model_event');
|
|
|
|
$this->slugger->update('tx_events_domain_model_date');
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2022-11-23 10:59:55 +01:00
|
|
|
|
2023-06-19 10:13:26 +02:00
|
|
|
$this->logger->info('Flushing cache');
|
|
|
|
$this->cacheManager->clearAllCacheTags();
|
|
|
|
|
2019-10-09 15:03:58 +02:00
|
|
|
$this->logger->info('Finished import');
|
2019-08-12 15:49:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setCategories(array $categories): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2022-07-05 14:08:14 +02:00
|
|
|
$categories = $this->categoriesAssignment->getCategories(new CategoryImport(
|
|
|
|
$this->import->getCategoryParent(),
|
|
|
|
$this->import->getCategoriesPid(),
|
|
|
|
$categories
|
|
|
|
));
|
2021-12-14 16:59:12 +01:00
|
|
|
|
2023-08-14 12:09:28 +02:00
|
|
|
$event = new CategoriesAssignEvent(
|
|
|
|
$this->tmpCurrentEvent,
|
|
|
|
$categories
|
|
|
|
);
|
|
|
|
$this->eventDispatcher->dispatch($event);
|
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
$this->dataHandler->storeAssignments(new Assignment(
|
|
|
|
$this->tmpCurrentEvent->getUid(),
|
|
|
|
'categories',
|
|
|
|
$event->getCategories()->toArray()
|
|
|
|
));
|
2022-07-05 14:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function setFeatures(array $features): void
|
|
|
|
{
|
|
|
|
$features = $this->categoriesAssignment->getCategories(new CategoryImport(
|
|
|
|
$this->import->getFeaturesParent(),
|
|
|
|
$this->import->getFeaturesPid(),
|
|
|
|
$features,
|
|
|
|
true
|
|
|
|
));
|
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
$this->dataHandler->storeAssignments(new Assignment(
|
|
|
|
$this->tmpCurrentEvent->getUid(),
|
|
|
|
'features',
|
|
|
|
$features->toArray()
|
|
|
|
));
|
2019-08-13 09:12:30 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setDates(
|
2021-09-07 08:36:48 +02:00
|
|
|
array $timeIntervals,
|
|
|
|
bool $canceled
|
2021-12-14 16:59:12 +01:00
|
|
|
): void {
|
2019-10-09 15:03:58 +02:00
|
|
|
// @TODO: does not seem to work -->
|
2019-08-12 15:49:52 +02:00
|
|
|
//$currentEventDates = $this->tmpCurrentEvent->getDates();
|
|
|
|
//$this->tmpCurrentEvent->removeAllDates($currentEventDates);
|
|
|
|
// <--
|
|
|
|
// TODO: Workaround delete dates
|
|
|
|
$currentEventDates = $this->tmpCurrentEvent->getDates();
|
|
|
|
$this->logger->info('Found ' . count($currentEventDates) . ' to delete');
|
|
|
|
foreach ($currentEventDates as $currentDate) {
|
|
|
|
$this->dateRepository->remove($currentDate);
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2022-04-21 08:07:25 +02:00
|
|
|
$dates = $this->datesFactory->createDates($timeIntervals, $canceled);
|
|
|
|
foreach ($dates as $date) {
|
|
|
|
$this->tmpCurrentEvent->addDate($date);
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2022-04-21 08:07:25 +02:00
|
|
|
|
2019-10-11 15:12:07 +02:00
|
|
|
$this->logger->info('Finished setup dates');
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setOrganizer(array $addresses): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($addresses as $address) {
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($address['rel'] == 'organizer') {
|
2019-08-12 15:49:52 +02:00
|
|
|
$tmpOrganizer = $this->organizerRepository->findOneByName($address['name']);
|
2019-08-13 11:17:34 +02:00
|
|
|
if ($tmpOrganizer) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->tmpCurrentEvent->setOrganizer($tmpOrganizer);
|
2019-08-13 11:17:34 +02:00
|
|
|
continue;
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2021-01-07 08:47:15 +01:00
|
|
|
$tmpOrganizer = $this->objectManager->get(Organizer::class);
|
2020-10-01 08:34:13 +02:00
|
|
|
$tmpOrganizer->setLanguageUid(-1);
|
2021-09-07 09:52:14 +02:00
|
|
|
$tmpOrganizer->setName($address['name'] ?? '');
|
|
|
|
$tmpOrganizer->setCity($address['city'] ?? '');
|
|
|
|
$tmpOrganizer->setZip($address['zip'] ?? '');
|
|
|
|
$tmpOrganizer->setStreet($address['street'] ?? '');
|
|
|
|
$tmpOrganizer->setPhone($address['phone'] ?? '');
|
|
|
|
$tmpOrganizer->setWeb($address['web'] ?? '');
|
|
|
|
$tmpOrganizer->setEmail($address['email'] ?? '');
|
|
|
|
$tmpOrganizer->setDistrict($address['district'] ?? '');
|
2019-08-13 11:17:34 +02:00
|
|
|
$this->organizerRepository->add($tmpOrganizer);
|
|
|
|
$this->tmpCurrentEvent->setOrganizer($tmpOrganizer);
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2020-08-19 11:30:13 +02:00
|
|
|
/**
|
|
|
|
* @param array $media
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setSocial(array $media): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($media as $link) {
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($link['rel'] == 'socialmedia' && $link['value'] == 'Facebook') {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setFacebook($link['url']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($link['rel'] == 'socialmedia' && $link['value'] == 'YouTube') {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setYouTube($link['url']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($link['rel'] == 'socialmedia' && $link['value'] == 'Instagram') {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setInstagram($link['url']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2020-10-01 09:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setTickets(array $media): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($media as $link) {
|
2022-07-07 08:22:45 +02:00
|
|
|
if (isset($link['rel']) === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($link['rel'] === 'ticket') {
|
2020-10-01 09:45:32 +02:00
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
2022-07-07 08:22:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
$link['rel'] === 'booking'
|
|
|
|
&& !$this->hasRelation('ticket', $media)
|
|
|
|
) {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
2022-07-07 08:22:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
$link['rel'] === 'PRICE_KARTENLINK'
|
|
|
|
&& !$this->hasRelation('ticket', $media)
|
|
|
|
&& !$this->hasRelation('booking', $media)
|
|
|
|
) {
|
2020-10-01 09:45:32 +02:00
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
2022-07-07 08:22:45 +02:00
|
|
|
return;
|
2020-10-01 09:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-07 08:22:45 +02:00
|
|
|
private function hasRelation(string $needle, array $haystack): bool
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($haystack as $key => $value) {
|
2022-07-07 08:22:45 +02:00
|
|
|
if (isset($haystack['rel']) && $haystack['rel'] === $needle) {
|
2020-10-01 09:45:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
2022-07-07 08:22:45 +02:00
|
|
|
|
|
|
|
if (is_array($value) && $this->hasRelation($needle, $value)) {
|
|
|
|
return true;
|
2020-10-01 09:45:32 +02:00
|
|
|
}
|
2020-08-19 11:30:13 +02:00
|
|
|
}
|
2022-07-07 08:22:45 +02:00
|
|
|
|
2020-10-01 09:45:32 +02:00
|
|
|
return false;
|
2020-08-19 11:30:13 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setTexts(array $texts): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($texts as $text) {
|
2021-12-20 10:20:47 +01:00
|
|
|
if (isset($text['value']) === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($text['rel'] == 'details' && $text['type'] == 'text/plain') {
|
2023-03-17 12:58:06 +01:00
|
|
|
$this->tmpCurrentEvent->setDetails(str_replace("\n\n", "\n", $text['value']));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($text['rel'] == 'teaser' && $text['type'] == 'text/plain') {
|
2023-03-17 12:58:06 +01:00
|
|
|
$this->tmpCurrentEvent->setTeaser(str_replace("\n\n", "\n", $text['value']));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2023-06-07 08:56:42 +02:00
|
|
|
if ($text['rel'] == 'PRICE_INFO' && $text['type'] == 'text/plain') {
|
2023-03-17 12:58:06 +01:00
|
|
|
$this->tmpCurrentEvent->setPriceInfo(str_replace("\n\n", "\n", $text['value']));
|
2020-03-16 14:06:03 +01:00
|
|
|
}
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function getOrCreateEvent(string $globalId, string $title): Event
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2019-08-12 15:49:52 +02:00
|
|
|
$event = $this->eventRepository->findOneByGlobalId($globalId);
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
if ($event instanceof Event) {
|
|
|
|
$this->logger->info(
|
|
|
|
'Found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database'
|
|
|
|
);
|
2019-08-13 11:17:34 +02:00
|
|
|
return $event;
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-08-13 11:17:34 +02:00
|
|
|
// New event is created
|
|
|
|
$this->logger->info(substr($title, 0, 20) . ' does not exist');
|
2021-01-07 08:47:15 +01:00
|
|
|
$event = $this->objectManager->get(Event::class);
|
2019-08-13 11:17:34 +02:00
|
|
|
// Create event and persist
|
|
|
|
$event->setGlobalId($globalId);
|
|
|
|
$this->eventRepository->add($event);
|
|
|
|
$this->persistenceManager->persistAll();
|
2021-12-14 16:59:12 +01:00
|
|
|
$this->logger->info(
|
|
|
|
'Not found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database.'
|
|
|
|
. ' Created new one.'
|
|
|
|
);
|
2019-08-12 15:49:52 +02:00
|
|
|
return $event;
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setAssets(array $assets): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2023-06-07 08:56:42 +02:00
|
|
|
$this->logger->info('Set assets');
|
2023-06-12 11:07:52 +02:00
|
|
|
$images = $this->filesAssignment->getImages(
|
|
|
|
$this->import,
|
|
|
|
$this->tmpCurrentEvent,
|
|
|
|
$assets
|
|
|
|
);
|
|
|
|
$this->tmpCurrentEvent->setImages($images);
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
|
2023-08-10 15:02:05 +02:00
|
|
|
private function setSource(array $source): void
|
|
|
|
{
|
|
|
|
if (isset($source['value'])) {
|
|
|
|
$this->tmpCurrentEvent->setSourceName($source['value']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($source['url'])) {
|
|
|
|
$this->tmpCurrentEvent->setSourceUrl($source['url']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-07 08:36:48 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* Fetch the boolean value for requested attribute.
|
2021-09-07 08:36:48 +02:00
|
|
|
*
|
|
|
|
* Returns first if multiple attributes with same key exist.
|
|
|
|
* Casts "true" and "false" to true and false.
|
|
|
|
*/
|
|
|
|
private function getAttributeValue(
|
|
|
|
array $event,
|
|
|
|
string $attributeKey
|
2021-12-14 16:59:12 +01:00
|
|
|
): bool {
|
2021-09-07 08:36:48 +02:00
|
|
|
$attributes = array_filter($event['attributes'] ?? [], function (array $attribute) use ($attributeKey) {
|
|
|
|
$currentKey = $attribute['key'] ?? '';
|
|
|
|
return $currentKey === $attributeKey;
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($attributes === []) {
|
2021-12-14 16:59:12 +01:00
|
|
|
return false;
|
2021-09-07 08:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$value = $attributes[0]['value'] ?? null;
|
|
|
|
|
|
|
|
if ($value === 'true') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ($value === 'false') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-07 08:56:42 +02:00
|
|
|
return (bool)$value;
|
2021-09-07 08:36:48 +02:00
|
|
|
}
|
2019-10-09 15:03:58 +02:00
|
|
|
}
|