mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Delete tag or tags by label
Tests not included
This commit is contained in:
parent
e71cef0bb8
commit
4da01f492b
2 changed files with 74 additions and 0 deletions
|
@ -352,6 +352,67 @@ class WallabagRestController extends FOSRestController
|
||||||
|
|
||||||
return $this->renderJsonResponse($json);
|
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.
|
* Retrieve version number.
|
||||||
*
|
*
|
||||||
|
|
|
@ -222,6 +222,19 @@ class EntryRepository extends EntityRepository
|
||||||
$this->getEntityManager()->flush();
|
$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.
|
* Find all entries that are attached to a give tag id.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue