[BUGFIX] Remove doubled SQL query in PageRepository 54/52854/2
authorBenni Mack <benni@typo3.org>
Thu, 11 May 2017 06:22:13 +0000 (08:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 18 May 2017 15:00:54 +0000 (17:00 +0200)
The method PageRepository->checkWorkspaceAccess() does a SQL query to fetch
the workspace record, then hands it over to BE_USER->checkWorkspace which has the
same functionality - to fetch the full workspace record.

As this is redundant code, the PageRepository code can be simplified a lot by just leaving
the workspaceCache property.

Resolves: #81187
Releases: master, 8.7
Change-Id: Ia82febb2269084ea9101acfc36a1c9aa20950290
Reviewed-on: https://review.typo3.org/52854
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Classes/Page/PageRepository.php

index 274e72b..93c82ba 100644 (file)
@@ -1804,38 +1804,17 @@ class PageRepository
      * Checks if user has access to workspace.
      *
      * @param int $wsid Workspace ID
-     * @return bool <code>TRUE</code> if has access
+     * @return bool true if the backend user has access to a certain workspace
      */
     public function checkWorkspaceAccess($wsid)
     {
         if (!$this->getBackendUser() || !ExtensionManagementUtility::isLoaded('workspaces')) {
             return false;
         }
-        if (isset($this->workspaceCache[$wsid])) {
-            $ws = $this->workspaceCache[$wsid];
-        } else {
-            if ($wsid > 0) {
-                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-                    ->getQueryBuilderForTable('sys_workspace');
-                $queryBuilder->getRestrictions()->removeAll();
-                $ws = $queryBuilder->select('*')
-                    ->from('sys_workspace')
-                    ->where(
-                        $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($wsid, \PDO::PARAM_INT)),
-                        $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
-                    )
-                    ->execute()
-                    ->fetch();
-                if (!is_array($ws)) {
-                    return false;
-                }
-            } else {
-                $ws = $wsid;
-            }
-            $ws = $this->getBackendUser()->checkWorkspace($ws);
-            $this->workspaceCache[$wsid] = $ws;
+        if (!isset($this->workspaceCache[$wsid])) {
+            $this->workspaceCache[$wsid] = $this->getBackendUser()->checkWorkspace($wsid);
         }
-        return (string)$ws['_ACCESS'] !== '';
+        return (string)$this->workspaceCache[$wsid]['_ACCESS'] !== '';
     }
 
     /**