From 5dd6e8892801b2e5dd323c687c1b5a32d142ef0a Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 28 May 2018 22:10:06 +0200
Subject: [PATCH] [TASK] Deprecate 3rd argument in
 PageRepository->getRootLine()

The third argument about catching errors can be achieved by building a try/catch
block around the method.

Resolves: #85105
Releases: master
Change-Id: I42f2b66e1b6267376e9352e76b9e58e9bde028f9
Reviewed-on: https://review.typo3.org/57075
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
---
 ...odArgumentInPageRepository-getRootLine.rst | 37 +++++++++++++++++++
 .../BackendConfigurationManager.php           | 11 +++---
 .../frontend/Classes/Page/PageRepository.php  |  7 +++-
 .../Classes/Typolink/PageLinkBuilder.php      |  6 ++-
 .../Php/MethodArgumentDroppedMatcher.php      |  6 +++
 5 files changed, 60 insertions(+), 7 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85105-3rdMethodArgumentInPageRepository-getRootLine.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85105-3rdMethodArgumentInPageRepository-getRootLine.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85105-3rdMethodArgumentInPageRepository-getRootLine.rst
new file mode 100644
index 000000000000..ad29a97787d2
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85105-3rdMethodArgumentInPageRepository-getRootLine.rst
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+==========================================================================
+Deprecation: #85105 - 3rd method argument in PageRepository->getRootLine()
+==========================================================================
+
+See :issue:`85105`
+
+Description
+===========
+
+The third argument of :php:`TYPO3\CMS\Frontend\Page\PageRepository->getRootLine()` has been marked
+as deprecated.
+
+That argument was mainly used to catch exceptions when a faulty rootline is found. The PageRepository
+currently handles the exceptions in a special way with some special magic. However, it is more
+feasible to always throw an exception and have the caller handle possible exceptions.
+
+
+Impact
+======
+
+Calling the method with three arguments will trigger a deprecation message.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with extensions calling the method directly with the 3rd argument.
+
+
+Migration
+=========
+
+Remove the third argument from code in PHP and wrap a try/catch block around the method call.
+
+.. index:: Frontend, PHP-API, FullyScanned
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php b/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
index 7782f9f09d23..3f4b3fb3336c 100644
--- a/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
+++ b/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
@@ -22,9 +22,9 @@ use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\RootlineUtility;
 use TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler;
 use TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler;
-use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * A general purpose configuration manager used in backend mode.
@@ -62,10 +62,11 @@ class BackendConfigurationManager extends AbstractConfigurationManager
             // Get the root line
             $rootline = [];
             if ($pageId > 0) {
-                /** @var $sysPage PageRepository */
-                $sysPage = GeneralUtility::makeInstance(PageRepository::class);
-                // Get the rootline for the current page
-                $rootline = $sysPage->getRootLine($pageId, '', true);
+                try {
+                    $rootline = GeneralUtility::makeInstance(RootlineUtility::class, $pageId)->get();
+                } catch (\RuntimeException $e) {
+                    $rootline = [];
+                }
             }
             // This generates the constants/config + hierarchy info for the template.
             $template->runThroughTemplates($rootline, 0);
diff --git a/typo3/sysext/frontend/Classes/Page/PageRepository.php b/typo3/sysext/frontend/Classes/Page/PageRepository.php
index ce9ecca1b4cb..a468b878adda 100644
--- a/typo3/sysext/frontend/Classes/Page/PageRepository.php
+++ b/typo3/sysext/frontend/Classes/Page/PageRepository.php
@@ -955,8 +955,13 @@ class PageRepository implements LoggerAwareInterface
      * @return array Array with page records from the root line as values. The array is ordered with the outer records first and root record in the bottom. The keys are numeric but in reverse order. So if you traverse/sort the array by the numeric keys order you will get the order from root and out. If an error is found (like eternal looping or invalid mountpoint) it will return an empty array.
      * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getPageAndRootline()
      */
-    public function getRootLine($uid, $MP = '', $ignoreMPerrors = false)
+    public function getRootLine($uid, $MP = '', $ignoreMPerrors = null)
     {
+        if ($ignoreMPerrors !== null) {
+            trigger_error('The third argument in PageRepository::getRootline() will be removed in TYPO3 v10.0. Use a try/catch block around this method to catch any mount point errors, if necessary', E_USER_DEPRECATED);
+        } else {
+            $ignoreMPerrors = false;
+        }
         $rootline = GeneralUtility::makeInstance(RootlineUtility::class, $uid, $MP, $this);
         try {
             return $rootline->get();
diff --git a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
index a5ba1c59268f..8061c4b86c76 100644
--- a/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
+++ b/typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
@@ -287,7 +287,11 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
 
         // Find closest mount point
         // Gets rootline of linked-to page
-        $tCR_rootline = $tsfe->sys_page->getRootLine($pageId, '', true);
+        try {
+            $tCR_rootline = $tsfe->sys_page->getRootLine($pageId);
+        } catch (\RuntimeException $e) {
+            $tCR_rootline = [];
+        }
         $inverseTmplRootline = array_reverse($tsfe->tmpl->rootLine);
         $rl_mpArray = [];
         $startMPaccu = false;
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php
index f88110880e40..e2472dfdfa69 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php
@@ -177,4 +177,10 @@ return [
             'Breaking-84877-MethodsOfLocalizationRepositoryChanged.rst',
         ],
     ],
+    'TYPO3\CMS\Frontend\Page\PageRepository->getRootLine' => [
+        'maximumNumberOfArguments' => 2,
+        'restFiles' => [
+            'Deprecation-85105-3rdMethodArgumentInPageRepository-getRootLine.rst',
+        ],
+    ],
 ];
-- 
GitLab