Skip to content

Instantly share code, notes, and snippets.

@kitzberger
Created November 8, 2018 17:03
Show Gist options
  • Save kitzberger/21cc3301e27633652a4b045f3c9ce0c4 to your computer and use it in GitHub Desktop.
Save kitzberger/21cc3301e27633652a4b045f3c9ce0c4 to your computer and use it in GitHub Desktop.
Debug Extbase Queries (TYPO3 6+7)
<?php
namespace Vendor\ExtensionName\Domain\Repository;
class XyzRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
public function findByFoo($value)
{
$query = $this->createQuery();
#$query->setFancyConstrations(...)
$this->debugQuery($query->execute());
return $query->execute();
}
/**
* 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']->debugOutput = 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']->debugOutput = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment