]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Delete tag or tags by label
authorThomas Citharel <tcit@tcit.fr>
Sat, 25 Jun 2016 16:37:41 +0000 (18:37 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 23 Aug 2016 05:26:58 +0000 (07:26 +0200)
Tests not included

src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php

index 03eb9b0848272381bfbc3dd550c476068d55dcd3..8eaff5f6b0c1610a18ed989aa1dd427584f03660 100644 (file)
@@ -352,6 +352,67 @@ class WallabagRestController extends FOSRestController
 
         return $this->renderJsonResponse($json);
     }
+
+    /**
+     * Permanently remove one tag from **every** entry.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag as a string"}
+     *      }
+     * )
+     *
+     * @return Response
+     */
+    public function deleteTagLabelAction(Request $request)
+    {
+        $this->validateAuthentication();
+        $label = $request->query->get('tag','');
+
+        $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label);
+        $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->removeTag($this->getUser()->getId(), $tag);
+
+        $json = $this->get('serializer')->serialize($tag, 'json');
+
+        return $this->renderJsonResponse($json);
+    }
+
+    /**
+     * Permanently remove some tags from **every** entry.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="tags", "dataType"="string", "required"=true, "format"="tag1,tag2", "description"="The tags as strings"}
+     *      }
+     * )
+     *
+     * @return Response
+     */
+    public function deleteTagsLabelAction(Request $request)
+    {
+        $this->validateAuthentication();
+
+        $tagsLabels = $request->query->get('tags', '');
+
+        $tags = array();
+
+        foreach (explode(',', $tagsLabels) as $tagLabel) {
+            $tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
+            $tags[] = $tagEntity;
+        }
+
+        $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->removeTags($this->getUser()->getId(), $tags);
+
+        $json = $this->get('serializer')->serialize($tags, 'json');
+
+        return $this->renderJsonResponse($json);
+    }
+
+
     /**
      * Retrieve version number.
      *
index e9351d85ef439451584a7b2315c5a1fbc56854b9..63c4c3be9f0f21f021a2c9d010f9fb3085499439 100644 (file)
@@ -222,6 +222,19 @@ class EntryRepository extends EntityRepository
         $this->getEntityManager()->flush();
     }
 
+    /**
+     * Remove tags from all user entries
+     *
+     * @param int $userId
+     * @param Array<Tag> $tags
+     */
+
+    public function removeTags($userId, $tags) {
+        foreach ($tags as $tag) {
+            $this->removeTag($userId, $tag);
+        }
+    }
+
     /**
      * Find all entries that are attached to a give tag id.
      *