aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-09-25 16:11:06 +0200
committerGitHub <noreply@github.com>2016-09-25 16:11:06 +0200
commit7e98ad962680fac17b3b90ae34b9c6e5afe7636f (patch)
tree451f2c7ec7011f1f0ee8911fb1921b02f158e1dc /src/Wallabag/CoreBundle/Repository
parent9d7dd6b0d2480d3efff5b0ab1461f2ef99bfd57a (diff)
parent289875836a09944f5993d33753042abfef13809e (diff)
downloadwallabag-7e98ad962680fac17b3b90ae34b9c6e5afe7636f.tar.gz
wallabag-7e98ad962680fac17b3b90ae34b9c6e5afe7636f.tar.zst
wallabag-7e98ad962680fac17b3b90ae34b9c6e5afe7636f.zip
Merge pull request #2308 from wallabag/tags-duplicate
Fix duplicate tags on import
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index 41f61607..9d127da7 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -7,17 +7,45 @@ use Doctrine\ORM\EntityRepository;
7class TagRepository extends EntityRepository 7class TagRepository extends EntityRepository
8{ 8{
9 /** 9 /**
10 * Find Tags. 10 * Count all tags per user.
11 *
12 * @param int $userId
13 * @param int $cacheLifeTime Duration of the cache for this query
14 *
15 * @return int
16 */
17 public function countAllTags($userId, $cacheLifeTime = null)
18 {
19 $query = $this->createQueryBuilder('t')
20 ->select('t.slug')
21 ->leftJoin('t.entries', 'e')
22 ->where('e.user = :userId')->setParameter('userId', $userId)
23 ->groupBy('t.slug')
24 ->getQuery();
25
26 if (null !== $cacheLifeTime) {
27 $query->useQueryCache(true);
28 $query->useResultCache(true);
29 $query->setResultCacheLifetime($cacheLifeTime);
30 }
31
32 return count($query->getArrayResult());
33 }
34
35 /**
36 * Find all tags with associated entries per user.
11 * 37 *
12 * @param int $userId 38 * @param int $userId
13 * 39 *
14 * @return array 40 * @return array
15 */ 41 */
16 public function findAllTags($userId) 42 public function findAllTagsWithEntries($userId)
17 { 43 {
18 return $this->createQueryBuilder('t') 44 return $this->createQueryBuilder('t')
19 ->leftJoin('t.entries', 'e') 45 ->leftJoin('t.entries', 'e')
20 ->where('e.user = :userId')->setParameter('userId', $userId); 46 ->where('e.user = :userId')->setParameter('userId', $userId)
47 ->getQuery()
48 ->getResult();
21 } 49 }
22 50
23 /** 51 /**