diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-06-23 08:30:23 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-06-23 08:30:23 +0200 |
commit | 18696f77fdc76f7055d84460d459051a6bb7253a (patch) | |
tree | 445651b0962e18b842b86244a9c0ba26462785b9 /src/Wallabag | |
parent | 29714661b1df78871ceaf0e079f11041a8641d4b (diff) | |
download | wallabag-18696f77fdc76f7055d84460d459051a6bb7253a.tar.gz wallabag-18696f77fdc76f7055d84460d459051a6bb7253a.tar.zst wallabag-18696f77fdc76f7055d84460d459051a6bb7253a.zip |
Avoid BC on exists endpoint
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 768c4fdc..793b91ba 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -18,9 +18,12 @@ class EntryRestController extends WallabagRestController | |||
18 | { | 18 | { |
19 | /** | 19 | /** |
20 | * Check if an entry exist by url. | 20 | * Check if an entry exist by url. |
21 | * Return ID if entry(ies) exist (and if you give the return_id parameter). | ||
22 | * Otherwise it returns false. | ||
21 | * | 23 | * |
22 | * @ApiDoc( | 24 | * @ApiDoc( |
23 | * parameters={ | 25 | * parameters={ |
26 | * {"name"="return_id", "dataType"="string", "required"=false, "format"="1 or 0", "description"="Set 1 if you want to retrieve ID in case entry(ies) exists, 0 by default"}, | ||
24 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, | 27 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, |
25 | * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Urls (as an array) to check if it exists"} | 28 | * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Urls (as an array) to check if it exists"} |
26 | * } | 29 | * } |
@@ -32,6 +35,7 @@ class EntryRestController extends WallabagRestController | |||
32 | { | 35 | { |
33 | $this->validateAuthentication(); | 36 | $this->validateAuthentication(); |
34 | 37 | ||
38 | $returnId = (null === $request->query->get('return_id')) ? 0 : (bool) $request->query->get('return_id'); | ||
35 | $urls = $request->query->get('urls', []); | 39 | $urls = $request->query->get('urls', []); |
36 | 40 | ||
37 | // handle multiple urls first | 41 | // handle multiple urls first |
@@ -42,7 +46,7 @@ class EntryRestController extends WallabagRestController | |||
42 | ->getRepository('WallabagCoreBundle:Entry') | 46 | ->getRepository('WallabagCoreBundle:Entry') |
43 | ->findByUrlAndUserId($url, $this->getUser()->getId()); | 47 | ->findByUrlAndUserId($url, $this->getUser()->getId()); |
44 | 48 | ||
45 | $results[$url] = $res instanceof Entry ? $res->getId() : false; | 49 | $results[$url] = $res instanceof Entry ? ($returnId ? $res->getId() : true) : false; |
46 | } | 50 | } |
47 | 51 | ||
48 | return $this->sendResponse($results); | 52 | return $this->sendResponse($results); |
@@ -59,7 +63,7 @@ class EntryRestController extends WallabagRestController | |||
59 | ->getRepository('WallabagCoreBundle:Entry') | 63 | ->getRepository('WallabagCoreBundle:Entry') |
60 | ->findByUrlAndUserId($url, $this->getUser()->getId()); | 64 | ->findByUrlAndUserId($url, $this->getUser()->getId()); |
61 | 65 | ||
62 | $exists = $res instanceof Entry ? $res->getId() : false; | 66 | $exists = $res instanceof Entry ? ($returnId ? $res->getId() : true) : false; |
63 | 67 | ||
64 | return $this->sendResponse(['exists' => $exists]); | 68 | return $this->sendResponse(['exists' => $exists]); |
65 | } | 69 | } |