Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.