From c9d8fd9eafd8f4cd2b2d504798af6658c436898b Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Thu, 9 Sep 2021 13:58:50 +0200
Subject: [PATCH] [BUGFIX] Avoid trigger_error for "rootUid" related methods

In #95037 the "rootUid" option has been deprecated
in favour of "startingPoints", which now allows to add
multiple root nodes for a tree.

However, for backwards compatibility, the "rootUid"
option is still used in core. The corresponding setter
and getter methods should therefore not trigger a
deprecation log entry. Extension scanner still finds
usages in extension code as weak match.

Resolves: #95163
Related: #95037
Releases: master
Change-Id: I6a974861949dfc2163a93e2e4fc60f27caafc7c2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70982
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
---
 .../backend/Classes/Security/CategoryPermissionsAspect.php   | 1 +
 .../Tree/TableConfiguration/DatabaseTreeDataProvider.php     | 3 +--
 .../11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.rst  | 5 ++---
 .../Configuration/ExtensionScanner/Php/MethodCallMatcher.php | 4 ++--
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Security/CategoryPermissionsAspect.php b/typo3/sysext/backend/Classes/Security/CategoryPermissionsAspect.php
index 04bdaa422c47..6da3e57f3550 100644
--- a/typo3/sysext/backend/Classes/Security/CategoryPermissionsAspect.php
+++ b/typo3/sysext/backend/Classes/Security/CategoryPermissionsAspect.php
@@ -78,6 +78,7 @@ final class CategoryPermissionsAspect
             $treeNodeCollection = $treeData->getChildNodes();
 
             if (!empty($categoryMountPoints) && !empty($treeNodeCollection)) {
+                // @deprecated Remove merging of $dataProvider->getRootUid() in v12
                 $startingPoints = array_unique(array_merge($dataProvider->getStartingPoints(), [$dataProvider->getRootUid()]));
                 $shallRepopulateTree = false;
 
diff --git a/typo3/sysext/core/Classes/Tree/TableConfiguration/DatabaseTreeDataProvider.php b/typo3/sysext/core/Classes/Tree/TableConfiguration/DatabaseTreeDataProvider.php
index dae7bd35377e..ca8960f50023 100644
--- a/typo3/sysext/core/Classes/Tree/TableConfiguration/DatabaseTreeDataProvider.php
+++ b/typo3/sysext/core/Classes/Tree/TableConfiguration/DatabaseTreeDataProvider.php
@@ -218,7 +218,6 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
      */
     public function setRootUid($rootUid)
     {
-        trigger_error(sprintf('%s is deprecated and will be removed in TYPO3 v12. Use %s->setStartingPoints() instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
         $this->rootUid = $rootUid;
     }
 
@@ -230,7 +229,6 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
      */
     public function getRootUid()
     {
-        trigger_error(sprintf('%s is deprecated and will be removed in TYPO3 v12. Use %s->getStartingPoints() instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
         return $this->rootUid;
     }
 
@@ -342,6 +340,7 @@ class DatabaseTreeDataProvider extends AbstractTableConfigurationTreeDataProvide
     protected function loadTreeData()
     {
         if ($this->getRootUid()) {
+            // @deprecated will be removed in v12
             $startingPoints = [$this->getRootUid()];
         } elseif ($this->getStartingPoints()) {
             $startingPoints = $this->getStartingPoints();
diff --git a/typo3/sysext/core/Documentation/Changelog/11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.rst b/typo3/sysext/core/Documentation/Changelog/11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.rst
index b84a961b72d7..a4ff4f7a25fe 100644
--- a/typo3/sysext/core/Documentation/Changelog/11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.rst
+++ b/typo3/sysext/core/Documentation/Changelog/11.4/Deprecation-95037-RootUidRelatedSettingOfTrees.rst
@@ -27,9 +27,8 @@ Using `treeConfig/rootUid` in TCA will trigger a TCA migration to
 
 The same applies to the according page TSconfig option.
 
-Directly calling :php:`setRootUid()` or :php:`getRootUid()` will
-trigger a PHP :php:`E_USER_DEPRECATED` error. The extension scanner will also
-detect those calls.
+The extension scanner detects any call to :php:`setRootUid()`
+or :php:`getRootUid()` as weak match.
 
 
 Affected Installations
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
index 60dfe03e7191..d4bcdbb981cf 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
@@ -4901,8 +4901,8 @@ return [
         ],
     ],
     'TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider->getRootUid' => [
-        'numberOfMandatoryArguments' => 1,
-        'maximumNumberOfArguments' => 1,
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
         'restFiles' => [
             'Deprecation-95037-RootUidRelatedSettingOfTrees.rst',
         ],
-- 
GitLab