X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FWallabagRestController.php;h=50652b777e9fe9b9bf9127640193be9b7405cc85;hb=da4136557963018287cae61226e9006c3c741747;hp=0c709ca099dfb964715338ce96ab413ef4310900;hpb=3199ec4702cec9c10ad0c663bcf6ce799068c9aa;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 0c709ca0..50652b77 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -14,6 +14,8 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\AnnotationBundle\Entity\Annotation; +use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\CoreBundle\Event\EntryDeletedEvent; class WallabagRestController extends FOSRestController { @@ -233,9 +235,11 @@ class WallabagRestController extends FOSRestController $em = $this->getDoctrine()->getManager(); $em->persist($entry); - $em->flush(); + // entry saved, dispatch event about it! + $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); + $json = $this->get('serializer')->serialize($entry, 'json'); return (new JsonResponse())->setJson($json); @@ -308,6 +312,9 @@ class WallabagRestController extends FOSRestController $this->validateAuthentication(); $this->validateUserAccess($entry->getUser()->getId()); + // entry deleted, dispatch event about it! + $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); + $em = $this->getDoctrine()->getManager(); $em->remove($entry); $em->flush(); @@ -536,7 +543,7 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [ + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [ 'entry' => $entry, ]); } @@ -544,10 +551,6 @@ class WallabagRestController extends FOSRestController /** * Creates a new annotation. * - * @param Request $request - * @param Entry $entry - * - * @return JsonResponse * @ApiDoc( * requirements={ * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"}, @@ -555,15 +558,20 @@ class WallabagRestController extends FOSRestController * {"name"="text", "dataType"="string", "required"=true, "description"=""}, * } * ) + * + * @param Request $request + * @param Entry $entry + * + * @return JsonResponse */ public function postAnnotationAction(Request $request, Entry $entry) { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [ - 'request' => $request, - 'entry' => $entry, - ]); + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:postAnnotation', [ + 'request' => $request, + 'entry' => $entry, + ]); } /** @@ -586,10 +594,10 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [ - 'annotation' => $annotation, - 'request' => $request, - ]); + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:putAnnotation', [ + 'annotation' => $annotation, + 'request' => $request, + ]); } /** @@ -611,9 +619,9 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [ - 'annotation' => $annotation, - ]); + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [ + 'annotation' => $annotation, + ]); } /**