From 281f59359e0c59c50aa4f93a55f6546026ea0a67 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 9 Dec 2021 18:35:36 +0100
Subject: [PATCH] [!!!][TASK] Remove unused updateRootlineData method
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The method TemplateService->updateRootlineData() can
be removed. Until TYPO3 v11 TemplateService resolved
the TypoScript for a specific page, then found out the
actual used language (config.sys_language_uid via
TSFE->settingLanguage()) and then fetched the (translated)
rootline based on the resolved language information.

This is not needed anymore, as settingLanguage() does not
call this method anymore, and is called much earlier now,
see https://review.typo3.org/c/Packages/TYPO3.CMS/+/65044.

TypoScript is now always loaded after a translated
page rootline has been fetched.

This method is now completely unneeded, and is remoevd
without replacement as the concept has now been
streamlined.

Resolves: #96351
Related: #23736
Releases: main
Change-Id: If959a36333fcf5c91bee84ee497fddd2bfcec89b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72605
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 .../Classes/TypoScript/TemplateService.php    | 32 -------------
 ...ervice-updateRootlineDataMethodRemoved.rst | 43 +++++++++++++++++
 .../Unit/TypoScript/TemplateServiceTest.php   | 48 -------------------
 .../Php/MethodCallMatcher.php                 |  7 +++
 4 files changed, 50 insertions(+), 80 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96351-UnusedTemplateService-updateRootlineDataMethodRemoved.rst

diff --git a/typo3/sysext/core/Classes/TypoScript/TemplateService.php b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
index f43210bc552f..b89e39aacb22 100644
--- a/typo3/sysext/core/Classes/TypoScript/TemplateService.php
+++ b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
@@ -690,38 +690,6 @@ class TemplateService
         }
     }
 
-    /**
-     * This function can be used to update the data of the current rootLine
-     * e.g. when a different language is used.
-     *
-     * This function must not be used if there are different pages in the
-     * rootline as before!
-     *
-     * @param array $fullRootLine Array containing the FULL rootline (up to the TYPO3 root)
-     * @throws \RuntimeException If the given $fullRootLine does not contain all pages that are in the current template rootline
-     */
-    public function updateRootlineData($fullRootLine)
-    {
-        if (!is_array($this->rootLine) || empty($this->rootLine)) {
-            return;
-        }
-
-        $fullRootLineByUid = [];
-        foreach ($fullRootLine as $rootLineData) {
-            $fullRootLineByUid[$rootLineData['uid']] = $rootLineData;
-        }
-
-        foreach ($this->rootLine as $level => $dataArray) {
-            $currentUid = $dataArray['uid'];
-
-            if (!array_key_exists($currentUid, $fullRootLineByUid)) {
-                throw new \RuntimeException(sprintf('The full rootLine does not contain data for the page with the uid %d that is contained in the template rootline.', $currentUid), 1370419654);
-            }
-
-            $this->rootLine[$level] = $fullRootLineByUid[$currentUid];
-        }
-    }
-
     /**
      * Includes static template files (from extensions) for the input template record row.
      *
diff --git a/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96351-UnusedTemplateService-updateRootlineDataMethodRemoved.rst b/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96351-UnusedTemplateService-updateRootlineDataMethodRemoved.rst
new file mode 100644
index 000000000000..6aa210cd74cf
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96351-UnusedTemplateService-updateRootlineDataMethodRemoved.rst
@@ -0,0 +1,43 @@
+.. include:: ../../Includes.txt
+
+============================================================================
+Breaking: #96351 - Unused TemplateService->updateRootlineData method removed
+============================================================================
+
+See :issue:`96351`
+
+Description
+===========
+
+The PHP method `TemplateService->updateRootlineData()` is removed.
+
+It was used as a workaround to update the fetched Rootline with
+translated pages until TYPO3 v10. This was necessary because the
+TypoScript information contained the language information, and
+then the page translations were loaded accordingly.
+
+Since TYPO3 v11 the language is resolved earlier, at the same
+time as the page ID, and the mechanism became obsolete.
+
+
+Impact
+======
+
+Calling the method in PHP will throw a fatal PHP error, as the method does not exist anymore.
+
+
+Affected Installations
+======================
+
+TYPO3 installations, mainly legacy installations with legacy
+extensions using this method to boot up their own TypoScript
+parsing.
+
+
+Migration
+=========
+
+Calling this method is not needed anymore and can be removed
+from the affected code.
+
+.. index:: Frontend, PHP-API, FullyScanned, ext:core
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php b/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php
index 56352af8fef3..178b15a4d2f2 100644
--- a/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php
+++ b/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php
@@ -153,52 +153,4 @@ class TemplateServiceTest extends UnitTestCase
             $this->templateService->config
         );
     }
-
-    /**
-     * @test
-     */
-    public function updateRootlineDataOverwritesOwnArrayData(): void
-    {
-        $originalRootline = [
-            0 => ['uid' => 2, 'title' => 'originalTitle'],
-            1 => ['uid' => 3, 'title' => 'originalTitle2'],
-        ];
-
-        $updatedRootline = [
-            0 => ['uid' => 1, 'title' => 'newTitle'],
-            1 => ['uid' => 2, 'title' => 'newTitle2'],
-            2 => ['uid' => 3, 'title' => 'newTitle3'],
-        ];
-
-        $expectedRootline = [
-            0 => ['uid' => 2, 'title' => 'newTitle2'],
-            1 => ['uid' => 3, 'title' => 'newTitle3'],
-        ];
-
-        $this->templateService->rootLine = $originalRootline;
-        $this->templateService->updateRootlineData($updatedRootline);
-        self::assertEquals($expectedRootline, $this->templateService->rootLine);
-    }
-
-    /**
-     * @test
-     */
-    public function updateRootlineDataWithInvalidNewRootlineThrowsException(): void
-    {
-        $originalRootline = [
-            0 => ['uid' => 2, 'title' => 'originalTitle'],
-            1 => ['uid' => 3, 'title' => 'originalTitle2'],
-        ];
-
-        $newInvalidRootline = [
-            0 => ['uid' => 1, 'title' => 'newTitle'],
-            1 => ['uid' => 2, 'title' => 'newTitle2'],
-        ];
-
-        $this->expectException(\RuntimeException::class);
-        $this->expectExceptionCode(1370419654);
-
-        $this->templateService->rootLine = $originalRootline;
-        $this->templateService->updateRootlineData($newInvalidRootline);
-    }
 }
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
index f9d55e2e1930..6b3ad773e829 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
@@ -5084,4 +5084,11 @@ return [
             'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
+    'TYPO3\CMS\Core\TypoScript\TemplateService->updateRootlineData' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Breaking-96351-UnusedTemplateService-updateRootlineDataMethodRemoved.rst',
+        ],
+    ],
 ];
-- 
GitLab