From 73161fa24e1f3e2d08e6005c53e3652462384569 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 14 Dec 2021 16:22:29 +0100 Subject: [PATCH] Make region optional during import --- .../Command/DestinationDataImportCommand.php | 18 +++++++----------- .../Service/DestinationDataImportService.php | 14 ++++++++++---- Documentation/Changelog/2.1.0.rst | 3 +++ phpstan-baseline.neon | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Classes/Command/DestinationDataImportCommand.php b/Classes/Command/DestinationDataImportCommand.php index db22734..d7da7b7 100644 --- a/Classes/Command/DestinationDataImportCommand.php +++ b/Classes/Command/DestinationDataImportCommand.php @@ -30,27 +30,23 @@ class DestinationDataImportCommand extends Command $this->addArgument( 'storage-pid', - InputArgument::OPTIONAL, - 'What is the storage pid?', - '6' + InputArgument::REQUIRED, + 'What is the storage pid?' ); $this->addArgument( 'region-uid', InputArgument::OPTIONAL, - 'What is the region uid?', - '1' + 'What is the region uid?' ); $this->addArgument( 'rest-experience', - InputArgument::OPTIONAL, - 'What is the rest experience?', - 'stadtmarketing-erfurt' + InputArgument::REQUIRED, + 'What is the rest experience?' ); $this->addArgument( 'files-folder', - InputArgument::OPTIONAL, - 'Where to save the image files?', - 'staedte/erfurt/events/' + InputArgument::REQUIRED, + 'Where to save the image files?' ); } diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index 1a7a1f3..f05376b 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -23,6 +23,7 @@ use Wrm\Events\Domain\Model\Category; use Wrm\Events\Domain\Model\Date; use Wrm\Events\Domain\Model\Event; use Wrm\Events\Domain\Model\Organizer; +use Wrm\Events\Domain\Model\Region; use Wrm\Events\Domain\Repository\CategoryRepository; use Wrm\Events\Domain\Repository\DateRepository; use Wrm\Events\Domain\Repository\EventRepository; @@ -72,7 +73,7 @@ class DestinationDataImportService private $storagePid; /** - * @var int + * @var ?int */ private $regionUid; @@ -221,7 +222,7 @@ class DestinationDataImportService public function import( string $restExperience, int $storagePid, - int $regionUid, + ?int $regionUid, string $filesFolder ): int { $this->restExperience = $restExperience; @@ -279,7 +280,10 @@ class DestinationDataImportService $this->logger->info('Processing json ' . count($data['items'])); // Get selected region - $selectedRegion = $this->regionRepository->findByUid($this->regionUid); + $selectedRegion = null; + if (is_int($this->regionUid)) { + $selectedRegion = $this->regionRepository->findByUid($this->regionUid); + } foreach ($data['items'] as $event) { $this->logger->info('Processing event ' . substr($event['title'], 0, 20)); @@ -291,7 +295,9 @@ class DestinationDataImportService $this->tmpCurrentEvent->setLanguageUid(-1); // Set selected Region - $this->tmpCurrentEvent->setRegion($selectedRegion); + if ($selectedRegion instanceof Region) { + $this->tmpCurrentEvent->setRegion($selectedRegion); + } // Set Title $this->tmpCurrentEvent->setTitle(substr($event['title'], 0, 254)); diff --git a/Documentation/Changelog/2.1.0.rst b/Documentation/Changelog/2.1.0.rst index 9b0db77..076f037 100644 --- a/Documentation/Changelog/2.1.0.rst +++ b/Documentation/Changelog/2.1.0.rst @@ -9,6 +9,9 @@ Nothing Features -------- +* ``region-uid`` of ``DestinationDataImportCommand`` is now optional. + No region will be fetched and assigned to Events if no uid is provided. + * ``DateDemandFactory`` supports TypoScript ``stdWrap`` on all settings on first level. * New option ``queryCallback`` for ``DateDemand`` was added. diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b8a064b..4bc2c8f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11,7 +11,7 @@ parameters: path: Classes/Command/DestinationDataImportCommand.php - - message: "#^Parameter \\#3 \\$regionUid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int, mixed given\\.$#" + message: "#^Parameter \\#3 \\$regionUid of method Wrm\\\\Events\\\\Service\\\\DestinationDataImportService\\:\\:import\\(\\) expects int\\|null, mixed given\\.$#" count: 1 path: Classes/Command/DestinationDataImportCommand.php