[TASK] Rename QueryContextType::NONE to QueryContextType::UNRESTRICTED 59/47759/6
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Mon, 18 Apr 2016 17:52:03 +0000 (19:52 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Tue, 19 Apr 2016 08:17:53 +0000 (10:17 +0200)
This name change transports the intent of the query context better and
makes it more intuitive to use.

Instead of explicitly disabling all enable fields and the deleted flag
using the following code:

$queryBuilder->getQueryContext()
    ->setIgnoreEnableFields(true)
    ->setIncludeDeleted(true);

the more descriptive predefined context can be used:

$queryBuilder->getQueryContext()->setContext('unrestricted')

Releases: master
Resolves: #75751
Change-Id: I4d38a328c2b6707a32f26022b4abfc48e945c0ed
Reviewed-on: https://review.typo3.org/47759
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/backend/Classes/History/RecordHistory.php
typo3/sysext/core/Classes/Database/Query/QueryContext.php
typo3/sysext/core/Classes/Database/Query/QueryContextType.php
typo3/sysext/core/Classes/Database/Query/QueryRestrictionBuilder.php
typo3/sysext/core/Tests/Unit/Database/Query/QueryRestrictionBuilderTest.php
typo3/sysext/recycler/Classes/Domain/Model/Tables.php

index acd5001..3a5fba8 100644 (file)
@@ -17,12 +17,12 @@ namespace TYPO3\CMS\Backend\History;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryContextType;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\DiffUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
@@ -663,10 +663,8 @@ class RecordHistory
                 // check if there are records on the page
                 /** @var QueryBuilder $queryBuilder */
                 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tablename);
-                $queryBuilder
-                    ->getQueryContext()
-                    ->setIgnoreEnableFields(true)
-                    ->setIncludeDeleted(true);
+                $queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
+
                 $rows = $queryBuilder
                     ->select('uid')
                     ->from($tablename)
index 393924b..caf0e4d 100644 (file)
@@ -147,7 +147,7 @@ class QueryContext
             } elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
                 return QueryContextType::BACKEND;
             } else {
-                return QueryContextType::NONE;
+                return QueryContextType::UNRESTRICTED;
             }
         }
 
index f716411..6ca782d 100644 (file)
@@ -27,7 +27,7 @@ class QueryContextType extends \TYPO3\CMS\Core\Type\Enumeration
      * Constants reflecting the query context type
      */
     const AUTO = 'AUTO';
-    const NONE = 'NONE';
+    const UNRESTRICTED = 'UNRESTRICTED';
     const FRONTEND = 'FRONTEND';
     const BACKEND = 'BACKEND';
 
index d46da94..4d6c560 100644 (file)
@@ -92,7 +92,7 @@ class QueryRestrictionBuilder
                 return $this->getFrontendVisibilityRestrictions();
             case QueryContextType::BACKEND:
                 return $this->getBackendVisibilityConstraints();
-            case QueryContextType::NONE:
+            case QueryContextType::UNRESTRICTED:
                 return $this->expressionBuilder->andX();
             default:
                 throw new \RuntimeException(
index e32b070..2f55572 100644 (file)
@@ -19,6 +19,7 @@ use Prophecy\Argument;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\QueryContext;
+use TYPO3\CMS\Core\Database\Query\QueryContextType;
 use TYPO3\CMS\Core\Database\Query\QueryRestrictionBuilder;
 use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
@@ -85,9 +86,9 @@ class QueryRestrictionBuilderTest extends UnitTestCase
     /**
      * @test
      */
-    public function getVisibilityConstraintsReturnsEmptyConstraintForNoneContext()
+    public function getVisibilityConstraintsReturnsEmptyConstraintForUnrestrictedContext()
     {
-        $this->queryContext->setContext('none');
+        $this->queryContext->setContext(QueryContextType::UNRESTRICTED);
 
         $subject = GeneralUtility::makeInstance(
             QueryRestrictionBuilder::class,
index e067013..a17270e 100644 (file)
@@ -14,9 +14,9 @@ namespace TYPO3\CMS\Recycler\Domain\Model;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\QueryContextType;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Recycler\Utility\RecyclerUtility;
 
 /**
@@ -42,10 +42,7 @@ class Tables
             if ($deletedField) {
                 // Determine whether the table has deleted records:
                 $queryBuilder = $connection->getQueryBuilderForTable($tableName);
-                $queryBuilder
-                    ->getQueryContext()
-                    ->setIgnoreEnableFields(true)
-                    ->setIncludeDeleted(true);
+                $queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
 
                 $deletedCount = $queryBuilder->count('uid')
                     ->from($tableName)