mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Handle no random result found
This commit is contained in:
parent
2491c50b6b
commit
091bafeb4c
1 changed files with 6 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace Wallabag\CoreBundle\Repository;
|
namespace Wallabag\CoreBundle\Repository;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Doctrine\ORM\NoResultException;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
|
@ -437,7 +438,7 @@ class EntryRepository extends EntityRepository
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @param string $type Can be unread, archive, starred, etc
|
* @param string $type Can be unread, archive, starred, etc
|
||||||
*
|
*
|
||||||
* @throws \Doctrine\ORM\NoResultException
|
* @throws NoResultException
|
||||||
*
|
*
|
||||||
* @return Entry
|
* @return Entry
|
||||||
*/
|
*/
|
||||||
|
@ -464,6 +465,10 @@ class EntryRepository extends EntityRepository
|
||||||
|
|
||||||
$ids = $qb->getQuery()->getArrayResult();
|
$ids = $qb->getQuery()->getArrayResult();
|
||||||
|
|
||||||
|
if (empty($ids)) {
|
||||||
|
throw new NoResultException();
|
||||||
|
}
|
||||||
|
|
||||||
// random select one in the list
|
// random select one in the list
|
||||||
$randomId = $ids[mt_rand(0, \count($ids) - 1)]['id'];
|
$randomId = $ids[mt_rand(0, \count($ids) - 1)]['id'];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue