class WallabagRestController extends FOSRestController
{
- /**
- * @param Entry $entry
- * @param string $tags
- */
- private function assignTagsToEntry(Entry $entry, $tags)
- {
- foreach (explode(',', $tags) as $label) {
- $label = trim($label);
- $tagEntity = $this
- ->getDoctrine()
- ->getRepository('WallabagCoreBundle:Tag')
- ->findOneByLabel($label);
-
- if (is_null($tagEntity)) {
- $tagEntity = new Tag();
- $tagEntity->setLabel($label);
- }
-
- // only add the tag on the entry if the relation doesn't exist
- if (!$entry->getTags()->contains($tagEntity)) {
- $entry->addTag($tagEntity);
- }
- }
- }
-
private function validateAuthentication()
{
if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
* {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."},
* {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."},
* {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
+ * {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"},
+ * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"},
* }
* )
*
$this->validateAuthentication();
$url = $request->request->get('url');
+ $isArchived = $request->request->get('archive');
+ $isStarred = $request->request->get('starred');
$entry = $this->get('wallabag_core.content_proxy')->updateEntry(
new Entry($this->getUser()),
$tags = $request->request->get('tags', '');
if (!empty($tags)) {
- $this->assignTagsToEntry($entry, $tags);
+ $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
+ }
+
+ if (true === (bool) $isStarred) {
+ $entry->setStarred(true);
+ }
+
+ if (true === (bool) $isArchived) {
+ $entry->setArchived(true);
}
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
+
$em->flush();
$json = $this->get('serializer')->serialize($entry, 'json');
$tags = $request->request->get('tags', '');
if (!empty($tags)) {
- $this->assignTagsToEntry($entry, $tags);
+ $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
}
$em = $this->getDoctrine()->getManager();
$tags = $request->request->get('tags', '');
if (!empty($tags)) {
- $this->assignTagsToEntry($entry, $tags);
+ $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
}
$em = $this->getDoctrine()->getManager();