Issue Bug Closed

#88118Loose reference while remove items from a tree based on a callback in PageTreeRepository

Steve Lenz 04/09/19, 10:54 updated 06/06/24, 09:59

Description

Hook “$GLOBALS[‘TYPO3_CONF_VARS’][‘SC_OPTIONS’][‘t3lib/class.t3lib_userauthgroup.php’][‘calcPerms’]” in BackendUserAuthentication has no effect.

The bug is in PageTreeRepository::applyCallbackToChildren in line 145:

/**
     * Removes items from a tree based on a callback, usually used for permission checks
     *
     * @param array $tree
     * @param callable $callback
     */
    protected function applyCallbackToChildren(array &$tree, callable $callback)
    {
        if (!isset($tree['_children'])) {
            return;
        }
        foreach ($tree['_children'] as $k => $childPage) {
            if (!call_user_func_array($callback, [$childPage])) {
                unset($tree['_children'][$k]);
                continue;
            }
            $this->applyCallbackToChildren($childPage, $callback);
        }
    }

The unset does not effect on _children array, because the iteration ignores the reference.

The solution to set reference for $childPage:

foreach ($tree['_children'] as $k => &$childPage) {
...
}

Reviews 2

Linked, but not in Forger: Change 60425

History 35

  1. Gerrit Code Review pushed patch set 1 for master to change 60425 status New Under Review 04/09/19, 11:22

  2. Oliver Hader changed Duplicated by #88257 05/02/19, 15:50

  3. Susanne Moog commented and changed status Under Review Closed 01/15/20, 16:56

    This has been fixed with 9.5.6 and v10 (see https://review.typo3.org/c/Packages/TYPO3.CMS/+/60701).

  4. Gerrit Code Review pushed patch set 2 for master to change 60425 status Closed Under Review 05/03/23, 09:15

  5. Riccardo De Contardi commented and changed status Under Review Closed removed the assignee 06/06/24, 09:59

    This has been already fixed; I therefore close it

    If you think that this is the wrong decision or experience the issue again please reopen it or open a new issue with a reference to this one.

    Thank you