]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/EntryRestController.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / EntryRestController.php
index 768c4fdc3423c7db828a9bca9d854bc2f884e69a..d1c95da665ecd3236592a68af65ef53081183080 100644 (file)
@@ -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);
+    }
 }