I'm trying to adjust my query using compare field in the TYPO3 repository and don't really get it figured out. Anybody knows how to correctly debug this? I am using TYPO3 8.x CMS. (8.4 to be precise)
<?php
public function findActiveProducts() {
$query = $this->createQuery();
$constraints = array();
$date = new \DateTime(midnight);
// $date = new \DateTime(); // i tried to use the precise time to compare
$today = $date->format('Y-m-d H:i:s');
// $today = $date->format('Y-m-d'); // 1st try (the field value in db)
// $today = $date->getTimestamp(); // 2nd try (the type in the modal
$constraints[] = $query->lessThanOrEqual('entrydate', $today);
$constraints[] = $query->equals('deleted', 0, false);
->matching(
$query->logicalAnd($constraints)
)
->setLimit(10)
->setOrderings(array(
'entrydate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
)
);
// Some debug's to find out more. sadly didn't work
\TYPO3\CMS\Core\Utility\DebugUtility::debug( $today , 'today value');
\TYPO3\CMS\Core\Utility\DebugUtility::debug( $query, 'my query');
\TYPO3\CMS\Core\Utility\DebugUtility::debug( $constraints, 'constraints');
$result = $query->execute();
?>
So: Does anybody have a good advise how to debug this? One guy on stackoverflow wrote an entry in another topic explaining we just have to switch on sql errors in TYPO3 and type a mistaken value in the query to output the sql error. This would work, but the error message doesn't last to the field I try to compare. So I'd be very pleased if s.b. would help me out of this misery.
The oldschool debugging no longer works in 8.x, else this would not be a big deal.
<?php
$parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbQueryParser');
$parser->convertQueryToDoctrineQueryBuilder($query);
$queryParts = $parser->parseQuery($query);
\TYPO3\CMS\Core\Utility\DebugUtility::debug($queryParts, 'Query');
?>
By the way the model... works fine in all the sections I'm using it, except in the custom query within the repository.
/**
* entrydate
*
* @var \DateTime
*/
protected $entrydate = null;
I've also searched stackoverflow but didn't find a fitting solution. - For me, this one doesn't work: How to compare DateTime in Extbase repository - I won't get my query with this one: How to debug a query in extbase? - neither did this: Extbase - get created sql from query