Skip to content

Instantly share code, notes, and snippets.

@manuelselbach
Last active March 1, 2016 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelselbach/38f9b5915ffddd951e0f to your computer and use it in GitHub Desktop.
Save manuelselbach/38f9b5915ffddd951e0f to your computer and use it in GitHub Desktop.
Debug Repository Queries in Extbase
<?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