2019-08-12 07:43:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wrm\Events\Service;
|
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
use TYPO3\CMS\Core\Core\Environment;
|
2021-12-16 09:11:45 +01:00
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
2021-01-07 08:58:03 +01:00
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
|
|
|
use TYPO3\CMS\Core\DataHandling\SlugHelper;
|
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;
|
2021-09-06 15:18:48 +02:00
|
|
|
use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
|
2021-12-14 16:59:12 +01:00
|
|
|
use TYPO3\CMS\Core\Resource\File;
|
2019-08-12 07:43:37 +02:00
|
|
|
use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
|
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
2021-12-14 16:59:12 +01:00
|
|
|
use TYPO3\CMS\Core\Resource\ResourceStorage;
|
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;
|
2019-08-12 07:43:37 +02:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
2021-09-08 12:32:51 +02:00
|
|
|
use Wrm\Events\Domain\Model\Category;
|
2021-01-07 08:58:03 +01:00
|
|
|
use Wrm\Events\Domain\Model\Date;
|
|
|
|
use Wrm\Events\Domain\Model\Event;
|
|
|
|
use Wrm\Events\Domain\Model\Organizer;
|
2021-12-14 16:22:29 +01:00
|
|
|
use Wrm\Events\Domain\Model\Region;
|
2021-09-06 15:19:06 +02:00
|
|
|
use Wrm\Events\Domain\Repository\CategoryRepository;
|
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;
|
|
|
|
use Wrm\Events\Domain\Repository\RegionRepository;
|
2021-12-15 12:28:06 +01:00
|
|
|
use Wrm\Events\Service\DestinationDataImportService\DataFetcher;
|
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
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restUrl;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restLicenseKey;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restType;
|
|
|
|
|
2020-02-19 09:08:15 +01:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2020-02-19 09:08:15 +01:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restLimit;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restMode;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restTemplate;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $restExperience;
|
|
|
|
|
2019-08-13 10:10:00 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var int
|
2019-08-13 10:10:00 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $storagePid;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:22:29 +01:00
|
|
|
* @var ?int
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $regionUid;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var int
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $categoriesPid;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var int
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $categoryParentUid;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
2021-12-14 16:59:12 +01:00
|
|
|
* @var string
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $filesFolder;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $settings = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Environment
|
2019-08-12 15:49:52 +02:00
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $environment;
|
|
|
|
|
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 RegionRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $regionRepository;
|
|
|
|
|
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 CategoryRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $sysCategoriesRepository;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var MetaDataRepository
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $metaDataRepository;
|
|
|
|
|
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;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* @var ResourceFactory
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private $resourceFactory;
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2021-12-15 12:28:06 +01:00
|
|
|
/**
|
|
|
|
* @var DataFetcher
|
|
|
|
*/
|
|
|
|
private $dataFetcher;
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
/**
|
|
|
|
* ImportService constructor.
|
|
|
|
* @param EventRepository $eventRepository
|
|
|
|
* @param RegionRepository $regionRepository
|
|
|
|
* @param OrganizerRepository $organizerRepository
|
|
|
|
* @param DateRepository $dateRepository
|
|
|
|
* @param CategoryRepository $sysCategoriesRepository
|
|
|
|
* @param MetaDataRepository $metaDataRepository
|
|
|
|
* @param ConfigurationManager $configurationManager
|
|
|
|
* @param PersistenceManager $persistenceManager
|
|
|
|
* @param ResourceFactory $resourceFactory
|
|
|
|
* @param ObjectManager $objectManager
|
2019-08-12 15:49:52 +02:00
|
|
|
* @param Environment $environment
|
2021-12-15 12:28:06 +01:00
|
|
|
* @param DataFetcher $dataFetcher
|
2019-08-12 07:43:37 +02:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
EventRepository $eventRepository,
|
|
|
|
RegionRepository $regionRepository,
|
|
|
|
OrganizerRepository $organizerRepository,
|
|
|
|
DateRepository $dateRepository,
|
|
|
|
CategoryRepository $sysCategoriesRepository,
|
|
|
|
MetaDataRepository $metaDataRepository,
|
|
|
|
ConfigurationManager $configurationManager,
|
|
|
|
PersistenceManager $persistenceManager,
|
|
|
|
ResourceFactory $resourceFactory,
|
2019-08-12 15:49:52 +02:00
|
|
|
ObjectManager $objectManager,
|
2021-12-15 12:28:06 +01:00
|
|
|
Environment $environment,
|
|
|
|
DataFetcher $dataFetcher
|
2019-08-12 07:43:37 +02:00
|
|
|
) {
|
2021-09-07 09:03:02 +02:00
|
|
|
$this->eventRepository = $eventRepository;
|
|
|
|
$this->regionRepository = $regionRepository;
|
|
|
|
$this->organizerRepository = $organizerRepository;
|
|
|
|
$this->dateRepository = $dateRepository;
|
|
|
|
$this->sysCategoriesRepository = $sysCategoriesRepository;
|
|
|
|
$this->metaDataRepository = $metaDataRepository;
|
|
|
|
$this->configurationManager = $configurationManager;
|
|
|
|
$this->persistenceManager = $persistenceManager;
|
|
|
|
$this->resourceFactory = $resourceFactory;
|
|
|
|
$this->objectManager = $objectManager;
|
|
|
|
$this->environment = $environment;
|
2021-12-15 12:28:06 +01:00
|
|
|
$this->dataFetcher = $dataFetcher;
|
2019-08-12 07:43:37 +02:00
|
|
|
|
|
|
|
// Get Typoscript Settings
|
|
|
|
$this->settings = $this->configurationManager->getConfiguration(
|
|
|
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
|
|
|
'Events',
|
|
|
|
'Pi1'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set properties
|
2021-09-07 09:03:02 +02:00
|
|
|
$this->restUrl = $this->settings['destinationData']['restUrl'];
|
|
|
|
$this->restLicenseKey = $this->settings['destinationData']['license'];
|
|
|
|
$this->restType = $this->settings['destinationData']['restType'];
|
|
|
|
$this->restLimit = $this->settings['destinationData']['restLimit'];
|
|
|
|
$this->restMode = $this->settings['destinationData']['restMode'];
|
|
|
|
$this->restTemplate = $this->settings['destinationData']['restTemplate'];
|
2021-12-14 16:59:12 +01:00
|
|
|
$this->categoriesPid = (int) $this->settings['destinationData']['categoriesPid'];
|
|
|
|
$this->categoryParentUid = (int) $this->settings['destinationData']['categoryParentUid'];
|
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(
|
|
|
|
string $restExperience,
|
|
|
|
int $storagePid,
|
2021-12-14 16:22:29 +01:00
|
|
|
?int $regionUid,
|
2021-12-14 16:59:12 +01:00
|
|
|
string $filesFolder
|
|
|
|
): int {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->restExperience = $restExperience;
|
|
|
|
$this->storagePid = $storagePid;
|
|
|
|
$this->regionUid = $regionUid;
|
|
|
|
$this->filesFolder = $filesFolder;
|
|
|
|
|
|
|
|
// 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' => [
|
|
|
|
'storagePid' => $this->storagePid,
|
|
|
|
],
|
|
|
|
];
|
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-08-12 07:43:37 +02:00
|
|
|
|
2019-10-09 15:03:58 +02:00
|
|
|
$this->logger->info('Starting Destination Data Import Service');
|
2020-02-19 09:08:15 +01:00
|
|
|
$restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&mode=' . $this->restMode . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate;
|
2019-08-12 07:43:37 +02:00
|
|
|
$this->logger->info('Try to get data from ' . $restUrl);
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
try {
|
|
|
|
$fetchedData = $this->fetchData($restUrl);
|
|
|
|
} 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
|
|
|
|
|
|
|
return $this->processData($fetchedData);
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function fetchData(string $restUrl): array
|
|
|
|
{
|
|
|
|
$jsonContent = file_get_contents($restUrl);
|
|
|
|
if (is_string($jsonContent) === false) {
|
|
|
|
throw new \Exception('Could not receive data.', 1639495835);
|
|
|
|
}
|
|
|
|
$jsonResponse = json_decode($jsonContent, true);
|
|
|
|
if (is_array($jsonResponse) === false) {
|
|
|
|
throw new \Exception('Could not receive data.', 1639495835);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items');
|
|
|
|
return $jsonResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-12-14 16:22:29 +01:00
|
|
|
$selectedRegion = null;
|
|
|
|
if (is_int($this->regionUid)) {
|
|
|
|
$selectedRegion = $this->regionRepository->findByUid($this->regionUid);
|
|
|
|
}
|
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']);
|
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)
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['highlight']) {
|
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
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['texts']) {
|
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
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Set address and geo data
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['name'] || $event['street'] || $event['city'] || $event['zip'] || $event['country'] || $event['web']) {
|
2020-03-16 13:52:58 +01:00
|
|
|
$this->setAddress($event);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-08-13 11:52:34 +02:00
|
|
|
|
2019-09-23 15:41:41 +02:00
|
|
|
// Set LatLng
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['geo']['main']['latitude'] && $event['geo']['main']['longitude']) {
|
2019-09-23 15:41:41 +02:00
|
|
|
$this->setLatLng($event['geo']['main']['latitude'], $event['geo']['main']['longitude']);
|
2021-01-07 08:50:43 +01:00
|
|
|
}
|
2019-09-23 15:41:41 +02:00
|
|
|
|
2019-08-13 09:12:30 +02:00
|
|
|
// Set Categories
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['categories']) {
|
2019-08-13 11:52:34 +02:00
|
|
|
$this->setCategories($event['categories']);
|
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 Organizer
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['addresses']) {
|
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
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['media_objects']) {
|
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
|
|
|
|
2020-10-01 09:45:32 +02:00
|
|
|
// Set Tickets
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['media_objects']) {
|
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
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['timeIntervals']) {
|
2021-09-07 08:36:48 +02:00
|
|
|
$this->setDates(
|
|
|
|
$event['timeIntervals'],
|
|
|
|
(bool) $this->getAttributeValue($event, 'DETAILS_ABGESAGT')
|
|
|
|
);
|
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
|
2021-01-07 08:50:43 +01:00
|
|
|
if ($event['media_objects']) {
|
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
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// Update and persist
|
|
|
|
$this->logger->info('Persist database');
|
|
|
|
$this->eventRepository->update($this->tmpCurrentEvent);
|
|
|
|
$this->persistenceManager->persistAll();
|
|
|
|
}
|
|
|
|
$this->doSlugUpdate();
|
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
|
|
|
|
2019-08-13 09:12:30 +02:00
|
|
|
/**
|
2019-10-09 15:03:58 +02:00
|
|
|
*
|
2019-08-13 09:12:30 +02:00
|
|
|
* @param array $categories
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setCategories(array $categories): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2019-08-13 09:12:30 +02:00
|
|
|
$sysParentCategory = $this->sysCategoriesRepository->findByUid($this->categoryParentUid);
|
2021-12-14 16:59:12 +01:00
|
|
|
if (!$sysParentCategory instanceof Category) {
|
|
|
|
$this->logger->warning(
|
|
|
|
'Could not fetch system parent category by uid.',
|
|
|
|
['uid' => $this->categoryParentUid]
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-13 09:12:30 +02:00
|
|
|
foreach ($categories as $categoryTitle) {
|
|
|
|
$tmpSysCategory = $this->sysCategoriesRepository->findOneByTitle($categoryTitle);
|
2019-08-13 11:17:34 +02:00
|
|
|
if (!$tmpSysCategory) {
|
2019-08-13 09:12:30 +02:00
|
|
|
$this->logger->info('Creating new category: ' . $categoryTitle);
|
2021-01-07 08:47:15 +01:00
|
|
|
$tmpSysCategory = $this->objectManager->get(Category::class);
|
2019-08-13 09:12:30 +02:00
|
|
|
$tmpSysCategory->setTitle($categoryTitle);
|
|
|
|
$tmpSysCategory->setParent($sysParentCategory);
|
2021-12-14 16:59:12 +01:00
|
|
|
$tmpSysCategory->setPid($this->categoriesPid);
|
2019-08-13 09:12:30 +02:00
|
|
|
$this->sysCategoriesRepository->add($tmpSysCategory);
|
|
|
|
$this->tmpCurrentEvent->addCategory($tmpSysCategory);
|
|
|
|
} else {
|
|
|
|
$this->tmpCurrentEvent->addCategory($tmpSysCategory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
// <--
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
// TODO: Workaround delete dates
|
|
|
|
$currentEventDates = $this->tmpCurrentEvent->getDates();
|
|
|
|
$this->logger->info('Found ' . count($currentEventDates) . ' to delete');
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
foreach ($currentEventDates as $currentDate) {
|
|
|
|
$this->dateRepository->remove($currentDate);
|
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-10-11 15:12:07 +02:00
|
|
|
$today = new \DateTime('today');
|
|
|
|
$today = $today->getTimestamp();
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
foreach ($timeIntervals as $date) {
|
|
|
|
// Check if dates are given as interval or not
|
|
|
|
if (empty($date['interval'])) {
|
2019-10-11 15:12:07 +02:00
|
|
|
if (strtotime($date['start']) > $today) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->logger->info('Setup single date');
|
|
|
|
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
|
|
|
|
$end = new \DateTime($date['end'], new \DateTimeZone($date['tz']));
|
|
|
|
$this->logger->info('Start transformed ' . $start->format('Y-m-d H:i'));
|
|
|
|
$this->logger->info('End transformed ' . $end->format('Y-m-d H:i'));
|
2021-09-07 08:36:48 +02:00
|
|
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
|
|
|
$start,
|
|
|
|
$end,
|
|
|
|
$canceled
|
|
|
|
));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-16 12:10:01 +01:00
|
|
|
if ($date['freq'] == 'Daily' && empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->logger->info('Setup daily interval dates');
|
|
|
|
$this->logger->info('Start ' . $date['start']);
|
|
|
|
$this->logger->info('End ' . $date['repeatUntil']);
|
|
|
|
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
|
|
|
|
$until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz']));
|
2020-03-16 12:10:01 +01:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
$i = (int) strtotime($start->format('l'), $start->getTimestamp());
|
|
|
|
while ($i !== 0 && $i <= $until->getTimestamp()) {
|
|
|
|
$i = (int) strtotime('+1 day', $i);
|
|
|
|
|
2019-10-11 15:12:07 +02:00
|
|
|
if ($i >= $today) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$eventStart = new \DateTime();
|
|
|
|
$eventStart->setTimestamp($i);
|
2021-12-14 16:59:12 +01:00
|
|
|
$eventStart->setTime((int) $start->format('H'), (int) $start->format('i'));
|
2019-08-12 15:49:52 +02:00
|
|
|
$eventEnd = new \DateTime();
|
|
|
|
$eventEnd->setTimestamp($i);
|
2021-12-14 16:59:12 +01:00
|
|
|
$eventEnd->setTime((int) $until->format('H'), (int) $until->format('i'));
|
2021-09-07 08:36:48 +02:00
|
|
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
|
|
|
$eventStart,
|
|
|
|
$eventEnd,
|
|
|
|
$canceled
|
|
|
|
));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
2021-01-07 08:50:43 +01:00
|
|
|
} elseif ($date['freq'] == 'Weekly' && !empty($date['weekdays']) && !empty($date['repeatUntil'])) {
|
2019-08-12 15:49:52 +02:00
|
|
|
foreach ($date['weekdays'] as $day) {
|
|
|
|
$this->logger->info('Setup weekly interval dates for ' . $day);
|
2019-08-12 07:43:37 +02:00
|
|
|
$this->logger->info('Start ' . $date['start']);
|
|
|
|
$this->logger->info('End ' . $date['repeatUntil']);
|
|
|
|
$start = new \DateTime($date['start'], new \DateTimeZone($date['tz']));
|
|
|
|
$until = new \DateTime($date['repeatUntil'], new \DateTimeZone($date['tz']));
|
|
|
|
|
2021-01-07 08:50:43 +01:00
|
|
|
for ($i = strtotime($day, $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 week', $i)) {
|
2019-10-11 15:12:07 +02:00
|
|
|
if ($i >= $today) {
|
2019-08-12 07:43:37 +02:00
|
|
|
$eventStart = new \DateTime();
|
|
|
|
$eventStart->setTimestamp($i);
|
2021-12-14 16:59:12 +01:00
|
|
|
$eventStart->setTime((int) $start->format('H'), (int) $start->format('i'));
|
2019-08-12 07:43:37 +02:00
|
|
|
$eventEnd = new \DateTime();
|
|
|
|
$eventEnd->setTimestamp($i);
|
2021-12-14 16:59:12 +01:00
|
|
|
$eventEnd->setTime((int) $until->format('H'), (int) $until->format('i'));
|
2021-09-07 08:36:48 +02:00
|
|
|
$this->tmpCurrentEvent->addDate(Date::createFromDestinationData(
|
|
|
|
$eventStart,
|
|
|
|
$eventEnd,
|
|
|
|
$canceled
|
|
|
|
));
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-12 15:49:52 +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) {
|
2019-08-12 15:49:52 +02:00
|
|
|
if ($address['rel'] == "organizer") {
|
|
|
|
$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
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
/**
|
2020-03-16 13:52:58 +01:00
|
|
|
* @param array $event
|
|
|
|
*/
|
2021-12-14 16:59:12 +01:00
|
|
|
private function setAddress(array $event): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2021-09-07 09:52:14 +02:00
|
|
|
$this->tmpCurrentEvent->setName($event['name'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setStreet($event['street'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setCity($event['city'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setZip($event['zip'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setCountry($event['country'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setPhone($event['phone'] ?? '');
|
|
|
|
$this->tmpCurrentEvent->setWeb($event['web'] ?? '');
|
2019-09-23 15:41:41 +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) {
|
|
|
|
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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $media
|
|
|
|
*/
|
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) {
|
2020-10-01 09:45:32 +02:00
|
|
|
if ($link['rel'] == "ticket") {
|
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
|
|
|
break;
|
2021-12-14 16:59:12 +01:00
|
|
|
} elseif ($link['rel'] == "booking" && !$this->multiArrayKeyExists('ticket', $media)) {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
2020-10-01 09:45:32 +02:00
|
|
|
break;
|
2021-12-14 16:59:12 +01:00
|
|
|
} elseif ($link['rel'] == "PRICE_KARTENLINK" && !$this->multiArrayKeyExists('ticket', $media) && !$this->multiArrayKeyExists('booking', $media)) {
|
2020-10-01 09:45:32 +02:00
|
|
|
$this->tmpCurrentEvent->setTicket($link['url']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function multiArrayKeyExists(string $needle, array $haystack): bool
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
|
|
|
foreach ($haystack as $key => $value) {
|
|
|
|
if ($needle == $key) {
|
2020-10-01 09:45:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-07 08:50:43 +01:00
|
|
|
if (is_array($value)) {
|
2021-12-14 16:59:12 +01:00
|
|
|
if ($this->multiArrayKeyExists($needle, $value) == true) {
|
2020-10-01 09:45:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-08-19 11:30:13 +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 setLatLng(string $lat, string $lng): void
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->tmpCurrentEvent->setLatitude($lat);
|
|
|
|
$this->tmpCurrentEvent->setLongitude($lng);
|
|
|
|
}
|
2019-08-12 07:43:37 +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) {
|
2019-08-12 15:49:52 +02:00
|
|
|
if ($text['rel'] == "details" && $text['type'] == "text/plain") {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setDetails(str_replace('\n\n', '\n', $text['value']));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
|
|
|
if ($text['rel'] == "teaser" && $text['type'] == "text/plain") {
|
2020-08-19 11:30:13 +02:00
|
|
|
$this->tmpCurrentEvent->setTeaser(str_replace('\n\n', '\n', $text['value']));
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2020-03-16 14:06:03 +01:00
|
|
|
if ($text['rel'] == "PRICE_INFO" && $text['type'] == "text/plain") {
|
2020-08-19 11:30:13 +02: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);
|
|
|
|
$event->setCategories(new ObjectStorage());
|
|
|
|
$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
|
|
|
{
|
2019-10-09 15:03:58 +02:00
|
|
|
$this->logger->info("Set assets");
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
$storage = $this->resourceFactory->getDefaultStorage();
|
|
|
|
if (!$storage instanceof ResourceStorage) {
|
|
|
|
$this->logger->error('No default storage defined. Cancel import.');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-08-13 11:17:34 +02:00
|
|
|
$error = false;
|
|
|
|
|
2021-01-07 08:50:43 +01:00
|
|
|
foreach ($assets as $media_object) {
|
|
|
|
if ($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") {
|
2021-12-16 10:00:51 +01:00
|
|
|
$fileUrl = urldecode($media_object['url']);
|
2021-12-14 16:59:12 +01:00
|
|
|
$orgFileNameSanitized = $storage->sanitizeFileName(
|
2020-08-18 15:22:34 +02:00
|
|
|
basename(
|
|
|
|
urldecode($media_object['url'])
|
2020-08-18 14:27:44 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-12-16 10:00:51 +01:00
|
|
|
$this->logger->info('File attached:' . $fileUrl);
|
2020-08-18 14:27:44 +02:00
|
|
|
$this->logger->info('File attached sanitized:' . $orgFileNameSanitized);
|
2019-10-09 15:03:58 +02:00
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
$targetFilePath = $this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder
|
|
|
|
. $orgFileNameSanitized;
|
2019-08-12 15:49:52 +02:00
|
|
|
// Check if file already exists
|
2021-12-14 16:59:12 +01:00
|
|
|
|
|
|
|
if (file_exists($targetFilePath)) {
|
2019-08-13 09:12:30 +02:00
|
|
|
$this->logger->info('File already exists');
|
2019-08-12 15:49:52 +02:00
|
|
|
} else {
|
2020-08-18 14:27:44 +02:00
|
|
|
$this->logger->info("File don't exist " . $orgFileNameSanitized);
|
2019-08-12 15:49:52 +02:00
|
|
|
// Load the file
|
2021-12-16 10:00:51 +01:00
|
|
|
if ($filename = $this->loadFile($fileUrl)) {
|
2019-08-12 15:49:52 +02:00
|
|
|
// Move file to defined folder
|
2021-12-16 10:00:51 +01:00
|
|
|
$this->logger->info('Adding file ' . $filename);
|
2021-09-06 15:18:48 +02:00
|
|
|
|
|
|
|
try {
|
2021-12-14 16:59:12 +01:00
|
|
|
$targetFolder = $storage->getFolder($this->filesFolder);
|
2021-09-06 15:18:48 +02:00
|
|
|
} catch (FolderDoesNotExistException $e) {
|
2021-12-14 16:59:12 +01:00
|
|
|
$targetFolder = $storage->createFolder($this->filesFolder);
|
2021-09-06 15:18:48 +02:00
|
|
|
}
|
|
|
|
|
2021-12-16 10:00:51 +01:00
|
|
|
$storage->addFile($filename, $targetFolder, basename($fileUrl));
|
2019-08-12 07:43:37 +02:00
|
|
|
} else {
|
2019-08-12 15:49:52 +02:00
|
|
|
$error = true;
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-12 07:43:37 +02:00
|
|
|
|
2019-08-12 15:49:52 +02:00
|
|
|
if ($error !== true) {
|
2021-09-06 16:33:18 +02:00
|
|
|
if ($this->tmpCurrentEvent->getImages()->count() > 0) {
|
2019-08-12 15:49:52 +02:00
|
|
|
$this->logger->info('Relation found');
|
2021-09-07 09:03:02 +02:00
|
|
|
// TODO: How to delete file references?
|
2019-08-12 15:49:52 +02:00
|
|
|
} else {
|
|
|
|
$this->logger->info('No relation found');
|
2021-12-14 16:59:12 +01:00
|
|
|
$fileIdentifier = $this->filesFolder . $orgFileNameSanitized;
|
|
|
|
$file = $storage->getFile($fileIdentifier);
|
|
|
|
if (!$file instanceof File) {
|
|
|
|
$this->logger->warning('Could not find file.', [$fileIdentifier]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->metaDataRepository->update(
|
|
|
|
$file->getUid(),
|
|
|
|
[
|
|
|
|
'title' => $media_object['value'],
|
|
|
|
'description' => $media_object['description'],
|
|
|
|
'alternative' => 'DD Import'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->createFileRelations(
|
|
|
|
$file->getUid(),
|
|
|
|
'tx_events_domain_model_event',
|
|
|
|
$this->tmpCurrentEvent->getUid(),
|
|
|
|
'images',
|
|
|
|
$this->storagePid
|
|
|
|
);
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-12 15:49:52 +02:00
|
|
|
}
|
2019-08-13 11:17:34 +02:00
|
|
|
$error = false;
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 12:28:06 +01:00
|
|
|
private function loadFile(string $fileUrl): string
|
2021-01-07 08:50:43 +01:00
|
|
|
{
|
2021-12-16 10:00:51 +01:00
|
|
|
$this->logger->info('Getting file ' . $fileUrl);
|
|
|
|
|
|
|
|
$file = new \SplFileInfo($fileUrl);
|
|
|
|
$temporaryFilename = GeneralUtility::tempnam($file->getBasename());
|
2021-12-15 12:28:06 +01:00
|
|
|
|
|
|
|
$response = $this->dataFetcher->fetchImage($fileUrl);
|
2021-12-16 10:00:51 +01:00
|
|
|
$fileContent = $response->getBody()->__toString();
|
|
|
|
if ($response->getStatusCode() !== 200) {
|
|
|
|
$this->logger->error('Cannot load file ' . $fileUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GeneralUtility::writeFile($temporaryFilename, $fileContent, true) === false) {
|
|
|
|
$this->logger->error('Could not write temporary file.');
|
|
|
|
return '';
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
2021-12-15 12:28:06 +01:00
|
|
|
|
2021-12-16 10:00:51 +01:00
|
|
|
return $temporaryFilename;
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function createFileRelations(
|
|
|
|
int $uid_local,
|
|
|
|
string $tablenames,
|
|
|
|
int $uid_foreign,
|
|
|
|
string $fieldname,
|
|
|
|
int $storagePid
|
|
|
|
): bool {
|
2019-08-12 07:43:37 +02:00
|
|
|
$newId = 'NEW1234';
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$data['sys_file_reference'][$newId] = array(
|
|
|
|
'table_local' => 'sys_file',
|
|
|
|
'uid_local' => $uid_local,
|
|
|
|
'tablenames' => $tablenames,
|
|
|
|
'uid_foreign' => $uid_foreign,
|
|
|
|
'fieldname' => $fieldname,
|
|
|
|
'pid' => $storagePid
|
|
|
|
);
|
|
|
|
|
|
|
|
$data[$tablenames][$uid_foreign] = array(
|
|
|
|
'pid' => $storagePid,
|
|
|
|
$fieldname => $newId
|
|
|
|
);
|
|
|
|
|
2021-01-07 08:47:15 +01:00
|
|
|
$dataHandler = $this->objectManager->get(DataHandler::class);
|
2019-08-12 07:43:37 +02:00
|
|
|
$dataHandler->start($data, array());
|
|
|
|
$dataHandler->process_datamap();
|
|
|
|
|
|
|
|
if (count($dataHandler->errorLog) === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-13 11:17:34 +02:00
|
|
|
|
2021-01-07 08:50:43 +01:00
|
|
|
foreach ($dataHandler->errorLog as $error) {
|
2019-08-13 11:17:34 +02:00
|
|
|
$this->logger->info($error);
|
|
|
|
}
|
|
|
|
return false;
|
2019-08-12 07:43:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
private function doSlugUpdate(): void
|
2019-08-12 07:43:37 +02:00
|
|
|
{
|
|
|
|
$this->logger->info('Update slugs');
|
|
|
|
|
|
|
|
$slugHelper = GeneralUtility::makeInstance(
|
|
|
|
SlugHelper::class,
|
|
|
|
'tx_events_domain_model_event',
|
|
|
|
'slug',
|
|
|
|
$GLOBALS['TCA']['tx_events_domain_model_event']['columns']['slug']['config']
|
|
|
|
);
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
|
|
|
|
->getConnectionForTable('tx_events_domain_model_event');
|
2019-08-12 07:43:37 +02:00
|
|
|
$queryBuilder = $connection->createQueryBuilder();
|
|
|
|
$queryBuilder->getRestrictions()->removeAll();
|
|
|
|
|
|
|
|
$statement = $queryBuilder->select('uid', 'global_id')
|
|
|
|
->from('tx_events_domain_model_event')
|
|
|
|
->where(
|
|
|
|
$queryBuilder->expr()->orX(
|
|
|
|
$queryBuilder->expr()->eq('slug', $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)),
|
|
|
|
$queryBuilder->expr()->isNull('slug')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
while ($record = $statement->fetch()) {
|
2021-12-14 16:59:12 +01:00
|
|
|
if (is_array($record) === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-12 07:43:37 +02:00
|
|
|
$queryBuilder = $connection->createQueryBuilder();
|
|
|
|
$queryBuilder->update('tx_events_domain_model_event')
|
|
|
|
->where(
|
|
|
|
$queryBuilder->expr()->eq(
|
|
|
|
'uid',
|
|
|
|
$queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->set('slug', $slugHelper->sanitize((string)$record['global_id']));
|
|
|
|
$queryBuilder->getSQL();
|
|
|
|
$queryBuilder->execute();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2021-12-14 16:59:12 +01:00
|
|
|
return (bool) $value;
|
2021-09-07 08:36:48 +02:00
|
|
|
}
|
2019-10-09 15:03:58 +02:00
|
|
|
}
|