+ /**
+ * Handles an entries list and delete URL.
+ *
+ * @ApiDoc(
+ * parameters={
+ * {"name"="urls", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...'}, {'url': 'http://...'}]", "description"="Urls (as an array) to delete."}
+ * }
+ * )
+ *
+ * @return JsonResponse
+ */
+ public function deleteEntriesListAction(Request $request)
+ {
+ $this->validateAuthentication();
+
+ $urls = json_decode($request->query->get('urls', []));
+
+ if (empty($urls)) {
+ return $this->sendResponse([]);
+ }
+
+ $results = [];
+
+ // handle multiple urls
+ foreach ($urls as $key => $url) {
+ $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
+ $url,
+ $this->getUser()->getId()
+ );
+
+ $results[$key]['url'] = $url;
+
+ if (false !== $entry) {
+ $em = $this->getDoctrine()->getManager();
+ $em->remove($entry);
+ $em->flush();
+
+ // entry deleted, dispatch event about it!
+ $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
+ }
+
+ $results[$key]['entry'] = $entry instanceof Entry ? true : false;
+ }
+
+ return $this->sendResponse($results);
+ }
+
+ /**
+ * Handles an entries list and create URL.
+ *
+ * @ApiDoc(
+ * parameters={
+ * {"name"="urls", "dataType"="string", "required"=true, "format"="A JSON array of urls [{'url': 'http://...'}, {'url': 'http://...'}]", "description"="Urls (as an array) to create."}
+ * }
+ * )
+ *
+ * @throws HttpException When limit is reached
+ *
+ * @return JsonResponse
+ */
+ public function postEntriesListAction(Request $request)
+ {
+ $this->validateAuthentication();
+
+ $urls = json_decode($request->query->get('urls', []));
+
+ $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions');
+
+ if (\count($urls) > $limit) {
+ throw new HttpException(400, 'API limit reached');
+ }
+
+ $results = [];
+ if (empty($urls)) {
+ return $this->sendResponse($results);
+ }
+
+ // handle multiple urls
+ foreach ($urls as $key => $url) {
+ $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
+ $url,
+ $this->getUser()->getId()
+ );
+
+ $results[$key]['url'] = $url;
+
+ if (false === $entry) {
+ $entry = new Entry($this->getUser());
+
+ $this->get('wallabag_core.content_proxy')->updateEntry($entry, $url);
+ }
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
+
+ $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
+
+ // entry saved, dispatch event about it!
+ $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
+ }
+
+ return $this->sendResponse($results);
+ }
+