]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Handle no random result found
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 19 Jan 2019 21:30:50 +0000 (22:30 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 19 Jan 2019 21:30:50 +0000 (22:30 +0100)
src/Wallabag/CoreBundle/Repository/EntryRepository.php

index fabb19638b7f1b9da2968929614d0658df807d47..45366623d23204e8d8a1ffd3bfd9b1fd1c2ca832 100644 (file)
@@ -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'];