Skip to content

Commit 6f036b2

Browse files
committed
[TASK] Fix recursive copying to different PID
1 parent 0048a6c commit 6f036b2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Classes/Integration/HookSubscribers/DataHandlerSubscriber.php

+17-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function processDatamap_afterDatabaseOperations($command, $table, $id, $f
5959
(int)$mostRecentCopyOfParentRecord['uid'],
6060
$localColumnPosition
6161
);
62-
$reference->updateDB($table, $newRecordUid, ['colPos' => $newColumnPosition]);
62+
$reference->updateDB($table, $newRecordUid, ['colPos' => $newColumnPosition, 'pid' => $mostRecentCopyOfParentRecord['pid']]);
6363
}
6464
}
6565
}
@@ -162,7 +162,7 @@ public function processCmdmap_postProcess(&$command, $table, $id, &$relativeTo,
162162
list ($originalRecord, $recordsToCopy) = $this->getParentAndRecordsNestedInGrid(
163163
$table,
164164
(int)$id,
165-
'uid, colPos'
165+
'uid, pid, colPos'
166166
);
167167

168168
if (empty($recordsToCopy)) {
@@ -171,23 +171,30 @@ public function processCmdmap_postProcess(&$command, $table, $id, &$relativeTo,
171171

172172
$languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
173173

174+
if ($relativeTo > 0) {
175+
$destinationPid = $relativeTo;
176+
} else {
177+
$relativeRecord = $this->getSingleRecordWithoutRestrictions($table, abs($relativeTo), 'pid');
178+
$destinationPid = $relativeRecord['pid'] ?? $relativeTo;
179+
}
174180

175181
foreach ($recordsToCopy as $recordToCopy) {
176182
$languageUid = (int) ($reference->cmdmap[$table][$id][$command]['update'][$languageField] ?? $recordToCopy[$languageField]);
177183
$newChildUid = $reference->copyRecord(
178184
$table,
179185
$recordToCopy['uid'],
180-
$originalRecord['pid'],
186+
$destinationPid,
181187
true,
182188
[
183189
$languageField => $languageUid,
184190
'colPos' => ColumnNumberUtility::calculateColumnNumberForParentAndColumn(
185191
$reference->copyMappingArray[$table][$id],
186192
ColumnNumberUtility::calculateLocalColumnNumber($recordToCopy['colPos'])
187-
)
193+
),
194+
'pid' => $destinationPid
188195
]
189196
);
190-
$this->recursivelyCopyChildRecords($table, $recordToCopy['uid'], $newChildUid, $languageUid, $reference);
197+
$this->recursivelyCopyChildRecords($table, $recordToCopy['uid'], $newChildUid, $destinationPid, $languageUid, $reference);
191198
}
192199
}
193200

@@ -199,7 +206,7 @@ public function clearCacheCommand($command)
199206
{
200207
}
201208

202-
protected function recursivelyCopyChildRecords(string $table, int $parentUid, int $newParentUid, int $languageUid, DataHandler $dataHandler)
209+
protected function recursivelyCopyChildRecords(string $table, int $parentUid, int $newParentUid, int $pageUid, int $languageUid, DataHandler $dataHandler)
203210
{
204211
list ($originalRecord, $recordsToCopy) = $this->getParentAndRecordsNestedInGrid(
205212
$table,
@@ -217,17 +224,18 @@ protected function recursivelyCopyChildRecords(string $table, int $parentUid, in
217224
$newChildUid = $dataHandler->copyRecord(
218225
$table,
219226
$recordToCopy['uid'],
220-
$originalRecord['pid'],
227+
$pageUid,
221228
true,
222229
[
223230
$languageField => $languageUid,
224231
'colPos' => ColumnNumberUtility::calculateColumnNumberForParentAndColumn(
225232
$newParentUid,
226233
ColumnNumberUtility::calculateLocalColumnNumber($recordToCopy['colPos'])
227-
)
234+
),
235+
'pid' => $pageUid
228236
]
229237
);
230-
$this->recursivelyCopyChildRecords($table, $recordToCopy['uid'], $newChildUid, $languageUid, $dataHandler);
238+
$this->recursivelyCopyChildRecords($table, $recordToCopy['uid'], $newChildUid, $pageUid, $languageUid, $dataHandler);
231239
}
232240
}
233241

0 commit comments

Comments
 (0)