[TASK] Deprecate "noWSOL" in PageRepository->getRecordRaw 03/52803/2
authorBenni Mack <benni@typo3.org>
Sun, 14 May 2017 12:26:25 +0000 (14:26 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 17 May 2017 12:16:18 +0000 (14:16 +0200)
The method getRecordRaw has a very unspeakable method argument called
"noWSOL" which is only used internally within PageRepository.

Setting "noWSOL" to true only does a regular SQL query which can be implemented
directly in the according places, as the WSOL does not need to be known.

Resolves: #81218
Releases: master
Change-Id: I459ead0172f4ca1a6655599dd47aee2651a452bb
Reviewed-on: https://review.typo3.org/52803
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-81218-NoWSOLArgumentInPageRepository-getRawRecord.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageRepository.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-81218-NoWSOLArgumentInPageRepository-getRawRecord.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-81218-NoWSOLArgumentInPageRepository-getRawRecord.rst
new file mode 100644 (file)
index 0000000..f06ef9c
--- /dev/null
@@ -0,0 +1,36 @@
+.. include:: ../../Includes.txt
+
+=====================================================================
+Deprecation: #81218 - noWSOL argument in PageRepository->getRawRecord
+=====================================================================
+
+See :issue:`81218`
+
+Description
+===========
+
+The method `PageRepository->getRawRecord()` has a fourth parameter called php:`$noWSOL` which allowed
+to disable the logic for getting the workspace-related record. This method argument was previously
+only used internally within PageRepository, and using this argument left the functionality of this
+method to only do a simple SQL statement, which can be implemented itself without using this API call.
+
+
+Impact
+======
+
+Calling PageRepository->getRawRecord() with a fourth parameter will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instance with custom extensions that use this method with a fourth parameter explicitly.
+
+
+Migration
+=========
+
+Remove the fourth parameter if set to false, if just a simple SQL call is needed, implement the SQL
+call directly in your PHP code.
+
+.. index:: Frontend, PHP-API
\ No newline at end of file
index a67b444..a7a065d 100644 (file)
@@ -1127,7 +1127,7 @@ class PageRepository
      * @return mixed Returns array (the record) if found, otherwise blank/0 (zero)
      * @see getPage_noCheck()
      */
-    public function getRawRecord($table, $uid, $fields = '*', $noWSOL = false)
+    public function getRawRecord($table, $uid, $fields = '*', $noWSOL = null)
     {
         $uid = (int)$uid;
         if (isset($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]) && $uid > 0) {
@@ -1142,6 +1142,10 @@ class PageRepository
                 ->fetch();
 
             if ($row) {
+                if ($noWSOL !== null) {
+                    GeneralUtility::deprecationLog('The fourth parameter of PageRepository->getRawRecord() has been deprecated, use a SQL statement directly. The parameter will be removed in TYPO3 v10.');
+                }
+                // @deprecated - remove this if-clause in TYPO3 v10
                 if (!$noWSOL) {
                     $this->versionOL($table, $row);
                 }
@@ -1410,16 +1414,37 @@ class PageRepository
             } else {
                 // Otherwise we have to expect "uid" to be in the record and look up based
                 // on this:
-                $newPidRec = $this->getRawRecord($table, $rr['uid'], 't3ver_oid,t3ver_wsid', true);
-                if (is_array($newPidRec)) {
-                    $oid = $newPidRec['t3ver_oid'];
-                    $wsid = $newPidRec['t3ver_wsid'];
+                $uid = (int)$rr['uid'];
+                if ($uid > 0) {
+                    $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
+                    $queryBuilder->getRestrictions()
+                        ->removeAll()
+                        ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+                    $newPidRec = $queryBuilder->select('t3ver_oid', 't3ver_wsid')
+                        ->from($table)
+                        ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
+                        ->execute()
+                        ->fetch();
+
+                    if (is_array($newPidRec)) {
+                        $oid = $newPidRec['t3ver_oid'];
+                        $wsid = $newPidRec['t3ver_wsid'];
+                    }
                 }
             }
             // If workspace ids matches and ID of current online version is found, look up
             // the PID value of that:
             if ($oid && ((int)$this->versioningWorkspaceId === 0 && $this->checkWorkspaceAccess($wsid) || (int)$wsid === (int)$this->versioningWorkspaceId)) {
-                $oidRec = $this->getRawRecord($table, $oid, 'pid', true);
+                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
+                $queryBuilder->getRestrictions()
+                    ->removeAll()
+                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+                $oidRec = $queryBuilder->select('pid')
+                    ->from($table)
+                    ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($oid, \PDO::PARAM_INT)))
+                    ->execute()
+                    ->fetch();
+
                 if (is_array($oidRec)) {
                     // SWAP uid as well? Well no, because when fixing a versioning PID happens it is
                     // assumed that this is a "branch" type page and therefore the uid should be
@@ -1538,10 +1563,24 @@ class PageRepository
         if (!empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS'])
             && (int)VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)
         ) {
+            $moveID = 0;
             // If t3ver_move_id is not found, then find it (but we like best if it is here)
             if (!isset($row['t3ver_move_id'])) {
-                $moveIDRec = $this->getRawRecord($table, $row['uid'], 't3ver_move_id', true);
-                $moveID = $moveIDRec['t3ver_move_id'];
+                if ((int)$row['uid'] > 0) {
+                    $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
+                    $queryBuilder->getRestrictions()
+                        ->removeAll()
+                        ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+                    $moveIDRec = $queryBuilder->select('t3ver_move_id')
+                        ->from($table)
+                        ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT)))
+                        ->execute()
+                        ->fetch();
+
+                    if (is_array($moveIDRec)) {
+                        $moveID = $moveIDRec['t3ver_move_id'];
+                    }
+                }
             } else {
                 $moveID = $row['t3ver_move_id'];
             }