diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-06-02 11:26:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-02 11:26:37 +0200 |
commit | a687c8d915276eee0c0494156700f7d0c0606735 (patch) | |
tree | 23178dc2407aa1b926b79281c34d8e05b6318d3b /src/Wallabag/ApiBundle/Controller/EntryRestController.php | |
parent | 14b8a7c950147d32d7c9782832b87bf2b18b4fd7 (diff) | |
parent | f5924e954730efdb7b9fadf23c0b73b3f5a0a434 (diff) | |
download | wallabag-a687c8d915276eee0c0494156700f7d0c0606735.tar.gz wallabag-a687c8d915276eee0c0494156700f7d0c0606735.tar.zst wallabag-a687c8d915276eee0c0494156700f7d0c0606735.zip |
Merge pull request #2708 from jcharaoui/import-disablecontentupdate
Import disableContentUpdate
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index c3ba1858..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); |
@@ -315,7 +316,7 @@ class EntryRestController extends WallabagRestController | |||
315 | } | 316 | } |
316 | 317 | ||
317 | try { | 318 | try { |
318 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | 319 | $this->get('wallabag_core.content_proxy')->updateEntry( |
319 | $entry, | 320 | $entry, |
320 | $url, | 321 | $url, |
321 | [ | 322 | [ |
@@ -428,7 +429,7 @@ class EntryRestController extends WallabagRestController | |||
428 | $this->validateUserAccess($entry->getUser()->getId()); | 429 | $this->validateUserAccess($entry->getUser()->getId()); |
429 | 430 | ||
430 | try { | 431 | try { |
431 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | 432 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); |
432 | } catch (\Exception $e) { | 433 | } catch (\Exception $e) { |
433 | $this->get('logger')->error('Error while saving an entry', [ | 434 | $this->get('logger')->error('Error while saving an entry', [ |
434 | 'exception' => $e, | 435 | 'exception' => $e, |