Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Do not reuse DataHandler #275

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
linawolf marked this conversation as resolved.
Show resolved Hide resolved
if (is_array($body)) {
$cmd = $body['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
Loading