[TASK] Doctrine: migrate EXT:sv 43/47843/6
authorMichael Oehlhof <typo3@oehlhof.de>
Thu, 21 Apr 2016 21:37:37 +0000 (23:37 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 7 Jun 2016 08:35:11 +0000 (10:35 +0200)
Resolves: #75852
Releases: master
Change-Id: I1b59f823c40d40dc9c71315f69c8a8d292876e16
Reviewed-on: https://review.typo3.org/47843
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Eugene Kenah Djomo <ekd@starfinanz.de>
Reviewed-by: Eugene Kenah Djomo <ekd@starfinanz.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/sv/Classes/AuthenticationService.php

index c3cad68..9a06e64 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Sv;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -148,18 +150,32 @@ class AuthenticationService extends AbstractAuthenticationService
             }
             $groups = array_unique($groups);
             if (!empty($groups)) {
-                $list = implode(',', $groups);
                 if ($this->writeDevLog) {
-                    GeneralUtility::devLog('Get usergroups with id: ' . $list, __CLASS__);
+                    GeneralUtility::devLog('Get usergroups with id: ' . implode(',', $groups), __CLASS__);
                 }
-                $lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain IS NULL OR lockToDomain=\'' . $this->authInfo['HTTP_HOST'] . '\')';
-                $hiddenP = !$this->authInfo['showHiddenRecords'] ? 'AND hidden=0 ' : '';
-                $res = $this->getDatabaseConnection()->exec_SELECTquery('*', $this->db_groups['table'], 'deleted=0 ' . $hiddenP . ' AND uid IN (' . $list . ')' . $lockToDomain_SQL);
-                while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
-                    $groupDataArr[$row['uid']] = $row;
+                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+                    ->getQueryBuilderForTable($this->db_groups['table']);
+                if (!empty($this->authInfo['showHiddenRecords'])) {
+                    $queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
                 }
-                if ($res) {
-                    $this->getDatabaseConnection()->sql_free_result($res);
+
+                $res = $queryBuilder->select('*')
+                    ->from($this->db_groups['table'])
+                    ->where(
+                        $queryBuilder->expr()->in('uid', array_map('intval', $groups)),
+                        $queryBuilder->expr()->orX(
+                            $queryBuilder->expr()->eq('lockToDomain', $queryBuilder->quote('')),
+                            $queryBuilder->expr()->isNull('lockToDomain'),
+                            $queryBuilder->expr()->eq(
+                                'lockToDomain',
+                                $queryBuilder->createNamedParameter($this->authInfo['HTTP_HOST'])
+                            )
+                        )
+                    )
+                    ->execute();
+
+                while ($row = $res->fetch()) {
+                    $groupDataArr[$row['uid']] = $row;
                 }
             } else {
                 if ($this->writeDevLog) {
@@ -184,13 +200,31 @@ class AuthenticationService extends AbstractAuthenticationService
     public function getSubGroups($grList, $idList = '', &$groups)
     {
         // Fetching records of the groups in $grList (which are not blocked by lockedToDomain either):
-        $lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain IS NULL OR lockToDomain=\'' . $this->authInfo['HTTP_HOST'] . '\')';
-        $hiddenP = !$this->authInfo['showHiddenRecords'] ? 'AND hidden=0 ' : '';
-        $res = $this->getDatabaseConnection()->exec_SELECTquery('uid,subgroup', 'fe_groups', 'deleted=0 ' . $hiddenP . ' AND uid IN (' . $grList . ')' . $lockToDomain_SQL);
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_groups');
+        if (!empty($this->authInfo['showHiddenRecords'])) {
+            $queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
+        }
+
+        $res = $queryBuilder
+            ->select('uid', 'subgroup')
+            ->from($this->db_groups['table'])
+            ->where(
+                $queryBuilder->expr()->in('uid', GeneralUtility::intExplode(',', $grList, true)),
+                $queryBuilder->expr()->orX(
+                    $queryBuilder->expr()->eq('lockToDomain', $queryBuilder->quote('')),
+                    $queryBuilder->expr()->isNull('lockToDomain'),
+                    $queryBuilder->expr()->eq(
+                        'lockToDomain',
+                        $queryBuilder->createNamedParameter($this->authInfo['HTTP_HOST'])
+                    )
+                )
+            )
+            ->execute();
+
         // Internal group record storage
         $groupRows = array();
         // The groups array is filled
-        while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
+        while ($row = $res->fetch()) {
             if (!in_array($row['uid'], $groups)) {
                 $groups[] = $row['uid'];
             }
@@ -214,14 +248,4 @@ class AuthenticationService extends AbstractAuthenticationService
             }
         }
     }
-
-    /**
-     * Returns the database connection
-     *
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }