$this->validateAuthentication();
$label = $request->get('tag', '');
- $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label);
+ $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser([$label], $this->getUser()->getId());
- if (empty($tag)) {
+ if (empty($tags)) {
throw $this->createNotFoundException('Tag not found');
}
+ $tag = $tags[0];
+
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->removeTag($this->getUser()->getId(), $tag);
$tagsLabels = $request->get('tags', '');
- $tags = [];
-
- foreach (explode(',', $tagsLabels) as $tagLabel) {
- $tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
-
- if (!empty($tagEntity)) {
- $tags[] = $tagEntity;
- }
- }
+ $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser(explode(',', $tagsLabels), $this->getUser()->getId());
if (empty($tags)) {
throw $this->createNotFoundException('Tags not found');
{
$this->validateAuthentication();
+ $tagFromDb = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findByLabelsAndUser([$tag->getLabel()], $this->getUser()->getId());
+
+ if (empty($tagFromDb)) {
+ throw $this->createNotFoundException('Tag not found');
+ }
+
$this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->removeTag($this->getUser()->getId(), $tag);
->getArrayResult();
}
+ public function findByLabelsAndUser($labels, $userId)
+ {
+ $qb = $this->getQueryBuilderByUser($userId)
+ ->select('t.id');
+
+ $ids = $qb->andWhere($qb->expr()->in('t.label', $labels))
+ ->getQuery()
+ ->getArrayResult();
+
+ $tags = [];
+ foreach ($ids as $id) {
+ $tags[] = $this->find($id);
+ }
+
+ return $tags;
+ }
+
/**
* Used only in test case to get a tag for our entry.
*