aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 14:50:52 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 14:50:52 +0100
commitfc73222723c7a0c9b577805d3ef51eb96b124b92 (patch)
tree002b77b82266b1e497e3683e72f4a457d4353633 /src/Wallabag/CoreBundle/Repository/EntryRepository.php
parentc997cfcc9c161241a6398b0942a1a869688d807a (diff)
downloadwallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.tar.gz
wallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.tar.zst
wallabag-fc73222723c7a0c9b577805d3ef51eb96b124b92.zip
Remove user reference in tag
Fix #1543
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 57bf8024..9ff80d6e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Repository;
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Pagerfanta\Adapter\DoctrineORMAdapter; 6use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta; 7use Pagerfanta\Pagerfanta;
8use Wallabag\CoreBundle\Entity\Tag;
8 9
9class EntryRepository extends EntityRepository 10class EntryRepository extends EntityRepository
10{ 11{
@@ -179,4 +180,22 @@ class EntryRepository extends EntityRepository
179 ->getQuery() 180 ->getQuery()
180 ->getSingleResult(); 181 ->getSingleResult();
181 } 182 }
183
184 /**
185 * Remove a tag from all user entries.
186 * We are using a native SQL query because Doctrine doesn't know EntryTag entity because it's a ManyToMany relation.
187 * Instead of that SQL query we should loop on every entry and remove the tag, could be really long ...
188 *
189 * @param int $userId
190 * @param Tag $tag
191 */
192 public function removeTag($userId, Tag $tag)
193 {
194 $sql = 'DELETE et FROM entry_tag et WHERE et.entry_id IN ( SELECT e.id FROM entry e WHERE e.user_id = :userId ) AND et.tag_id = :tagId';
195 $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
196 $stmt->execute([
197 'userId' => $userId,
198 'tagId' => $tag->getId(),
199 ]);
200 }
182} 201}