[FEATURE] move configuration of returnRawQueryResult 55/23155/4
authorFelix Oertel <fo@lightwerk.com>
Sat, 17 Aug 2013 15:10:28 +0000 (17:10 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 6 Oct 2013 17:23:21 +0000 (19:23 +0200)
In motion to streamline the persistence configuration we will
get rid of the Typo3QuerySettings. Especially for
returnRawQueryResult it does not make sense to have a
configuration for that.

We moved it to be a method argument, so some can still decide
on a per-query-basis, what the query is supposed to return.

Resolves: #51145
Releases: 6.2
Change-Id: I948267149b66c350b271d3c98c5cbe3e268d087e
Reviewed-on: https://review.typo3.org/23155
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Classes/Persistence/Generic/Query.php
typo3/sysext/extbase/Classes/Persistence/Generic/QuerySettingsInterface.php
typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php
typo3/sysext/extbase/Classes/Persistence/QueryInterface.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryTest.php

index 3e00808..061552b 100644 (file)
@@ -203,11 +203,12 @@ class Query implements \TYPO3\CMS\Extbase\Persistence\QueryInterface {
        /**
         * Executes the query against the database and returns the result
         *
-        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
+        * @param $returnRawQueryResult boolean avoids the object mapping by the persistence
+        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
         * @api
         */
-       public function execute() {
-               if ($this->getQuerySettings()->getReturnRawQueryResult() === TRUE) {
+       public function execute($returnRawQueryResult = FALSE) {
+               if ($returnRawQueryResult === TRUE || $this->getQuerySettings()->getReturnRawQueryResult() === TRUE) {
                        return $this->persistenceManager->getObjectDataByQuery($this);
                } else {
                        return $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface', $this);
index 069d598..65c35cd 100644 (file)
@@ -181,6 +181,7 @@ interface QuerySettingsInterface {
         *
         * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
         * @return void
+        * @deprecated since Extbase 6.2, will be removed two versions later
         */
        public function setReturnRawQueryResult($returnRawQueryResult);
 
@@ -188,6 +189,7 @@ interface QuerySettingsInterface {
         * Returns the state, if the QueryResult should be returned unmapped.
         *
         * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
+        * @deprecated since Extbase 6.2, will be removed two versions later
         */
        public function getReturnRawQueryResult();
 }
index e4394fe..09d3f52 100644 (file)
@@ -107,6 +107,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Flag if the the query result should be returned as raw QueryResult.
         *
         * @var boolean
+        * @deprecated since Extbase 6.2, will be removed two versions later
         */
        protected $returnRawQueryResult = FALSE;
 
@@ -382,8 +383,10 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         *
         * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
         * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
         */
        public function setReturnRawQueryResult($returnRawQueryResult) {
+               GeneralUtility::logDeprecatedFunction();
                $this->returnRawQueryResult = $returnRawQueryResult;
                return $this;
        }
@@ -392,8 +395,10 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Returns the state, if the QueryResult should be returned unmapped.
         *
         * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
+        * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
         */
        public function getReturnRawQueryResult() {
+               GeneralUtility::logDeprecatedFunction();
                return $this->returnRawQueryResult;
        }
 }
index 6554702..32731dd 100644 (file)
@@ -128,10 +128,11 @@ interface QueryInterface {
        /**
         * Executes the query and returns the result.
         *
-        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE
+        * @param $returnRawQueryResult boolean avoids the object mapping by the persistence
+        * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $returnRawQueryResult is TRUE
         * @api
         */
-       public function execute();
+       public function execute($returnRawQueryResult = FALSE);
 
        /**
         * Sets the property names to order the result by. Expected like this:
index b0ac10f..2e8bd08 100644 (file)
@@ -100,6 +100,16 @@ class QueryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        */
+       public function executeReturnsRawObjectDataIfReturnRawQueryResultIsSet() {
+               $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
+               $expectedResult = 'rawQueryResult';
+               $actualResult = $this->query->execute(TRUE);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
         * @expectedException \InvalidArgumentException
         */
        public function setLimitAcceptsOnlyIntegers() {