From 4c84c6b6b00567bc292db0d03c795e5e293c08ba Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Tue, 28 Apr 2020 15:11:58 +0200 Subject: [PATCH] FEAT #13664 TIME 1:00 Improve check alfresco account --- .../controllers/AlfrescoController.php | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/app/external/alfresco/controllers/AlfrescoController.php b/src/app/external/alfresco/controllers/AlfrescoController.php index 55f6b134a8f..f20a644eca4 100644 --- a/src/app/external/alfresco/controllers/AlfrescoController.php +++ b/src/app/external/alfresco/controllers/AlfrescoController.php @@ -300,25 +300,43 @@ class AlfrescoController } $alfrescoUri = rtrim($configuration['uri'], '/'); - $requestBody = [ - 'query' => [ - 'query' => "select * from cmis:folder", - 'language' => 'cmis', - ], - "paging" => [ - 'maxItems' => '1' - ], - 'fields' => ['id', 'name'] - ]; - $curlResponse = CurlModel::execSimple([ - 'url' => "{$alfrescoUri}/search/versions/1/search", - 'basicAuth' => ['user' => $body['login'], 'password' => $body['password']], - 'headers' => ['content-type:application/json', 'Accept: application/json'], - 'method' => 'POST', - 'body' => json_encode($requestBody) - ]); + if (empty($body['nodeId'])) { + $requestBody = [ + 'query' => [ + 'query' => "select * from cmis:folder", + 'language' => 'cmis', + ], + "paging" => [ + 'maxItems' => '1' + ], + 'fields' => ['id', 'name'] + ]; + $curlResponse = CurlModel::execSimple([ + 'url' => "{$alfrescoUri}/search/versions/1/search", + 'basicAuth' => ['user' => $body['login'], 'password' => $body['password']], + 'headers' => ['content-type:application/json', 'Accept: application/json'], + 'method' => 'POST', + 'body' => json_encode($requestBody) + ]); + + } else { + $curlResponse = CurlModel::execSimple([ + 'url' => "{$alfrescoUri}/alfresco/versions/1/nodes/{$body['nodeId']}/children", + 'basicAuth' => ['user' => $body['login'], 'password' => $body['password']], + 'headers' => ['content-type:application/json'], + 'method' => 'GET', + 'queryParams' => ['where' => '(isFolder=true)'] + ]); + } + if ($curlResponse['code'] != 200) { - return $response->withStatus(400)->withJson(['errors' => json_encode($curlResponse['response'])]); + if ($curlResponse['code'] == 404) { + return $response->withStatus(400)->withJson(['errors' => 'Page not found', 'lang' => 'pageNotFound']); + } elseif (!empty($curlResponse['response']['error']['briefSummary'])) { + return $response->withStatus(400)->withJson(['errors' => $curlResponse['response']['error']['briefSummary']]); + } else { + return $response->withStatus(400)->withJson(['errors' => json_encode($curlResponse['response'])]); + } } return $response->withStatus(204); -- GitLab