[BUGFIX] Queries with NULL don't work anymore 92/28592/8
authorKlaas Johan Kooistra <k.kooistra@drecomm.nl>
Fri, 21 Mar 2014 08:12:53 +0000 (09:12 +0100)
committerFelix Oertel <mehl@foertel.com>
Mon, 24 Mar 2014 16:57:15 +0000 (17:57 +0100)
See change: I517c0500cad75cae96fd739f2ff7222db80b42a5
At the end of the Typo3DbQueryParser::parseComparison() method the updated
operator for NULL values was no longer passed to the parseDynamicOperand,
generating = NULL instead of IS NULL.

Solved the issue by adding the operator parameter again.

Change-Id: I13c3cecf0bf4c95789032f31ead192b945794484
Resolves: #57130
Related: #55167
Releases: 6.2
Reviewed-on: https://review.typo3.org/28592
Reviewed-by: Markus Klein
Reviewed-by: Felix Oertel
Tested-by: Felix Oertel
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
typo3/sysext/extbase/Tests/Functional/Persistence/OperatorTest.php [new file with mode: 0644]

index 46303f6..1be29cb 100644 (file)
@@ -263,6 +263,7 @@ class Typo3DbQueryParser {
         * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
         * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source The source
         * @param array &$sql The query parts
+        * @throws \RuntimeException
         * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
         * @return void
         */
@@ -329,7 +330,7 @@ class Typo3DbQueryParser {
                        if ($hasValue === FALSE) {
                                $sql['where'][] = '1<>1';
                        } else {
-                               $this->parseDynamicOperand($comparison, $source, $sql, NULL);
+                               $this->parseDynamicOperand($comparison, $operator, $source, $sql, NULL);
                        }
                } elseif ($operator === \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_CONTAINS) {
                        if ($operand2 === NULL) {
@@ -368,25 +369,22 @@ class Typo3DbQueryParser {
                                        $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
                                }
                        }
-                       $this->parseDynamicOperand($comparison, $source, $sql);
+                       $this->parseDynamicOperand($comparison, $operator, $source, $sql);
                }
        }
 
        /**
         * Parse a DynamicOperand into SQL and parameter arrays.
         *
-        * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface $operand
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface $comparison
         * @param string $operator One of the JCR_OPERATOR_* constants
         * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source The source
         * @param array &$sql The query parts
         * @param string $valueFunction an optional SQL function to apply to the operand value
         * @return void
         */
-       protected function parseDynamicOperand(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface $comparison, \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array &$sql, $valueFunction = NULL) {
+       protected function parseDynamicOperand(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface $comparison, $operator, \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array &$sql, $valueFunction = NULL) {
                $operand = $comparison->getOperand1();
-               $operator = $comparison->getOperator();
-               $operand2 = $comparison->getOperand2();
-
                if ($operand instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\LowerCaseInterface) {
                        $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, 'LOWER');
                } elseif ($operand instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\UpperCaseInterface) {
diff --git a/typo3/sysext/extbase/Tests/Functional/Persistence/OperatorTest.php b/typo3/sysext/extbase/Tests/Functional/Persistence/OperatorTest.php
new file mode 100644 (file)
index 0000000..5d5d8b7
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Felix Oertel <typo3@foertel.com>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
+
+class OperatorTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
+
+       /**
+        * @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
+        */
+       protected $blogRepository;
+
+       /**
+        * @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository
+        */
+       protected $postRepository;
+
+       /**
+        * @var array
+        */
+       protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
+
+       /**
+        * @var array
+        */
+       protected $coreExtensionsToLoad = array('extbase', 'fluid');
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
+        */
+       protected $objectManager;
+
+       /**
+        * Sets up this test suite.
+        */
+       public function setUp() {
+               parent::setUp();
+
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
+
+               $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $this->blogRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
+               $this->postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
+
+       }
+
+       /**
+        * @test
+        */
+       public function equalsNullIsResolvedCorrectly() {
+               $query = $this->postRepository->createQuery();
+
+               $query->matching(
+                       $query->equals('title', NULL)
+               );
+
+               $this->assertSame(0, $query->count());
+       }
+}