From aabdc018dd2934ed666ce0dd899c6aefea34960c Mon Sep 17 00:00:00 2001
From: Marvin Buchmann <marvin_buchmann@web.de>
Date: Mon, 4 Mar 2024 19:01:05 +0100
Subject: [PATCH] [TASK] Centralize logic from
 PageLayoutController->getExistingPageTranslations() in BackendUtility
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The logic of PageLayoutController->getExistingPageTranslations() was
moved to BackendUtility::getExistingPageTranslations() to make the
code reusable in other places.

Resolves: #103274
Releases: main
Change-Id: I2fbc596ff33356e1dd4c39c11a7ccea409af945e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83201
Reviewed-by: Frank Nägler <frank.naegler@typo3.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Frank Nägler <frank.naegler@typo3.com>
---
 .../Controller/PageLayoutController.php       | 36 +------------------
 .../Classes/Utility/BackendUtility.php        | 36 +++++++++++++++++++
 2 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/PageLayoutController.php b/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
index 5057d1eae6bf..c7d086122bfa 100644
--- a/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
+++ b/typo3/sysext/backend/Classes/Controller/PageLayoutController.php
@@ -198,7 +198,7 @@ class PageLayoutController
         if ($this->id) {
             // Compile language data for pid != 0 only. The language drop-down is not shown on pid 0
             // since pid 0 can't be localized.
-            $pageTranslations = $this->getExistingPageTranslations();
+            $pageTranslations = BackendUtility::getExistingPageTranslations($this->id);
             foreach ($pageTranslations as $pageTranslation) {
                 $languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
                 if (isset($this->availableLanguages[$languageId])) {
@@ -236,40 +236,6 @@ class PageLayoutController
         }
     }
 
-    /**
-     * Fetch all records of the current page ID.
-     * Does not check permissions.
-     */
-    protected function getExistingPageTranslations(): array
-    {
-        if ($this->id === 0) {
-            return [];
-        }
-        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
-        $queryBuilder->getRestrictions()->removeAll()
-            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
-            ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
-        $result = $queryBuilder
-            ->select('*')
-            ->from('pages')
-            ->where(
-                $queryBuilder->expr()->eq(
-                    $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
-                    $queryBuilder->createNamedParameter($this->id, Connection::PARAM_INT)
-                )
-            )
-            ->executeQuery();
-
-        $rows = [];
-        while ($row = $result->fetchAssociative()) {
-            BackendUtility::workspaceOL('pages', $row, $this->getBackendUser()->workspace);
-            if ($row && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
-                $rows[] = $row;
-            }
-        }
-        return $rows;
-    }
-
     protected function getLocalizedPageRecord(int $languageId): ?array
     {
         if ($languageId === 0) {
diff --git a/typo3/sysext/backend/Classes/Utility/BackendUtility.php b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
index 27c02820c053..5e1a124ec9a2 100644
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
@@ -479,6 +479,42 @@ class BackendUtility
         return $row;
     }
 
+    /**
+     * Fetch all records of the given page ID.
+     * Does not check permissions.
+     *
+     * @internal
+     */
+    public static function getExistingPageTranslations(int $pageUid): array
+    {
+        if ($pageUid === 0) {
+            return [];
+        }
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
+        $queryBuilder->getRestrictions()->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
+            ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, self::getBackendUserAuthentication()->workspace));
+        $result = $queryBuilder
+            ->select('*')
+            ->from('pages')
+            ->where(
+                $queryBuilder->expr()->eq(
+                    $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
+                    $queryBuilder->createNamedParameter($pageUid, Connection::PARAM_INT)
+                )
+            )
+            ->executeQuery();
+
+        $rows = [];
+        while ($row = $result->fetchAssociative()) {
+            BackendUtility::workspaceOL('pages', $row, self::getBackendUserAuthentication()->workspace);
+            if ($row && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
+                $rows[] = $row;
+            }
+        }
+        return $rows;
+    }
+
     /**
      * Opens the page tree to the specified page id
      *
-- 
GitLab