diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-02-24 11:34:36 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-30 11:47:39 +0200 |
commit | 61351218f90df455c6edcc530bfc746d60b43a12 (patch) | |
tree | abb1945e9f9c648ac686eb67bb1386eb175f72d3 /src/Wallabag/ApiBundle/Controller/EntryRestController.php | |
parent | d181bd728565454ec53d960f321ed0a4c3bf26c8 (diff) | |
download | wallabag-61351218f90df455c6edcc530bfc746d60b43a12.tar.gz wallabag-61351218f90df455c6edcc530bfc746d60b43a12.tar.zst wallabag-61351218f90df455c6edcc530bfc746d60b43a12.zip |
Save changes
PHP CS
Fixed Events on changes
Renamed field
First draft for migration (create table Change)
Added setter for tag in EntryTaggedEvent
Fixed migration for Change table
Added API route for entry history
Removed deletion history
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 31bb67fd..2cf562bc 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -12,7 +12,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |||
12 | use Wallabag\CoreBundle\Entity\Entry; | 12 | use Wallabag\CoreBundle\Entity\Entry; |
13 | use Wallabag\CoreBundle\Entity\Tag; | 13 | use Wallabag\CoreBundle\Entity\Tag; |
14 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | 14 | use Wallabag\CoreBundle\Event\EntrySavedEvent; |
15 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | 15 | use Wallabag\CoreBundle\Event\EntryTaggedEvent; |
16 | use Wallabag\CoreBundle\Event\EntryUpdatedEvent; | ||
16 | 17 | ||
17 | class EntryRestController extends WallabagRestController | 18 | class EntryRestController extends WallabagRestController |
18 | { | 19 | { |
@@ -385,6 +386,8 @@ class EntryRestController extends WallabagRestController | |||
385 | $em = $this->getDoctrine()->getManager(); | 386 | $em = $this->getDoctrine()->getManager(); |
386 | $em->flush(); | 387 | $em->flush(); |
387 | 388 | ||
389 | $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry)); | ||
390 | |||
388 | return $this->sendResponse($entry); | 391 | return $this->sendResponse($entry); |
389 | } | 392 | } |
390 | 393 | ||
@@ -426,6 +429,7 @@ class EntryRestController extends WallabagRestController | |||
426 | $em->flush(); | 429 | $em->flush(); |
427 | 430 | ||
428 | // entry saved, dispatch event about it! | 431 | // entry saved, dispatch event about it! |
432 | $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry)); | ||
429 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | 433 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); |
430 | 434 | ||
431 | return $this->sendResponse($entry); | 435 | return $this->sendResponse($entry); |
@@ -496,14 +500,17 @@ class EntryRestController extends WallabagRestController | |||
496 | $this->validateUserAccess($entry->getUser()->getId()); | 500 | $this->validateUserAccess($entry->getUser()->getId()); |
497 | 501 | ||
498 | $tags = $request->request->get('tags', ''); | 502 | $tags = $request->request->get('tags', ''); |
503 | $tagsEntries = []; | ||
499 | if (!empty($tags)) { | 504 | if (!empty($tags)) { |
500 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); | 505 | $tagsEntries = $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); |
501 | } | 506 | } |
502 | 507 | ||
503 | $em = $this->getDoctrine()->getManager(); | 508 | $em = $this->getDoctrine()->getManager(); |
504 | $em->persist($entry); | 509 | $em->persist($entry); |
505 | $em->flush(); | 510 | $em->flush(); |
506 | 511 | ||
512 | $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tagsEntries)); | ||
513 | |||
507 | return $this->sendResponse($entry); | 514 | return $this->sendResponse($entry); |
508 | } | 515 | } |
509 | 516 | ||
@@ -650,4 +657,28 @@ class EntryRestController extends WallabagRestController | |||
650 | 657 | ||
651 | return (new JsonResponse())->setJson($json); | 658 | return (new JsonResponse())->setJson($json); |
652 | } | 659 | } |
660 | |||
661 | /** | ||
662 | * Gets history since a date. | ||
663 | * | ||
664 | * @ApiDoc( | ||
665 | * parameters={ | ||
666 | * {"name"="since", "dataType"="integer", "required"=true, "format"="A timestamp", "description"="Timestamp of the history's start"}, | ||
667 | * } | ||
668 | * ) | ||
669 | * | ||
670 | * @return JsonResponse | ||
671 | */ | ||
672 | public function getEntriesHistoryAction(Request $request) | ||
673 | { | ||
674 | $this->validateAuthentication(); | ||
675 | |||
676 | $res = $this->getDoctrine() | ||
677 | ->getRepository('WallabagCoreBundle:Change') | ||
678 | ->findChangesSinceDate($request->query->get('since')); | ||
679 | |||
680 | $json = $this->get('serializer')->serialize($res, 'json'); | ||
681 | |||
682 | return (new JsonResponse())->setJson($json); | ||
683 | } | ||
653 | } | 684 | } |