]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/EntryRestController.php
Save changes
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / EntryRestController.php
index 31bb67fd7d834ed391f08b2c942ca78d6c1056f9..2cf562bc5fceaf3e2333d2d743b08e92dfc028de 100644 (file)
@@ -12,7 +12,8 @@ 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\EntryTaggedEvent;
+use Wallabag\CoreBundle\Event\EntryUpdatedEvent;
 
 class EntryRestController extends WallabagRestController
 {
@@ -385,6 +386,8 @@ class EntryRestController extends WallabagRestController
         $em = $this->getDoctrine()->getManager();
         $em->flush();
 
+        $this->get('event_dispatcher')->dispatch(EntryUpdatedEvent::NAME, new EntryUpdatedEvent($entry));
+
         return $this->sendResponse($entry);
     }
 
@@ -426,6 +429,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);
@@ -496,14 +500,17 @@ 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);
+            $tagsEntries = $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
         }
 
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
         $em->flush();
 
+        $this->get('event_dispatcher')->dispatch(EntryTaggedEvent::NAME, new EntryTaggedEvent($entry, $tagsEntries));
+
         return $this->sendResponse($entry);
     }
 
@@ -650,4 +657,28 @@ class EntryRestController extends WallabagRestController
 
         return (new JsonResponse())->setJson($json);
     }
+
+    /**
+     * 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);
+    }
 }