From bc5801452b1c73453be122c469ef74dac7611d5f Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 9 Oct 2019 15:03:58 +0200 Subject: [PATCH] [FIX] Fix crazy die error --- .../Command/DestinationDataImportCommand.php | 10 ++--- Classes/Domain/Repository/DateRepository.php | 2 + .../Service/DestinationDataImportService.php | 37 +++++++++---------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Classes/Command/DestinationDataImportCommand.php b/Classes/Command/DestinationDataImportCommand.php index 734e214..5cd0802 100644 --- a/Classes/Command/DestinationDataImportCommand.php +++ b/Classes/Command/DestinationDataImportCommand.php @@ -23,29 +23,29 @@ class DestinationDataImportCommand extends Command { 'storage-pid', InputArgument::OPTIONAL, 'What is the storage pid?', - '281' + '6' ); $this->addArgument( 'region-uid', InputArgument::OPTIONAL, 'What is the region uid?', - '3' + '1' ); $this->addArgument( 'category-parent-uid', InputArgument::OPTIONAL, 'What is the default category parent uid?', - '6' + '52' ); $this->addArgument('rest-experience', InputArgument::OPTIONAL, 'What is the rest experience?', - 'arnstadt' + 'stadtmarketing-erfurt' ); $this->addArgument('files-folder', InputArgument::OPTIONAL, 'Where to save the image files?', - 'redaktion/arnstadt/events/' + 'staedte/erfurt/events/' ); } diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 78f080b..7440753 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -85,6 +85,8 @@ class DateRepository extends \TYPO3\CMS\Extbase\Persistence\Repository $query->lessThanOrEqual('start', $demand->getEnd()) ] ); + } else { + $constraints['untilnow'] = $query->greaterThanOrEqual('start', date("Y-m-d H:i:s")); } if ($demand->getLimit() !== '') { diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index 2e2daa6..8d8f7dd 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -222,16 +222,14 @@ class DestinationDataImportService { // Set Configuration $this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $persistenceConfiguration)); - $this->logger = GeneralUtility::makeInstance(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; - $this->logger->info('Try to get data from ' . $restUrl); if ($jsonResponse = json_decode(file_get_contents($restUrl),true)) { - $this->logger->info('Received data with ' . count($jsonResponse) . 'items'); + $this->logger->info('Received data with ' . count($jsonResponse['items']) . ' items'); return $this->processData($jsonResponse); } else { $this->logger->error('Could not receive data.'); @@ -246,7 +244,9 @@ class DestinationDataImportService { */ public function processData($data) { - // Get seleceted region + $this->logger->info('Processing json ' . count($data['items'])); + + // Get selected region $selectedRegion = $this->regionRepository->findByUid($this->regionUid); foreach ($data['items'] as $event) { @@ -301,10 +301,12 @@ class DestinationDataImportService { } $this->doSlugUpdate(); + $this->logger->info('Finished import'); return 0; } /** + * * @param array $categories */ protected function setCategories(Array $categories) { @@ -331,7 +333,7 @@ class DestinationDataImportService { */ protected function setDates(Array $timeIntervals) { - // TODO: does not seem to work --> + // @TODO: does not seem to work --> //$currentEventDates = $this->tmpCurrentEvent->getDates(); //$this->tmpCurrentEvent->removeAllDates($currentEventDates); // <-- @@ -341,7 +343,6 @@ class DestinationDataImportService { $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); } @@ -367,9 +368,7 @@ class DestinationDataImportService { } 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']); @@ -389,11 +388,9 @@ class DestinationDataImportService { $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']); @@ -416,11 +413,9 @@ class DestinationDataImportService { } } } - } - } - + $this->logger->info('Finished setup dates'); } } @@ -436,9 +431,7 @@ class DestinationDataImportService { $this->tmpCurrentEvent->setOrganizer($tmpOrganizer); continue; } - $tmpOrganizer = $this->objectManager->get(\Wrm\Events\Domain\Model\Organizer::class); - $tmpOrganizer->setName($address['name']); $tmpOrganizer->setCity($address['city']); $tmpOrganizer->setZip($address['zip']); @@ -447,10 +440,8 @@ class DestinationDataImportService { $tmpOrganizer->setWeb($address['web']); $tmpOrganizer->setEmail($address['email']); $tmpOrganizer->setDistrict($address['district']); - $this->organizerRepository->add($tmpOrganizer); $this->tmpCurrentEvent->setOrganizer($tmpOrganizer); - } } } @@ -526,6 +517,8 @@ class DestinationDataImportService { */ protected function setAssets(Array $assets) { + $this->logger->info("Set assets"); + $error = false; foreach ($assets as $media_object) @@ -534,6 +527,11 @@ class DestinationDataImportService { $this->storage = $this->resourceFactory->getDefaultStorage(); + if ($this->storage == null) { + $this->logger->error('No default storage defined. Cancel import.'); + die(); + } + // Check if file already exists if (file_exists($this->environment->getPublicPath() . '/fileadmin/' . $this->filesFolder . strtolower(basename($media_object['url'])))) { $this->logger->info('File already exists'); @@ -632,7 +630,6 @@ class DestinationDataImportService { */ protected function doSlugUpdate() { - $this->logger->info('Update slugs'); $slugHelper = GeneralUtility::makeInstance( @@ -672,4 +669,4 @@ class DestinationDataImportService { return true; } -} \ No newline at end of file +}