#109683Undefined variable "tree" in Expression Language crashes DataHandler during CLI operations on orphaned records
Description
Hello,
When using the TYPO3 DataHandler within a CLI context (e.g., an UpgradeWizard), processing records that are orphaned or reside on non-existent pages leads to a fatal error in the Symfony Expression Language parser. This occurs because the tree object is only initialized if a rootline is successfully determined.
This issue is specifically present when using the global Configuration/page.tsconfig file, as the condition matching logic there does not gracefully handle the absence of the tree variable.
Reproducer
- Define a Page TSconfig condition in Configuration/page.tsconfig:
[916 in tree.rootLineIds] TCEMAIN.clearCacheCmd = 12 [END]
- Execute a DataHandler operation via CLI (e.g., an UpgradeWizard) on a record whose pid does not exist.
- The Symfony Expression Language parser fails because tree is completely missing from the context.
Current Behavior
The parser stops with the following error:
Variable "tree" is not valid around position 1 for expression "916 in tree.rootLineIds".
Because the variable is not registered at all when the rootline is empty, standard null-coalescing (tree ?? …) or optional chaining (tree?.) within the expression does not prevent the crash. This is due to the Symfony Expression Language being evaluated in a mode where unknown variables are not ignored:
if (!($this->flags & self::IGNORE_UNKNOWN_VARIABLES)) { ... }
The only current workaround is a complex and non-intuitive expression:
[916 in traverse((tree ?? {rootLineIds: []}), 'rootLineIds')]
Affected Component
The logic resides in IncludeTreeConditionMatcherVisitor.
The current implementation only adds tree to $enrichedVariables if $localRootLine is not empty:
$localRootLine = $variables['localRootLine'] ?? $fullRootLine;
if (!empty($localRootLine)) {
$tree = new \stdClass();
// ... initialization of $tree
$enrichedVariables['tree'] = $tree;
}
Expected Behavior
The tree variable should be initialized as an empty object or a null-safe entity by the IncludeTreeConditionMatcherVisitor even in CLI or orphaned record contexts. This would allow the use of the null-safe operator (tree?.rootLineIds) or simply return false for the condition without crashing the process.
Stefan