Commit 3b4ffe61 authored by Felix Oertel's avatar Felix Oertel Committed by Christian Kuhn
Browse files

[FEATURE] move configuration of returnRawQueryResult

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
parent 797b1646
......@@ -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);
......
......@@ -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();
}
......@@ -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;
}
}
......@@ -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:
......
......@@ -98,6 +98,16 @@ class QueryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
$this->assertEquals($expectedResult, $actualResult);
}
/**
* @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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment