]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Keep url in exists endpoint
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index 45366623d23204e8d8a1ffd3bfd9b1fd1c2ca832..0c175abbbef5c375886cfd7f8a60d71c3910bec1 100644 (file)
@@ -346,6 +346,30 @@ class EntryRepository extends EntityRepository
         return false;
     }
 
+    /**
+     * Find an entry by its hashed url and its owner.
+     * If it exists, return the entry otherwise return false.
+     *
+     * @param $hashedUrl
+     * @param $userId
+     *
+     * @return Entry|bool
+     */
+    public function findByHashedUrlAndUserId($hashedUrl, $userId)
+    {
+        $res = $this->createQueryBuilder('e')
+            ->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl))
+            ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
+            ->getQuery()
+            ->getResult();
+
+        if (\count($res)) {
+            return current($res);
+        }
+
+        return false;
+    }
+
     /**
      * Count all entries for a user.
      *