Make region optional during import

This commit is contained in:
Daniel Siepmann 2021-12-14 16:22:29 +01:00
parent 29c31375a5
commit 73161fa24e
4 changed files with 21 additions and 16 deletions

View file

@ -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?'
);
}

View file

@ -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));

View file

@ -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.

View file

@ -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