X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FWallabagRestController.php;h=03990088218971850a9c87240381e911c3a1a2e0;hb=refs%2Fpull%2F1699%2Fhead;hp=354a6f8e7a0b750c63ec06b26fb68a4f6506a81f;hpb=39643c6b76d92d509b1af0228b6379d7fdce8a1c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 354a6f8e..03990088 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -3,41 +3,18 @@ namespace Wallabag\ApiBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; +use Hateoas\Configuration\Route; +use Hateoas\Representation\Factory\PagerfantaFactory; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; -use Hateoas\Configuration\Route; -use Hateoas\Representation\Factory\PagerfantaFactory; 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')) { @@ -72,7 +49,6 @@ class WallabagRestController extends FOSRestController $order = $request->query->get('order', 'desc'); $page = (int) $request->query->get('page', 1); $perPage = (int) $request->query->get('perPage', 30); - $tags = $request->query->get('tags', []); $pager = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') @@ -84,7 +60,7 @@ class WallabagRestController extends FOSRestController $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); $paginatedCollection = $pagerfantaFactory->createRepresentation( $pager, - new Route('api_get_entries', [], $absolute = true) + new Route('api_get_entries', [], UrlGeneratorInterface::ABSOLUTE_URL) ); $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); @@ -139,7 +115,7 @@ class WallabagRestController extends FOSRestController $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(); @@ -191,7 +167,7 @@ class WallabagRestController extends FOSRestController $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(); @@ -269,7 +245,7 @@ class WallabagRestController extends FOSRestController $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();