diff --git a/Classes/Configuration/ImportConfiguration.php b/Classes/Configuration/ImportConfiguration.php index 07e57636..695406fd 100644 --- a/Classes/Configuration/ImportConfiguration.php +++ b/Classes/Configuration/ImportConfiguration.php @@ -11,6 +11,8 @@ namespace JWeiland\Events2\Configuration; +use TYPO3\CMS\Reactions\Model\ReactionInstruction; + /** * This configuration contains all needed data to start an event2 record import */ @@ -20,10 +22,19 @@ class ImportConfiguration private int $storagePid; - public function __construct(int $storagePid, array $payload) + private string $storageFolder; + + public function __construct(ReactionInstruction $reactionInstruction) { - $this->storagePid = $storagePid; - $this->payload = $payload; + $reactionRecord = $reactionInstruction->toArray(); + $this->payload = $reactionRecord['payload'] ?? []; + $this->storagePid = (int)($reactionRecord['storage_pid'] ?? 0); + $this->storageFolder = $reactionRecord['storage_folder'] ?? ''; + } + + public function getPayload(): array + { + return $this->payload; } public function getStoragePid(): int @@ -31,8 +42,8 @@ public function getStoragePid(): int return $this->storagePid; } - public function getPayload(): array + public function getStorageFolder(): string { - return $this->payload; + return $this->storageFolder; } } diff --git a/Classes/Reaction/ImportEventsReaction.php b/Classes/Reaction/ImportEventsReaction.php index bba72dec..77158698 100644 --- a/Classes/Reaction/ImportEventsReaction.php +++ b/Classes/Reaction/ImportEventsReaction.php @@ -49,19 +49,7 @@ public static function getIconIdentifier(): string public function react(ServerRequestInterface $request, array $payload, ReactionInstruction $reaction): ResponseInterface { $statusData = []; - - $storagePid = $this->getStoragePid($reaction); - - // Early return, if storage PID is 0 - if ($storagePid === 0) { - $statusData['success'] = false; - $statusData['error'] = 'Storage pid can not be empty'; - return $this->jsonResponse($statusData); - } - - $statusData['success'] = $this->jsonImporter->import( - new ImportConfiguration($storagePid, $payload) - ); + $statusData['success'] = $this->jsonImporter->import(new ImportConfiguration($reaction)); if ($statusData['success'] === false) { $statusData['error'] = 'Error while importing events'; @@ -79,9 +67,4 @@ protected function jsonResponse(array $data, int $statusCode = 200): ResponseInt ->withHeader('Content-Type', 'application/json') ->withBody($this->streamFactory->createStream((string)json_encode($data))); } - - protected function getStoragePid(ReactionInstruction $reaction): int - { - return (int)($reaction->toArray()['storage_pid'] ?? 0); - } }