Last active
March 1, 2016 10:44
-
-
Save manuelselbach/38f9b5915ffddd951e0f to your computer and use it in GitHub Desktop.
Debug Repository Queries in Extbase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeController | |
{ | |
/** | |
* Example method | |
*/ | |
public function someAction() | |
{ | |
$results = $this->someRespository->findAll(); | |
$this->debugQuery($results); | |
} | |
/** | |
* Debugs a SQL query from a QueryResult | |
* | |
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $queryResult | |
* @param boolean $explainOutput | |
* | |
* @return void | |
*/ | |
public function debugQuery( | |
\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $queryResult, | |
$explainOutput = false | |
) { | |
$GLOBALS['TYPO3_DB']->debugOuput = 2; | |
if ($explainOutput) { | |
$GLOBALS['TYPO3_DB']->explainOutput = true; | |
} | |
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = true; | |
$queryResult->toArray(); | |
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($GLOBALS['TYPO3_DB']->debug_lastBuiltQuery); | |
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = false; | |
$GLOBALS['TYPO3_DB']->explainOutput = false; | |
$GLOBALS['TYPO3_DB']->debugOuput = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment