mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-22 07:56:10 +01:00
Refactored the import command
This commit is contained in:
parent
9ebe9a4751
commit
a16b5d4ef7
4 changed files with 296 additions and 276 deletions
12
Classes/Command/ImportCommand.php
Normal file
12
Classes/Command/ImportCommand.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
namespace Wrm\Events\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
|
||||||
|
class ImportCommand extends Command {
|
||||||
|
// Just to prevent scheduler from breaking
|
||||||
|
}
|
|
@ -180,7 +180,7 @@ class CleanupService {
|
||||||
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
|
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
|
||||||
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
|
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
|
||||||
'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
|
'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
|
||||||
'logFile' => 'typo3temp/logs/events_importcleanup'
|
'logFile' => 'typo3temp/logs/events_cleanup'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Wrm\Events\Service;
|
namespace Wrm\Events\Service;
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Core\Environment;
|
||||||
use TYPO3\CMS\Core\Resource\FileRepository;
|
use TYPO3\CMS\Core\Resource\FileRepository;
|
||||||
use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
|
use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
|
||||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||||
|
@ -70,6 +71,10 @@ class DestinationDataImportService {
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $settings = [];
|
protected $settings = [];
|
||||||
|
/*
|
||||||
|
* @var
|
||||||
|
*/
|
||||||
|
protected $enviroment;
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
|
@ -136,6 +141,7 @@ class DestinationDataImportService {
|
||||||
* @param PersistenceManager $persistenceManager
|
* @param PersistenceManager $persistenceManager
|
||||||
* @param ResourceFactory $resourceFactory
|
* @param ResourceFactory $resourceFactory
|
||||||
* @param ObjectManager $objectManager
|
* @param ObjectManager $objectManager
|
||||||
|
* @param Environment $environment
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EventRepository $eventRepository,
|
EventRepository $eventRepository,
|
||||||
|
@ -148,7 +154,8 @@ class DestinationDataImportService {
|
||||||
ConfigurationManager $configurationManager,
|
ConfigurationManager $configurationManager,
|
||||||
PersistenceManager $persistenceManager,
|
PersistenceManager $persistenceManager,
|
||||||
ResourceFactory $resourceFactory,
|
ResourceFactory $resourceFactory,
|
||||||
ObjectManager $objectManager
|
ObjectManager $objectManager,
|
||||||
|
Environment $environment
|
||||||
) {
|
) {
|
||||||
$this->eventRepository = $eventRepository;
|
$this->eventRepository = $eventRepository;
|
||||||
$this->regionRepository = $regionRepository;
|
$this->regionRepository = $regionRepository;
|
||||||
|
@ -161,6 +168,7 @@ class DestinationDataImportService {
|
||||||
$this->persistenceManager = $persistenceManager;
|
$this->persistenceManager = $persistenceManager;
|
||||||
$this->resourceFactory = $resourceFactory;
|
$this->resourceFactory = $resourceFactory;
|
||||||
$this->objectManager = $objectManager;
|
$this->objectManager = $objectManager;
|
||||||
|
$this->environment = $environment;
|
||||||
|
|
||||||
// Get Typoscript Settings
|
// Get Typoscript Settings
|
||||||
$this->settings = $this->configurationManager->getConfiguration(
|
$this->settings = $this->configurationManager->getConfiguration(
|
||||||
|
@ -175,31 +183,6 @@ class DestinationDataImportService {
|
||||||
$this->restType = $this->settings['destinationData']['restType'];
|
$this->restType = $this->settings['destinationData']['restType'];
|
||||||
$this->restLimit = $this->settings['destinationData']['restLimit'];
|
$this->restLimit = $this->settings['destinationData']['restLimit'];
|
||||||
$this->restTemplate = $this->settings['destinationData']['dataTemplate'];
|
$this->restTemplate = $this->settings['destinationData']['dataTemplate'];
|
||||||
|
|
||||||
// Set storage pid
|
|
||||||
$frameworkConfiguration = $this->configurationManager->getConfiguration(
|
|
||||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
|
|
||||||
);
|
|
||||||
|
|
||||||
$persistenceConfiguration = [
|
|
||||||
'persistence' => [
|
|
||||||
'storagePid' => $this->storagePid,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
|
|
||||||
|
|
||||||
// Init Logger
|
|
||||||
// Nötig, damit logger arbeitet?
|
|
||||||
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
|
|
||||||
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
|
|
||||||
'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
|
|
||||||
'logFile' => 'typo3temp/logs/events_import.log'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
|
|
||||||
$this->logger->info('Starting Destination Data Import Service');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,6 +200,34 @@ class DestinationDataImportService {
|
||||||
$this->categoryParentUid = $categoryParentUid;
|
$this->categoryParentUid = $categoryParentUid;
|
||||||
$this->filesFolder = $filesFolder;
|
$this->filesFolder = $filesFolder;
|
||||||
|
|
||||||
|
// Get configuration
|
||||||
|
$frameworkConfiguration = $this->configurationManager->getConfiguration(
|
||||||
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set storage pid
|
||||||
|
$persistenceConfiguration = [
|
||||||
|
'persistence' => [
|
||||||
|
'storagePid' => $this->storagePid,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Set Configuration
|
||||||
|
$this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration));
|
||||||
|
|
||||||
|
// Init Logger
|
||||||
|
// Nötig, damit logger arbeitet?
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
|
||||||
|
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
|
||||||
|
'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
|
||||||
|
'logFile' => 'typo3temp/logs/events_import.log'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
|
||||||
|
$this->logger->info('Starting Destination Data Import Service');
|
||||||
|
|
||||||
$restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate;
|
$restUrl = $this->restUrl . '?experience=' . $this->restExperience . '&licensekey=' . $this->restLicenseKey . '&type=' . $this->restType . '&limit=' . $this->restLimit . '&template=' . $this->restTemplate;
|
||||||
|
|
||||||
$this->logger->info('Try to get data from ' . $restUrl);
|
$this->logger->info('Try to get data from ' . $restUrl);
|
||||||
|
@ -241,72 +252,151 @@ class DestinationDataImportService {
|
||||||
$selectedRegion = $this->regionRepository->findByUid($this->regionUid);
|
$selectedRegion = $this->regionRepository->findByUid($this->regionUid);
|
||||||
|
|
||||||
foreach ($data['items'] as $event) {
|
foreach ($data['items'] as $event) {
|
||||||
|
|
||||||
$this->logger->info('Processing event ' . substr($event['title'], 0, 20));
|
$this->logger->info('Processing event ' . substr($event['title'], 0, 20));
|
||||||
|
|
||||||
// Event already exists ?
|
// Event already exists? If not create one!
|
||||||
$this->tmpCurrentEvent = $this->eventRepository->findOneByGlobalId($event['global_id']);
|
$this->tmpCurrentEvent = $this->getOrCreateEvent($event['global_id'], $event['title']);
|
||||||
|
|
||||||
if (!$this->tmpCurrentEvent)
|
|
||||||
{
|
|
||||||
$this->logger->info(substr($event['title'], 0, 20) . ' does not exist');
|
|
||||||
$this->tmpCurrentEvent = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Event');
|
|
||||||
|
|
||||||
// Create event and persist
|
|
||||||
$this->tmpCurrentEvent->setGlobalId($event['global_id']);
|
|
||||||
$this->tmpCurrentEvent->setCategories(new ObjectStorage());
|
|
||||||
$this->eventRepository->add($this->tmpCurrentEvent);
|
|
||||||
$this->persistenceManager->persistAll();
|
|
||||||
|
|
||||||
$this->logger->info('Not found "' . substr($event['title'], 0, 20) . '..." with global id ' . $event['global_id'] . ' in database. Created new one.');
|
|
||||||
} else {
|
|
||||||
// Global ID is found and events gets updated
|
|
||||||
$this->tmpCurrentEvent = $this->eventRepository->findOneByGlobalId($event['global_id']);
|
|
||||||
//$this->currentEventIsNew = FALSE;
|
|
||||||
$this->logger->info('Found "' . substr($event['title'], 0, 20) . '..." with global id ' . $event['global_id'] . ' in database');
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Set selected Region
|
// Set selected Region
|
||||||
$this->tmpCurrentEvent->setRegion($selectedRegion);
|
$this->tmpCurrentEvent->setRegion($selectedRegion);
|
||||||
|
|
||||||
////////////
|
|
||||||
// Set Title
|
// Set Title
|
||||||
$this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254));
|
$this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254));
|
||||||
|
|
||||||
//////////////////////////////////////////////
|
|
||||||
// Set Highlight (Is only set in rest if true)
|
// Set Highlight (Is only set in rest if true)
|
||||||
if($event['highlight'])
|
if($event['highlight'])
|
||||||
$this->tmpCurrentEvent->setHighlight($event['highlight']);
|
$this->tmpCurrentEvent->setHighlight($event['highlight']);
|
||||||
|
|
||||||
////////////
|
|
||||||
// Set Texts
|
// Set Texts
|
||||||
foreach ($event['texts'] as $text)
|
$this->setTexts($event['texts']);
|
||||||
{
|
|
||||||
if ($text['rel'] == "details" && $text['type'] == "text/plain") {
|
|
||||||
$this->tmpCurrentEvent->setDetails($text['value']);
|
|
||||||
}
|
|
||||||
if ($text['rel'] == "teaser" && $text['type'] == "text/plain") {
|
|
||||||
$this->tmpCurrentEvent->setTeaser($text['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////
|
// Set address and geo data
|
||||||
// Set Address
|
$this->setAddress($event['street'], $event['city'], $event['zip'], $event['country'], $event['geo']['main']['latitude'], $event['geo']['main']['longitude']);
|
||||||
$this->tmpCurrentEvent->setStreet($event['street']);
|
|
||||||
$this->tmpCurrentEvent->setCity($event['city']);
|
|
||||||
$this->tmpCurrentEvent->setZip($event['zip']);
|
|
||||||
$this->tmpCurrentEvent->setCountry($event['country']);
|
|
||||||
|
|
||||||
//////////
|
|
||||||
// Set Geo
|
|
||||||
$this->tmpCurrentEvent->setLatitude($event['geo']['main']['latitude']);
|
|
||||||
$this->tmpCurrentEvent->setLongitude($event['geo']['main']['longitude']);
|
|
||||||
|
|
||||||
////////////////
|
|
||||||
// Set Organizer
|
// Set Organizer
|
||||||
|
$this->setOrganizer($event['addresses']);
|
||||||
|
|
||||||
$tmpOrganizer = FALSE;
|
// Set Dates
|
||||||
foreach ($event['addresses'] as $address)
|
$this->setDates($event['timeIntervals']);
|
||||||
|
|
||||||
|
// Set Assets
|
||||||
|
$this->setAssets($event['media_objects']);
|
||||||
|
|
||||||
|
// Update and persist
|
||||||
|
$this->logger->info('Persist database');
|
||||||
|
$this->eventRepository->update($this->tmpCurrentEvent);
|
||||||
|
$this->persistenceManager->persistAll();
|
||||||
|
|
||||||
|
}
|
||||||
|
$this->doSlugUpdate();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $timeIntervals
|
||||||
|
*/
|
||||||
|
protected function setDates(Array $timeIntervals) {
|
||||||
|
|
||||||
|
// TODO: does not seem to work -->
|
||||||
|
//$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->logger->info('Delete ' . $currentDate->getStart()->format('Y-m-d'));
|
||||||
|
$this->dateRepository->remove($currentDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = new \DateTime();
|
||||||
|
$now = $now->getTimestamp();
|
||||||
|
|
||||||
|
foreach ($timeIntervals as $date) {
|
||||||
|
|
||||||
|
// Check if dates are given as interval or not
|
||||||
|
if (empty($date['interval'])) {
|
||||||
|
|
||||||
|
if (strtotime($date['start']) > $now) {
|
||||||
|
$this->logger->info('Setup single date');
|
||||||
|
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\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'));
|
||||||
|
$dateObj->setStart($start);
|
||||||
|
$dateObj->setEnd($end);
|
||||||
|
$this->tmpCurrentEvent->addDate($dateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
if ($date['freq'] == 'Daily' && empty($date['weekdays'])) {
|
||||||
|
|
||||||
|
$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']));
|
||||||
|
for($i = strtotime($start->format('l'), $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 day', $i)) {
|
||||||
|
if ($i > $now) {
|
||||||
|
$eventStart = new \DateTime();
|
||||||
|
$eventStart->setTimestamp($i);
|
||||||
|
$eventStart->setTime($start->format('H'), $start->format('i'));
|
||||||
|
$eventEnd = new \DateTime();
|
||||||
|
$eventEnd->setTimestamp($i);
|
||||||
|
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
||||||
|
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Date');
|
||||||
|
$dateObj->setStart($eventStart);
|
||||||
|
$dateObj->setEnd($eventEnd);
|
||||||
|
$this->tmpCurrentEvent->addDate($dateObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ($date['freq'] == 'Weekly' && !empty($date['weekdays'])) {
|
||||||
|
|
||||||
|
foreach ($date['weekdays'] as $day) {
|
||||||
|
|
||||||
|
$this->logger->info('Setup weekly interval dates for ' . $day);
|
||||||
|
$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']));
|
||||||
|
|
||||||
|
for($i = strtotime($day, $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 week', $i)) {
|
||||||
|
if ($i > $now) {
|
||||||
|
$eventStart = new \DateTime();
|
||||||
|
$eventStart->setTimestamp($i);
|
||||||
|
$eventStart->setTime($start->format('H'), $start->format('i'));
|
||||||
|
$eventEnd = new \DateTime();
|
||||||
|
$eventEnd->setTimestamp($i);
|
||||||
|
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
||||||
|
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Date');
|
||||||
|
$dateObj->setStart($eventStart);
|
||||||
|
$dateObj->setEnd($eventEnd);
|
||||||
|
$this->tmpCurrentEvent->addDate($dateObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $addresses
|
||||||
|
*/
|
||||||
|
protected function setOrganizer(Array $addresses) {
|
||||||
|
foreach ($addresses as $address)
|
||||||
{
|
{
|
||||||
if ($address['rel'] == "organizer") {
|
if ($address['rel'] == "organizer") {
|
||||||
$tmpOrganizer = $this->organizerRepository->findOneByName($address['name']);
|
$tmpOrganizer = $this->organizerRepository->findOneByName($address['name']);
|
||||||
|
@ -329,153 +419,85 @@ class DestinationDataImportService {
|
||||||
} else {
|
} else {
|
||||||
$this->tmpCurrentEvent->setOrganizer($tmpOrganizer);
|
$this->tmpCurrentEvent->setOrganizer($tmpOrganizer);
|
||||||
}
|
}
|
||||||
$tmpOrganizer = FALSE;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
/**
|
||||||
// Set Dates
|
* @param string $street
|
||||||
|
* @param string $city
|
||||||
// TODO: does not seem to work -->
|
* @param string $zip
|
||||||
//$currentEventDates = $this->tmpCurrentEvent->getDates();
|
* @param string $country
|
||||||
//$this->tmpCurrentEvent->removeAllDates($currentEventDates);
|
* @param string $lat
|
||||||
// <--
|
* @param string $lng
|
||||||
|
*/
|
||||||
// TODO: Workaround delete dates
|
protected function setAddress(String $street, String $city, String $zip, String $country, String $lat, String $lng) {
|
||||||
$currentEventDates = $this->tmpCurrentEvent->getDates();
|
$this->tmpCurrentEvent->setStreet($street);
|
||||||
$this->logger->info('Found ' . count($currentEventDates) . ' to delete');
|
$this->tmpCurrentEvent->setCity($city);
|
||||||
|
$this->tmpCurrentEvent->setZip($zip);
|
||||||
foreach ($currentEventDates as $currentDate) {
|
$this->tmpCurrentEvent->setCountry($country);
|
||||||
//$this->logger->info('Delete ' . $currentDate->getStart()->format('Y-m-d'));
|
$this->tmpCurrentEvent->setLatitude($lat);
|
||||||
$this->dateRepository->remove($currentDate);
|
$this->tmpCurrentEvent->setLongitude($lng);
|
||||||
}
|
}
|
||||||
|
|
||||||
$now = new \DateTime();
|
/**
|
||||||
$now = $now->getTimestamp();
|
* Set Texts
|
||||||
|
* @param Array $texts
|
||||||
foreach ($event['timeIntervals'] as $date) {
|
*/
|
||||||
|
protected function setTexts(Array $texts) {
|
||||||
// Check if dates are given as interval or not
|
foreach ($texts as $text)
|
||||||
if (empty($date['interval'])) {
|
{
|
||||||
|
if ($text['rel'] == "details" && $text['type'] == "text/plain") {
|
||||||
if (strtotime($date['start']) > $now) {
|
$this->tmpCurrentEvent->setDetails($text['value']);
|
||||||
|
}
|
||||||
$this->logger->info('Setup single date');
|
if ($text['rel'] == "teaser" && $text['type'] == "text/plain") {
|
||||||
//$this->logger->info('Start ' . $date['start']);
|
$this->tmpCurrentEvent->setTeaser($text['value']);
|
||||||
//$this->logger->info('End ' . $date['end']);
|
}
|
||||||
|
}
|
||||||
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\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'));
|
|
||||||
|
|
||||||
$dateObj->setStart($start);
|
|
||||||
$dateObj->setEnd($end);
|
|
||||||
|
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load File
|
||||||
|
* @param String $globalId
|
||||||
|
* @param String $title
|
||||||
|
*/
|
||||||
|
protected function getOrCreateEvent(String $globalId, String $title) {
|
||||||
|
|
||||||
|
$event = $this->eventRepository->findOneByGlobalId($globalId);
|
||||||
|
|
||||||
|
if (!$event)
|
||||||
|
{
|
||||||
|
$this->logger->info(substr($title, 0, 20) . ' does not exist');
|
||||||
|
$event = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Event');
|
||||||
|
|
||||||
|
// Create event and persist
|
||||||
|
$event->setGlobalId($globalId);
|
||||||
|
$event->setCategories(new ObjectStorage());
|
||||||
|
$this->eventRepository->add($event);
|
||||||
|
$this->persistenceManager->persistAll();
|
||||||
|
|
||||||
|
$this->logger->info('Not found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database. Created new one.');
|
||||||
} else {
|
} else {
|
||||||
|
// Global ID is found and events gets updated
|
||||||
|
$event = $this->eventRepository->findOneByGlobalId($globalId);
|
||||||
if ($date['freq'] == 'Daily' && empty($date['weekdays'])) {
|
$this->logger->info('Found "' . substr($title, 0, 20) . '..." with global id ' . $globalId . ' in database');
|
||||||
|
|
||||||
$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']));
|
|
||||||
|
|
||||||
for($i = strtotime($start->format('l'), $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 day', $i)) {
|
|
||||||
|
|
||||||
if ($i > $now) {
|
|
||||||
|
|
||||||
$eventStart = new \DateTime();
|
|
||||||
$eventStart->setTimestamp($i);
|
|
||||||
$eventStart->setTime($start->format('H'), $start->format('i'));
|
|
||||||
|
|
||||||
$eventEnd = new \DateTime();
|
|
||||||
$eventEnd->setTimestamp($i);
|
|
||||||
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
|
||||||
|
|
||||||
//$this->logger->info($eventStart->format('Y-m-d H:i'));
|
|
||||||
//$this->logger->info($eventEnd->format('Y-m-d H:i'));
|
|
||||||
|
|
||||||
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Date');
|
|
||||||
$dateObj->setStart($eventStart);
|
|
||||||
$dateObj->setEnd($eventEnd);
|
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @param array $assets
|
||||||
else if ($date['freq'] == 'Weekly' && !empty($date['weekdays'])) {
|
*/
|
||||||
|
protected function setAssets(Array $assets) {
|
||||||
foreach ($date['weekdays'] as $day) {
|
foreach ($assets as $media_object)
|
||||||
|
|
||||||
$this->logger->info('Setup weekly interval dates for ' . $day);
|
|
||||||
$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']));
|
|
||||||
|
|
||||||
for($i = strtotime($day, $start->getTimestamp()); $i <= $until->getTimestamp(); $i = strtotime('+1 week', $i)) {
|
|
||||||
|
|
||||||
if ($i > $now) {
|
|
||||||
|
|
||||||
$eventStart = new \DateTime();
|
|
||||||
$eventStart->setTimestamp($i);
|
|
||||||
$eventStart->setTime($start->format('H'), $start->format('i'));
|
|
||||||
|
|
||||||
$eventEnd = new \DateTime();
|
|
||||||
$eventEnd->setTimestamp($i);
|
|
||||||
$eventEnd->setTime($until->format('H'), $until->format('i'));
|
|
||||||
|
|
||||||
//$this->logger->info($eventStart->format('Y-m-d H:i'));
|
|
||||||
//$this->logger->info($eventEnd->format('Y-m-d H:i'));
|
|
||||||
|
|
||||||
$dateObj = $this->objectManager->get('Wrm\\Events\\Domain\\Model\\Date');
|
|
||||||
$dateObj->setStart($eventStart);
|
|
||||||
$dateObj->setEnd($eventEnd);
|
|
||||||
$this->tmpCurrentEvent->addDate($dateObj);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////
|
|
||||||
// Set Assets
|
|
||||||
|
|
||||||
$this->resourceFactory = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
|
|
||||||
$this->fileRepository = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\FileRepository');
|
|
||||||
$this->metaDataRepository = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
|
|
||||||
|
|
||||||
foreach ($event['media_objects'] as $media_object)
|
|
||||||
{
|
{
|
||||||
if($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") {
|
if($media_object['rel'] == "default" && $media_object['type'] == "image/jpeg") {
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
$this->storage = $this->resourceFactory->getDefaultStorage();
|
$this->storage = $this->resourceFactory->getDefaultStorage();
|
||||||
|
|
||||||
// Check if file already exists
|
// Check if file already exists
|
||||||
if (file_exists(PATH_site . '/fileadmin/' . $this->filesFolder . strtolower(basename($media_object['url'])))) {
|
if (file_exists($this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder . strtolower(basename($media_object['url'])))) {
|
||||||
$this->logger->info('[NOTICE] File already exists');
|
$this->logger->info('[NOTICE] File already exists');
|
||||||
} else {
|
} else {
|
||||||
$this->logger->info("[NOTICE] File don't exist");
|
$this->logger->info("[NOTICE] File don't exist");
|
||||||
|
@ -503,25 +525,15 @@ class DestinationDataImportService {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update and persist
|
|
||||||
$this->logger->info('Persist database');
|
|
||||||
$this->eventRepository->update($this->tmpCurrentEvent);
|
|
||||||
$this->persistenceManager->persistAll();
|
|
||||||
|
|
||||||
}
|
|
||||||
$this->doSlugUpdate();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load File
|
* Load File
|
||||||
*
|
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function loadFile($file) {
|
protected function loadFile($file) {
|
||||||
$directory = PATH_site . "uploads/tx_Events/";
|
$directory = $this->environment->getPublicPath() . "uploads/tx_Events/";
|
||||||
$filename = basename($file);
|
$filename = basename($file);
|
||||||
$this->logger->info('[INFO] Getting file ' . $file . ' as ' . $filename);
|
$this->logger->info('[INFO] Getting file ' . $file . ' as ' . $filename);
|
||||||
$asset = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($file);
|
$asset = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($file);
|
||||||
|
@ -530,7 +542,6 @@ class DestinationDataImportService {
|
||||||
$fp = fopen($directory . $filename, 'w');
|
$fp = fopen($directory . $filename, 'w');
|
||||||
fputs($fp, $asset);
|
fputs($fp, $asset);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
$this->logger->info('[ERROR] cannot load file ' . $file);
|
$this->logger->info('[ERROR] cannot load file ' . $file);
|
||||||
|
@ -539,7 +550,6 @@ class DestinationDataImportService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build relations for FAL
|
* Build relations for FAL
|
||||||
*
|
|
||||||
* @param int $uid_local
|
* @param int $uid_local
|
||||||
* @param string $tablenames
|
* @param string $tablenames
|
||||||
* @param int $uid_foreign
|
* @param int $uid_foreign
|
||||||
|
@ -582,7 +592,6 @@ class DestinationDataImportService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs slug update
|
* Performs slug update
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function doSlugUpdate()
|
protected function doSlugUpdate()
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
TYPO3_CONTEXT=Production/Staging /usr/local/bin/php7.1.6-cli typo3cms/stage.thueringer-staedte.de/current/vendor/bin/typo3 events:import
|
TYPO3_CONTEXT=Production/Staging /usr/local/bin/php7.1.6-cli typo3cms/stage.thueringer-staedte.de/current/vendor/bin/typo3 events:import
|
||||||
|
|
||||||
|
|
||||||
##### Clean category relations
|
##### Clean category relations
|
||||||
|
|
||||||
TRUNCATE TABLE tx_events_domain_model_event;
|
TRUNCATE TABLE tx_events_domain_model_event;
|
||||||
|
@ -17,4 +16,4 @@
|
||||||
DELETE FROM sys_category_record_mm WHERE tablenames = 'tx_events_domain_model_event';
|
DELETE FROM sys_category_record_mm WHERE tablenames = 'tx_events_domain_model_event';
|
||||||
DELETE FROM sys_file_reference WHERE tablenames = 'tx_events_domain_model_event';
|
DELETE FROM sys_file_reference WHERE tablenames = 'tx_events_domain_model_event';
|
||||||
DELETE FROM sys_file WHERE identifier LIKE '%/events/%';
|
DELETE FROM sys_file WHERE identifier LIKE '%/events/%';
|
||||||
DELETE FROM sys_file_metadata alternative = 'DD Import';
|
DELETE FROM sys_file_metadata WHERE alternative = 'DD Import';
|
Loading…
Reference in a new issue