external_import icon indicating copy to clipboard operation
external_import copied to clipboard

Bug: tceDeleteCommands Overwritten When Deleting Multiple Child Tables

Open crookoo opened this issue 2 months ago • 1 comments

Description:

When importing records with multiple child relations (e.g., financing, leasing), the deletion commands for child records are not correctly accumulated. Only the last child table’s entries are retained in $tceDeleteCommands, because the variable is overwritten inside the loop.


Current Behavior:

In Cobweb\ExternalImport\Step\StoreDataStep::run():

https://github.com/cobwebch/external_import/blob/ce60fa7567e17103d9f61d866615e0c8d3238464/Classes/Step/StoreDataStep.php#L407-L417

This reinitializes $tceDeleteCommands in every iteration, discarding previously collected delete commands.


Expected Behavior: Delete commands for all child tables should be collected and merged into $tceDeleteCommands.


Proposed Fix:

Replace:

$tceDeleteCommands = [
    $childTable => [],
];

With:

if (!isset($tceDeleteCommands[$childTable])) {
    $tceDeleteCommands[$childTable] = [];
}

This ensures all child table deletions are accumulated properly.


Impact:

  • Child records of earlier child tables (e.g., tx_cartvehicles_domain_model_product_financing) are not deleted when later ones (e.g., leasing) are processed.
  • Leads to stale or orphaned data in the database.
  • Issue only occurs when multiple child tables are involved in a single import.

Environment:

  • TYPO3 v11.5.41
  • external_import 7.3.0 (but in current version still in place)
  • Occurs when using multiple children configurations per parent record

Steps to Reproduce:

  1. Import a record with two child configurations: e.g., financing and leasing.
  2. On the next import, remove the financing data but leave leasing.
  3. Observe: financing entries remain in DB and are not deleted.
  4. Only the leasing delete commands are sent to TCEmain.

Additional Context:

This bug is subtle and not immediately visible unless you debug the $tceDeleteCommands structure during import.

crookoo avatar Nov 07 '25 11:11 crookoo

Thanks for reporting in such a wonderfully detailed way. One reason the bug was not spotted is that having multiple children configuration per import configuration is not officially supported. The current code cannot guarantee a side-effect-free process.

Still, it's worth fixing what you found. I'm not sure when I will get around to it though. Also, I see that you are using version 7.3 and I will not produce a bugfix release for that old version. The fix would go into the 8.x branch.

fsuter avatar Nov 14 '25 16:11 fsuter