[TASK] Deprecate AbstractUserAuthentication->fetchUserRecord 85/58485/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 30 Sep 2018 10:34:52 +0000 (12:34 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 30 Sep 2018 11:13:06 +0000 (13:13 +0200)
To untie authentication services from user authentication a bit better,
the fetchUserRecord() method of AbstractAuthenticationService now
implements fetchUserRecord() on its own instead of calling the method
with the same name of $pObj.
AbstractUserAuthentication->fetchUserRecord() is then unused and can
be deprecated.

Resolves: #86466
Releases: master
Change-Id: Ia144ea2dfb8a7c7462ed12875ee35caab9763ba2
Reviewed-on: https://review.typo3.org/58485
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Authentication/AbstractAuthenticationService.php
typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-86466-AbstractUserAuthentication-fetchUserRecord.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php

index 6fc9f23..369a0a2 100644 (file)
@@ -14,7 +14,11 @@ namespace TYPO3\CMS\Core\Authentication;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Service\AbstractService;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Authentication services class
@@ -136,7 +140,31 @@ class AbstractAuthenticationService extends AbstractService
     public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '')
     {
         $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
-        $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
+        $user = false;
+        if ($username || $extraWhere) {
+            $query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
+            $query->getRestrictions()->removeAll()
+                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+            $constraints = array_filter([
+                QueryHelper::stripLogicalOperatorPrefix($dbUser['check_pid_clause']),
+                QueryHelper::stripLogicalOperatorPrefix($dbUser['enable_clause']),
+                QueryHelper::stripLogicalOperatorPrefix($extraWhere),
+            ]);
+            if (!empty($username)) {
+                array_unshift(
+                    $constraints,
+                    $query->expr()->eq(
+                        $dbUser['username_column'],
+                        $query->createNamedParameter($username, \PDO::PARAM_STR)
+                    )
+                );
+            }
+            $user = $query->select('*')
+                ->from($dbUser['table'])
+                ->where(...$constraints)
+                ->execute()
+                ->fetch();
+        }
         return $user;
     }
 }
index 0f091ff..ac2ce42 100644 (file)
@@ -1517,9 +1517,11 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
      * @param string $username user name
      * @param string $extraWhere Additional WHERE clause: " AND ...
      * @return mixed User array or FALSE
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
      */
     public function fetchUserRecord($dbUser, $username, $extraWhere = '')
     {
+        trigger_error('This method will be removed in TYPO3 v10.', E_USER_DEPRECATED);
         $user = false;
         if ($username || $extraWhere) {
             $query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
@@ -1548,7 +1550,6 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
                 ->execute()
                 ->fetch();
         }
-
         return $user;
     }
 
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86466-AbstractUserAuthentication-fetchUserRecord.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86466-AbstractUserAuthentication-fetchUserRecord.rst
new file mode 100644 (file)
index 0000000..c8a1a20
--- /dev/null
@@ -0,0 +1,38 @@
+.. include:: ../../Includes.txt
+
+=================================================================
+Deprecation: #86466 - AbstractUserAuthentication->fetchUserRecord
+=================================================================
+
+See :issue:`86466`
+
+Description
+===========
+
+Method :php:`TYPO3\CMS\Core\Authentication\AbstractUserAuthentication->fetchUserRecord()`
+has been marked as deprecated.
+
+
+Impact
+======
+
+Calling the method will trigger a PHP :php:`E_USER_DEPRECATED` error.
+
+
+Affected Installations
+======================
+
+The methods has been called indirectly via
+:php:`TYPO3\CMS\Core\Authentication\AbstractAuthenticationService->fetchUserRecord()` as
+:php:`$this->pObj->fetchUserRecord()`. It has usually not been called directly through
+custom authentication services. Instances are usually not affected by the change, the
+extension scanner will find possible usages.
+
+
+Migration
+=========
+
+If used within authentication services, use :php:`$this->fetchUserRecord()` instead, otherwise
+copy the method around.
+
+.. index:: PHP-API, FullyScanned
\ No newline at end of file
index 1c40779..b0df7b8 100644 (file)
@@ -3768,4 +3768,11 @@ return [
             'Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst'
         ],
     ],
+    'TYPO3\CMS\Core\Authentication\AbstractUserAuthentication->fetchUserRecord' => [
+        'numberOfMandatoryArguments' => 2,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-86466-AbstractUserAuthentication-fetchUserRecord.rst'
+        ],
+    ],
 ];