Bug #106655
openpasteDataMap overridden for each command in DataHandler::process_cmdmap
0%
Description
The `$pasteDataMap` is initialized as array before iterating the whole `$this->cmdmap`. However inside the third nested `foreach`, that iterates over the actual commands array, the `$pasteDataMap` is initialized once more.
This leads to all data set during processing of previous commands, to be lost. Therefore only the data from the last command is available after the whole command map has been processed.
I don't know, if this is reproducable with a standard TYPO3 installation, because I'm not sure, if there actually is a way to trigger multiple move or copy commands, with additional update data, that would trigger this bug. I found it, with an upgrade wizard, that would use the data handler to save the changes, made to the records. In my case, I was moving multiple content elements into a container element, which get the container parent and colPos data to be updated after the move.
The extra line has been introduced with https://review.typo3.org/c/Packages/TYPO3.CMS/+/86773.
Updated by Georg Ringer 14 days ago
- Related to Bug #89787: Copying element with IRRE element from one language to another added
Updated by Gerrit Code Review 13 days ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89309
Updated by Stefan Bürk 13 days ago
@Thorben Nissen Thanks for the report.
However, the repost states "what is wished to do", but does miss to describe what the "bug"
is and how it can reproduced to verify that a code change does what is intended.
Updated by Thorben Nissen 13 days ago
@Stefan Bürk Thanks for pointing this out. I tried to improve the description to make it clearer what the actual bug is and how I could reproduce it.
Updated by Gerrit Code Review 13 days ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89309
Updated by Astrid Haubold 12 days ago
· Edited
Ok, I could reproduce the issue:
Steps to reproduce:
copy 2 simple content elements using DataHandler directly with only one command map.
Example code :
$commandMap = [
'tt_content' => [
19 => [
'copy' => [
'action' => 'paste',
'target' => 170,
'update' => [
'colPos' => 3
],
]
],
18 => [
'copy' => [
'action' => 'paste',
'target' => 170,
'update' => [
'colPos' => 3
],
]
],
],
];
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$backendUser = $GLOBALS['BE_USER'];
if (isset($backendUser->uc['copyLevels'])) {
$dataHandler->copyTree = $backendUser->uc['copyLevels'];
}
$dataHandler->start([], $commandMap);
$dataHandler->process_cmdmap();
Expected behavior: both elements receive colPos 3.
Actual behavior: only the second element receives colPos 3
Reason seems to be that the actual update with the values from $pasteDatamap happens in a separate DataHandler call for all records at once after the whole command map has been processed :
$copyTCE = $this->getLocalTCE();
$copyTCE->start($pasteDatamap, [], $this->BE_USER, $this->referenceIndexUpdater);
$copyTCE->process_datamap();