aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-01-19 22:30:50 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-19 22:30:50 +0100
commit091bafeb4c4da9af8ea1201d5371887062f03f2e (patch)
treebbff07b995cb20bcbbfa82bfbf84b28891952709
parent2491c50b6bbb4d51696ad64aa754c1cd0fc83d1b (diff)
downloadwallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.tar.gz
wallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.tar.zst
wallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.zip
Handle no random result found
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php7
1 files changed, 6 insertions, 1 deletions
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 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\NoResultException;
6use Doctrine\ORM\QueryBuilder; 7use Doctrine\ORM\QueryBuilder;
7use Pagerfanta\Adapter\DoctrineORMAdapter; 8use Pagerfanta\Adapter\DoctrineORMAdapter;
8use Pagerfanta\Pagerfanta; 9use Pagerfanta\Pagerfanta;
@@ -437,7 +438,7 @@ class EntryRepository extends EntityRepository
437 * @param int $userId 438 * @param int $userId
438 * @param string $type Can be unread, archive, starred, etc 439 * @param string $type Can be unread, archive, starred, etc
439 * 440 *
440 * @throws \Doctrine\ORM\NoResultException 441 * @throws NoResultException
441 * 442 *
442 * @return Entry 443 * @return Entry
443 */ 444 */
@@ -464,6 +465,10 @@ class EntryRepository extends EntityRepository
464 465
465 $ids = $qb->getQuery()->getArrayResult(); 466 $ids = $qb->getQuery()->getArrayResult();
466 467
468 if (empty($ids)) {
469 throw new NoResultException();
470 }
471
467 // random select one in the list 472 // random select one in the list
468 $randomId = $ids[mt_rand(0, \count($ids) - 1)]['id']; 473 $randomId = $ids[mt_rand(0, \count($ids) - 1)]['id'];
469 474