Add entry.saved event to import & rest

This commit is contained in:
Jeremy Benoist
2016-11-02 07:10:23 +01:00
parent e0597476d1
commit 7816eb622d
17 changed files with 222 additions and 49 deletions

View File

@ -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();