From bf6c0346d8d35a719dd1bff1cb4d573d422f99ff Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 31 May 2017 09:31:18 +0200 Subject: WIP Signed-off-by: Thomas Citharel --- .../ApiBundle/Controller/EntryRestController.php | 42 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 768c4fdc..d1c95da6 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -11,8 +11,10 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; -use Wallabag\CoreBundle\Event\EntrySavedEvent; use Wallabag\CoreBundle\Event\EntryDeletedEvent; +use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\CoreBundle\Event\EntryTaggedEvent; +use Wallabag\CoreBundle\Event\EntryUpdatedEvent; class EntryRestController extends WallabagRestController { @@ -356,6 +358,8 @@ class EntryRestController extends WallabagRestController $this->upsertEntry($entry, $request, true); + $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry)); + return $this->sendResponse($entry); } @@ -397,6 +401,7 @@ class EntryRestController extends WallabagRestController $em->flush(); // entry saved, dispatch event about it! + $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry)); $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); return $this->sendResponse($entry); @@ -467,6 +472,7 @@ class EntryRestController extends WallabagRestController $this->validateUserAccess($entry->getUser()->getId()); $tags = $request->request->get('tags', ''); + $tagsEntries = []; if (!empty($tags)) { $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); } @@ -475,6 +481,8 @@ class EntryRestController extends WallabagRestController $em->persist($entry); $em->flush(); + $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tagsEntries)); + return $this->sendResponse($entry); } @@ -668,11 +676,11 @@ class EntryRestController extends WallabagRestController } if (!is_null($isArchived)) { - $entry->setArchived((bool) $isArchived); + $entry->setArchived((bool)$isArchived); } if (!is_null($isStarred)) { - $entry->setStarred((bool) $isStarred); + $entry->setStarred((bool)$isStarred); } if (!empty($tags)) { @@ -680,9 +688,9 @@ class EntryRestController extends WallabagRestController } if (!is_null($isPublic)) { - if (true === (bool) $isPublic && null === $entry->getUid()) { + if (true === (bool)$isPublic && null === $entry->getUid()) { $entry->generateUid(); - } elseif (false === (bool) $isPublic) { + } elseif (false === (bool)$isPublic) { $entry->cleanUid(); } } @@ -694,4 +702,28 @@ class EntryRestController extends WallabagRestController // entry saved, dispatch event about it! $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); } + + /** + * Gets history since a date. + * + * @ApiDoc( + * parameters={ + * {"name"="since", "dataType"="integer", "required"=true, "format"="A timestamp", "description"="Timestamp of the history's start"}, + * } + * ) + * + * @return JsonResponse + */ + public function getEntriesHistoryAction(Request $request) + { + $this->validateAuthentication(); + + $res = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Change') + ->findChangesSinceDate($request->query->get('since')); + + $json = $this->get('serializer')->serialize($res, 'json'); + + return (new JsonResponse())->setJson($json); + } } -- cgit v1.2.3