diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-01-19 22:30:50 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-01-19 22:30:50 +0100 |
commit | 091bafeb4c4da9af8ea1201d5371887062f03f2e (patch) | |
tree | bbff07b995cb20bcbbfa82bfbf84b28891952709 /src/Wallabag | |
parent | 2491c50b6bbb4d51696ad64aa754c1cd0fc83d1b (diff) | |
download | wallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.tar.gz wallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.tar.zst wallabag-091bafeb4c4da9af8ea1201d5371887062f03f2e.zip |
Handle no random result found
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 7 |
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 @@ | |||
3 | namespace Wallabag\CoreBundle\Repository; | 3 | namespace Wallabag\CoreBundle\Repository; |
4 | 4 | ||
5 | use Doctrine\ORM\EntityRepository; | 5 | use Doctrine\ORM\EntityRepository; |
6 | use Doctrine\ORM\NoResultException; | ||
6 | use Doctrine\ORM\QueryBuilder; | 7 | use Doctrine\ORM\QueryBuilder; |
7 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 8 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
8 | use Pagerfanta\Pagerfanta; | 9 | use 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 | ||