X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=6972e974eeeb1853d28472f5be3ebf1b881ea9fa;hb=873f6b8e03079d11fab541aa5b0bc6f8fe2d645e;hp=553ad6abadd7f0c91f687ad4edebe7d5a7fbd0db;hpb=45c159b79883f3e5b2d1f8e5e3f09f0909da5d08;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 553ad6ab..6972e974 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -106,8 +106,9 @@ class EntryRepository extends EntityRepository $qb->andWhere('e.isArchived = true'); } + // We lower() all parts here because PostgreSQL 'LIKE' verb is case-sensitive $qb - ->andWhere('e.content LIKE :term OR e.title LIKE :term')->setParameter('term', '%'.$term.'%') + ->andWhere('lower(e.content) LIKE lower(:term) OR lower(e.title) LIKE lower(:term) OR lower(e.url) LIKE lower(:term)')->setParameter('term', '%'.$term.'%') ->leftJoin('e.tags', 't') ->groupBy('e.id'); @@ -125,9 +126,7 @@ class EntryRepository extends EntityRepository { return $this ->getBuilderByUser($userId) - ->leftJoin('e.tags', 't') - ->groupBy('e.id') - ->having('count(t.id) = 0'); + ->andWhere('size(e.tags) = 0'); } /** @@ -173,7 +172,7 @@ class EntryRepository extends EntityRepository $qb->orderBy('e.updatedAt', $order); } - $pagerAdapter = new DoctrineORMAdapter($qb); + $pagerAdapter = new DoctrineORMAdapter($qb, true, false); return new Pagerfanta($pagerAdapter); } @@ -329,7 +328,7 @@ class EntryRepository extends EntityRepository * * @return int */ - public function countAllEntriesByUsername($userId) + public function countAllEntriesByUser($userId) { $qb = $this->createQueryBuilder('e') ->select('count(e)') @@ -372,4 +371,42 @@ class EntryRepository extends EntityRepository ->setParameter('userId', $userId) ->execute(); } + + public function removeArchivedByUserId($userId) + { + $this->getEntityManager() + ->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId AND e.isArchived = TRUE') + ->setParameter('userId', $userId) + ->execute(); + } + + /** + * Get id and url from all entries + * Used for the clean-duplicates command. + */ + public function getAllEntriesIdAndUrl($userId) + { + $qb = $this->createQueryBuilder('e') + ->select('e.id, e.url') + ->where('e.user = :userid')->setParameter(':userid', $userId); + + return $qb->getQuery()->getArrayResult(); + } + + /** + * Find all entries by url and owner. + * + * @param $url + * @param $userId + * + * @return array + */ + public function findAllByUrlAndUserId($url, $userId) + { + return $this->createQueryBuilder('e') + ->where('e.url = :url')->setParameter('url', urldecode($url)) + ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) + ->getQuery() + ->getResult(); + } }