aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index d154c18b..93c8157e 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -231,7 +231,6 @@ class EntryRestController extends WallabagRestController
231 $this->validateAuthentication(); 231 $this->validateAuthentication();
232 232
233 $urls = json_decode($request->query->get('urls', [])); 233 $urls = json_decode($request->query->get('urls', []));
234 $results = [];
235 234
236 $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions'); 235 $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions');
237 236
@@ -239,32 +238,34 @@ class EntryRestController extends WallabagRestController
239 throw new HttpException(400, 'API limit reached'); 238 throw new HttpException(400, 'API limit reached');
240 } 239 }
241 240
241 $results = [];
242 if (empty($urls)) {
243 return $this->sendResponse($results);
244 }
245
242 // handle multiple urls 246 // handle multiple urls
243 if (!empty($urls)) { 247 foreach ($urls as $key => $url) {
244 foreach ($urls as $key => $url) { 248 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId(
245 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId( 249 $url,
246 $url, 250 $this->getUser()->getId()
247 $this->getUser()->getId() 251 );
248 );
249
250 $results[$key]['url'] = $url;
251
252 if (false === $entry) {
253 $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
254 new Entry($this->getUser()),
255 $url
256 );
257 }
258 252
259 $em = $this->getDoctrine()->getManager(); 253 $results[$key]['url'] = $url;
260 $em->persist($entry);
261 $em->flush();
262 254
263 $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false; 255 if (false === $entry) {
256 $entry = new Entry($this->getUser());
264 257
265 // entry saved, dispatch event about it! 258 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $url);
266 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
267 } 259 }
260
261 $em = $this->getDoctrine()->getManager();
262 $em->persist($entry);
263 $em->flush();
264
265 $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
266
267 // entry saved, dispatch event about it!
268 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
268 } 269 }
269 270
270 return $this->sendResponse($results); 271 return $this->sendResponse($results);