diff options
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 26746f7d..0ecf1a0e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -27,10 +27,10 @@ class EntryRestController extends WallabagRestController | |||
27 | * @ApiDoc( | 27 | * @ApiDoc( |
28 | * parameters={ | 28 | * parameters={ |
29 | * {"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"}, | 29 | * {"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"}, |
30 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, | 30 | * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="DEPRECATED, use hashed_url instead"}, |
31 | * {"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"} | 31 | * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="DEPRECATED, use hashed_urls instead"}, |
32 | * {"name"="hashedurl", "dataType"="string", "required"=true, "format"="An url", "description"="Md5 url to check if it exists"}, | 32 | * {"name"="hashed_url", "dataType"="string", "required"=true, "format"="An url", "description"="Md5 url to check if it exists"}, |
33 | * {"name"="hashedurls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Md5 urls (as an array) to check if it exists"} | 33 | * {"name"="hashed_urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Md5 urls (as an array) to check if it exists"} |
34 | * } | 34 | * } |
35 | * ) | 35 | * ) |
36 | * | 36 | * |
@@ -39,22 +39,18 @@ class EntryRestController extends WallabagRestController | |||
39 | public function getEntriesExistsAction(Request $request) | 39 | public function getEntriesExistsAction(Request $request) |
40 | { | 40 | { |
41 | $this->validateAuthentication(); | 41 | $this->validateAuthentication(); |
42 | $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); | ||
42 | 43 | ||
43 | $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); | 44 | $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); |
44 | $urls = $request->query->get('urls', []); | ||
45 | 45 | ||
46 | $hashedUrls = $request->query->get('hashedurls', []); | 46 | $urls = $request->query->get('urls', []); |
47 | $hashedUrls = $request->query->get('hashed_urls', []); | ||
47 | 48 | ||
48 | // handle multiple urls first | 49 | // handle multiple urls first |
49 | if (!empty($hashedUrls)) { | 50 | if (!empty($hashedUrls)) { |
50 | $results = []; | 51 | $results = []; |
51 | foreach ($hashedUrls as $hashedUrl) { | 52 | foreach ($hashedUrls as $hashedUrl) { |
52 | $res = $this->getDoctrine() | 53 | $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId()); |
53 | ->getRepository('WallabagCoreBundle:Entry') | ||
54 | ->findOneBy([ | ||
55 | 'hashedUrl' => $hashedUrl, | ||
56 | 'user' => $this->getUser()->getId(), | ||
57 | ]); | ||
58 | 54 | ||
59 | // $results[$url] = $this->returnExistInformation($res, $returnId); | 55 | // $results[$url] = $this->returnExistInformation($res, $returnId); |
60 | $results[$hashedUrl] = $this->returnExistInformation($res, $returnId); | 56 | $results[$hashedUrl] = $this->returnExistInformation($res, $returnId); |
@@ -63,24 +59,33 @@ class EntryRestController extends WallabagRestController | |||
63 | return $this->sendResponse($results); | 59 | return $this->sendResponse($results); |
64 | } | 60 | } |
65 | 61 | ||
62 | // @deprecated, to be remove in 3.0 | ||
63 | if (!empty($urls)) { | ||
64 | $results = []; | ||
65 | foreach ($urls as $url) { | ||
66 | $res = $repo->findByUrlAndUserId($url, $this->getUser()->getId()); | ||
67 | |||
68 | $results[$url] = $this->returnExistInformation($res, $returnId); | ||
69 | } | ||
70 | |||
71 | return $this->sendResponse($results); | ||
72 | } | ||
73 | |||
66 | // let's see if it is a simple url? | 74 | // let's see if it is a simple url? |
67 | $hashedUrl = $request->query->get('hashedurl', ''); | 75 | $url = $request->query->get('url', ''); |
76 | $hashedUrl = $request->query->get('hashed_url', ''); | ||
68 | 77 | ||
69 | // if (empty($url)) { | 78 | if (empty($url) && empty($hashedUrl)) { |
70 | // throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); | 79 | throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); |
71 | // } | 80 | } |
72 | 81 | ||
73 | if (empty($hashedUrl)) { | 82 | $method = 'findByUrlAndUserId'; |
74 | throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser()->getId()); | 83 | if (!empty($hashedUrl)) { |
84 | $method = 'findByHashedUrlAndUserId'; | ||
85 | $url = $hashedUrl; | ||
75 | } | 86 | } |
76 | 87 | ||
77 | $res = $this->getDoctrine() | 88 | $res = $repo->$method($url, $this->getUser()->getId()); |
78 | ->getRepository('WallabagCoreBundle:Entry') | ||
79 | // ->findByUrlAndUserId($url, $this->getUser()->getId()); | ||
80 | ->findOneBy([ | ||
81 | 'hashedUrl' => $hashedUrl, | ||
82 | 'user' => $this->getUser()->getId(), | ||
83 | ]); | ||
84 | 89 | ||
85 | return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]); | 90 | return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]); |
86 | } | 91 | } |