Remove limit clause and use maxResults query method

This commit is contained in:
Thibaud Fabre
2016-09-21 15:03:00 +02:00
parent e9f74c9c52
commit 4a434672b4

View File

@@ -28,9 +28,10 @@ class TokenRepository extends EntityRepository
WHERE t.type = :type WHERE t.type = :type
AND t.user = :user AND t.user = :user
AND t.data = :basket_id AND t.data = :basket_id
AND (t.expiration > CURRENT_TIMESTAMP() OR t.expiration IS NULL) ORDER BY t.created DESC LIMIT 1'; AND (t.expiration > CURRENT_TIMESTAMP() OR t.expiration IS NULL) ORDER BY t.created DESC';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setMaxResults(1);
$query->setParameters([ $query->setParameters([
':type' => TokenManipulator::TYPE_VALIDATE, ':type' => TokenManipulator::TYPE_VALIDATE,
':user' => $user, ':user' => $user,
@@ -49,9 +50,10 @@ class TokenRepository extends EntityRepository
{ {
$dql = 'SELECT t FROM Phraseanet:Token t $dql = 'SELECT t FROM Phraseanet:Token t
WHERE t.value = :value WHERE t.value = :value
AND (t.expiration IS NULL OR t.expiration >= CURRENT_TIMESTAMP()) ORDER BY t.created DESC LIMIT 1'; AND (t.expiration IS NULL OR t.expiration >= CURRENT_TIMESTAMP()) ORDER BY t.created DESC';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setMaxResults(1);
$query->setParameters([':value' => $value]); $query->setParameters([':value' => $value]);
return $query->getOneOrNullResult(); return $query->getOneOrNullResult();