aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php42
1 files changed, 37 insertions, 5 deletions
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;
11use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 11use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12use Wallabag\CoreBundle\Entity\Entry; 12use Wallabag\CoreBundle\Entity\Entry;
13use Wallabag\CoreBundle\Entity\Tag; 13use Wallabag\CoreBundle\Entity\Tag;
14use Wallabag\CoreBundle\Event\EntrySavedEvent;
15use Wallabag\CoreBundle\Event\EntryDeletedEvent; 14use Wallabag\CoreBundle\Event\EntryDeletedEvent;
15use Wallabag\CoreBundle\Event\EntrySavedEvent;
16use Wallabag\CoreBundle\Event\EntryTaggedEvent;
17use Wallabag\CoreBundle\Event\EntryUpdatedEvent;
16 18
17class EntryRestController extends WallabagRestController 19class EntryRestController extends WallabagRestController
18{ 20{
@@ -356,6 +358,8 @@ class EntryRestController extends WallabagRestController
356 358
357 $this->upsertEntry($entry, $request, true); 359 $this->upsertEntry($entry, $request, true);
358 360
361 $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry));
362
359 return $this->sendResponse($entry); 363 return $this->sendResponse($entry);
360 } 364 }
361 365
@@ -397,6 +401,7 @@ class EntryRestController extends WallabagRestController
397 $em->flush(); 401 $em->flush();
398 402
399 // entry saved, dispatch event about it! 403 // entry saved, dispatch event about it!
404 $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry));
400 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); 405 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
401 406
402 return $this->sendResponse($entry); 407 return $this->sendResponse($entry);
@@ -467,6 +472,7 @@ class EntryRestController extends WallabagRestController
467 $this->validateUserAccess($entry->getUser()->getId()); 472 $this->validateUserAccess($entry->getUser()->getId());
468 473
469 $tags = $request->request->get('tags', ''); 474 $tags = $request->request->get('tags', '');
475 $tagsEntries = [];
470 if (!empty($tags)) { 476 if (!empty($tags)) {
471 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 477 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
472 } 478 }
@@ -475,6 +481,8 @@ class EntryRestController extends WallabagRestController
475 $em->persist($entry); 481 $em->persist($entry);
476 $em->flush(); 482 $em->flush();
477 483
484 $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tagsEntries));
485
478 return $this->sendResponse($entry); 486 return $this->sendResponse($entry);
479 } 487 }
480 488
@@ -668,11 +676,11 @@ class EntryRestController extends WallabagRestController
668 } 676 }
669 677
670 if (!is_null($isArchived)) { 678 if (!is_null($isArchived)) {
671 $entry->setArchived((bool) $isArchived); 679 $entry->setArchived((bool)$isArchived);
672 } 680 }
673 681
674 if (!is_null($isStarred)) { 682 if (!is_null($isStarred)) {
675 $entry->setStarred((bool) $isStarred); 683 $entry->setStarred((bool)$isStarred);
676 } 684 }
677 685
678 if (!empty($tags)) { 686 if (!empty($tags)) {
@@ -680,9 +688,9 @@ class EntryRestController extends WallabagRestController
680 } 688 }
681 689
682 if (!is_null($isPublic)) { 690 if (!is_null($isPublic)) {
683 if (true === (bool) $isPublic && null === $entry->getUid()) { 691 if (true === (bool)$isPublic && null === $entry->getUid()) {
684 $entry->generateUid(); 692 $entry->generateUid();
685 } elseif (false === (bool) $isPublic) { 693 } elseif (false === (bool)$isPublic) {
686 $entry->cleanUid(); 694 $entry->cleanUid();
687 } 695 }
688 } 696 }
@@ -694,4 +702,28 @@ class EntryRestController extends WallabagRestController
694 // entry saved, dispatch event about it! 702 // entry saved, dispatch event about it!
695 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); 703 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
696 } 704 }
705
706 /**
707 * Gets history since a date.
708 *
709 * @ApiDoc(
710 * parameters={
711 * {"name"="since", "dataType"="integer", "required"=true, "format"="A timestamp", "description"="Timestamp of the history's start"},
712 * }
713 * )
714 *
715 * @return JsonResponse
716 */
717 public function getEntriesHistoryAction(Request $request)
718 {
719 $this->validateAuthentication();
720
721 $res = $this->getDoctrine()
722 ->getRepository('WallabagCoreBundle:Change')
723 ->findChangesSinceDate($request->query->get('since'));
724
725 $json = $this->get('serializer')->serialize($res, 'json');
726
727 return (new JsonResponse())->setJson($json);
728 }
697} 729}