Skip to content

Commit

Permalink
[BUGFIX] Do not reuse DataHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed May 23, 2024
1 parent 85f36eb commit 77bad98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
31 changes: 17 additions & 14 deletions Classes/Controller/AdminModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,24 @@ protected function debugAction(
ServerRequestInterface $request,
ModuleTemplate $view,
): ResponseInterface {
$cmd = $request->getParsedBody()['tx_examples_admin_examples']['cmd'] ?? 'cookies';
switch ($cmd) {
case 'cookies':
$this->debugCookies();
break;
default:
// do something else
$body = $request->getParsedBody();
if (is_array($body)) {
$cmd = $request->getParsedBody()['tx_examples_admin_examples']['cmd'] ?? 'cookies';
switch ($cmd) {
case 'cookies':
$this->debugCookies();
break;
default:
// do something else
}

$view->assignMultiple(
[
'cookies' => $request->getCookieParams(),
'lastcommand' => $cmd,
],
);
}

$view->assignMultiple(
[
'cookies' => $request->getCookieParams(),
'lastcommand' => $cmd,
],
);
return $view->renderResponse('AdminModule/Debug');
}

Expand Down
14 changes: 9 additions & 5 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function __construct(
protected readonly ResourceFactory $resourceFactory,
protected readonly FileRepository $fileRepository,
protected readonly ConnectionPool $connectionPool,
protected readonly DataHandler $dataHandler,
protected readonly TableInformationService $tableInformationService,
private readonly LoggerInterface $logger,
) {}
Expand Down Expand Up @@ -458,10 +457,15 @@ public function fileReferenceCreateAction(
'image' => $newId, // For multiple new references $newId is a comma-separated list
];
// process the data
$this->dataHandler->start($data, []);
$this->dataHandler->process_datamap();

/** @var DataHandler $dataHandler */
// Do not inject or reuse the DataHander as it holds state!
// Do not use `new` as GeneralUtility::makeInstance handles dependencies
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, []);
$dataHandler->process_datamap();
// Error or success reporting
if (count($this->dataHandler->errorLog) === 0) {
if (count($dataHandler->errorLog) === 0) {
$this->addFlashMessage(
LocalizationUtility::translate(
'create_relation_success',
Expand All @@ -470,7 +474,7 @@ public function fileReferenceCreateAction(
'',
);
} else {
foreach ($this->dataHandler->errorLog as $log) {
foreach ($dataHandler->errorLog as $log) {
$this->addFlashMessage(
$log,
LocalizationUtility::translate(
Expand Down

0 comments on commit 77bad98

Please sign in to comment.