aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-24 15:19:50 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3 (patch)
treeae181b75a7a9305b9d12774e4e451059acce5bce /src/Wallabag/CoreBundle/Repository/EntryRepository.php
parent27a8708b673bb0a28a520131d94ce17c7d3b9f96 (diff)
downloadwallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.tar.gz
wallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.tar.zst
wallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.zip
Change the way to check for an existing entry
The repository method return the entry found or false if nothing exists.
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 502e9da0..b8e22eb8 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -226,18 +226,26 @@ class EntryRepository extends EntityRepository
226 226
227 /** 227 /**
228 * Find an entry by its url and its owner. 228 * Find an entry by its url and its owner.
229 * If it exists, return the entry otherwise return false.
229 * 230 *
230 * @param $url 231 * @param $url
231 * @param $userId 232 * @param $userId
232 * 233 *
233 * @return array 234 * @return array|bool
234 */ 235 */
235 public function findOneByUrlAndUserId($url, $userId) 236 public function existByUrlAndUserId($url, $userId)
236 { 237 {
237 return $this->createQueryBuilder('e') 238 $res = $this->createQueryBuilder('e')
239 ->select('e.id, e.createdAt')
238 ->where('e.url = :url')->setParameter('url', $url) 240 ->where('e.url = :url')->setParameter('url', $url)
239 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 241 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
240 ->getQuery() 242 ->getQuery()
241 ->getResult(); 243 ->getResult();
244
245 if (count($res) > 1) {
246 return next($res);
247 }
248
249 return false;
242 } 250 }
243} 251}