aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-02-19 21:21:47 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-02-19 21:21:47 +0100
commit0cde91cc6f42497844866d7631b8f28e024af965 (patch)
tree3cca40042f576a67672bde1236bd059b710f4f97 /src/Wallabag/ApiBundle
parenta8c6b8ee0cb4e77731df502a05479a8501806309 (diff)
parentc2656f96d4776c86b13d8a4c93a78ee7c4d3824c (diff)
downloadwallabag-0cde91cc6f42497844866d7631b8f28e024af965.tar.gz
wallabag-0cde91cc6f42497844866d7631b8f28e024af965.tar.zst
wallabag-0cde91cc6f42497844866d7631b8f28e024af965.zip
Merge pull request #1699 from wallabag/v2-assign-tag
Move assignTagsToEntry in ContentProxy helper
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php31
1 files changed, 3 insertions, 28 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 84bc14a9..03990088 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -15,31 +15,6 @@ use Wallabag\CoreBundle\Entity\Tag;
15 15
16class WallabagRestController extends FOSRestController 16class WallabagRestController extends FOSRestController
17{ 17{
18 /**
19 * @param Entry $entry
20 * @param string $tags
21 */
22 private function assignTagsToEntry(Entry $entry, $tags)
23 {
24 foreach (explode(',', $tags) as $label) {
25 $label = trim($label);
26 $tagEntity = $this
27 ->getDoctrine()
28 ->getRepository('WallabagCoreBundle:Tag')
29 ->findOneByLabel($label);
30
31 if (is_null($tagEntity)) {
32 $tagEntity = new Tag();
33 $tagEntity->setLabel($label);
34 }
35
36 // only add the tag on the entry if the relation doesn't exist
37 if (!$entry->getTags()->contains($tagEntity)) {
38 $entry->addTag($tagEntity);
39 }
40 }
41 }
42
43 private function validateAuthentication() 18 private function validateAuthentication()
44 { 19 {
45 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { 20 if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
@@ -140,7 +115,7 @@ class WallabagRestController extends FOSRestController
140 115
141 $tags = $request->request->get('tags', ''); 116 $tags = $request->request->get('tags', '');
142 if (!empty($tags)) { 117 if (!empty($tags)) {
143 $this->assignTagsToEntry($entry, $tags); 118 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
144 } 119 }
145 120
146 $em = $this->getDoctrine()->getManager(); 121 $em = $this->getDoctrine()->getManager();
@@ -192,7 +167,7 @@ class WallabagRestController extends FOSRestController
192 167
193 $tags = $request->request->get('tags', ''); 168 $tags = $request->request->get('tags', '');
194 if (!empty($tags)) { 169 if (!empty($tags)) {
195 $this->assignTagsToEntry($entry, $tags); 170 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
196 } 171 }
197 172
198 $em = $this->getDoctrine()->getManager(); 173 $em = $this->getDoctrine()->getManager();
@@ -270,7 +245,7 @@ class WallabagRestController extends FOSRestController
270 245
271 $tags = $request->request->get('tags', ''); 246 $tags = $request->request->get('tags', '');
272 if (!empty($tags)) { 247 if (!empty($tags)) {
273 $this->assignTagsToEntry($entry, $tags); 248 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
274 } 249 }
275 250
276 $em = $this->getDoctrine()->getManager(); 251 $em = $this->getDoctrine()->getManager();