#110193DataHandler::undeleteRecordRelations() cascade fails for foreign_field inline relations
Description
Steps to reproduce
- Configure an inline TCA relation with
foreign_field(standard IRRE pattern), where both parent and child table havedelete => 'deleted'soft-delete. - Add some children to a parent record.
- Delete the parent via DataHandler — the IRRE cascade correctly soft-deletes the children.
- Undelete the parent via DataHandler (
cmd[$table][$uid][undelete] = 1).
Expected
The children are soft-deleted-cascaded back to deleted=0 alongside the parent, mirroring the delete-cascade path in DataHandler::deleteRecord_procFields().
Actual
Only the parent is restored. Children remain deleted=1. No error, no log entry.
Root cause
DataHandler::undeleteRecordRelations() (Classes/DataHandling/DataHandler.php, around line 6093–6098):
$relationHandler->start($value, $foreignTable, '', $uid, $table, $fieldConfig);
$relationHandler->undeleteRecord = true;
foreach ($relationHandler->itemArray as $reference) {
$this->undeleteRecord($reference['table'], (int)$reference['id']);
}
The undeleteRecord flag is set after start() has already been called. Internally start() dispatches to RelationHandler::readForeignField(), which evaluates the flag on line 840:
$useDeleteClause = !$this->undeleteRecord;
At that point undeleteRecord is still false, so $useDeleteClause is true and a DeletedRestriction is added to the QueryBuilder. The SELECT ends up as … WHERE foreign_field = $uid AND deleted = 0, filtering out precisely the soft-deleted children we want to restore. $itemArray is empty, the following foreach is a no-op.
Setting undeleteRecord = true afterwards has no effect since the query is already gone.
The todo comment on line 6075 (“Add functional test undelete coverage to verify details, some details seem to be missing.”@) suggests this path has been under-tested.
Proposed fix
Move the undeleteRecord = true assignment before start():
$relationHandler = $this->createRelationHandlerInstance();
$relationHandler->undeleteRecord = true;
$relationHandler->start($value, $foreignTable, '', $uid, $table, $fieldConfig);
foreach ($relationHandler->itemArray as $reference) {
$this->undeleteRecord($reference['table'], (int)$reference['id']);
}
undeleteRecord() itself is idempotent — line 5948 early-returns for records with deleted === false — so accidentally loading a live child (if any) is harmless.
Same fix should be applied to the FlexForm branch around line 6108 if the equivalent path is added there (currently a @todo).
Environment
- TYPO3 14.3.4
- PHP 8.4
- Reproducer setup: parent table without
versioningWS, child table withoutversioningWS, standard inlineforeign_fieldrelation, user in Live workspace.
Reviews 2
History 24
-
Gerrit Code Review pushed patch set 1 for main to change 94775 status
NewUnder Review <span data-processor="relativetime" data-value="2026-07-14T09:28:58+00:00" > 07/14/26, 09:28 </span> -
Gerrit Code Review pushed patch set 1 for 14.3 to change 94932 <span data-processor="relativetime" data-value="2026-07-24T15:34:14+00:00" > 07/24/26, 15:34 </span>
-
Kay Wienöbst commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-07-24T15:40:12+00:00" > 07/24/26, 15:40 </span> -
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2026-08-11T08:51:04+00:00" > 08/11/26, 08:51 </span>
Applied in changeset commit:b7e7c0ba92719517743e636e705613ed829ccb48.