Skip to content

Commit

Permalink
Send full reaction record to IMportConfiguration constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sfroemkenjw committed Nov 5, 2024
1 parent 2721023 commit 603b03c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
21 changes: 16 additions & 5 deletions Classes/Configuration/ImportConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -20,19 +22,28 @@ 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
{
return $this->storagePid;
}

public function getPayload(): array
public function getStorageFolder(): string
{
return $this->payload;
return $this->storageFolder;
}
}
19 changes: 1 addition & 18 deletions Classes/Reaction/ImportEventsReaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
}

0 comments on commit 603b03c

Please sign in to comment.