From 091bafeb4c4da9af8ea1201d5371887062f03f2e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 19 Jan 2019 22:30:50 +0100 Subject: Handle no random result found --- src/Wallabag/CoreBundle/Repository/EntryRepository.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index fabb1963..45366623 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\NoResultException; use Doctrine\ORM\QueryBuilder; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; @@ -437,7 +438,7 @@ class EntryRepository extends EntityRepository * @param int $userId * @param string $type Can be unread, archive, starred, etc * - * @throws \Doctrine\ORM\NoResultException + * @throws NoResultException * * @return Entry */ @@ -464,6 +465,10 @@ class EntryRepository extends EntityRepository $ids = $qb->getQuery()->getArrayResult(); + if (empty($ids)) { + throw new NoResultException(); + } + // random select one in the list $randomId = $ids[mt_rand(0, \count($ids) - 1)]['id']; -- cgit v1.2.3