@@ -36,87 +36,87 @@ |
||
| 36 | 36 | |
| 37 | 37 | class LookupPlugin implements ISearchPlugin { |
| 38 | 38 | |
| 39 | - /** @var IConfig */ |
|
| 40 | - private $config; |
|
| 41 | - /** @var IClientService */ |
|
| 42 | - private $clientService; |
|
| 43 | - /** @var string remote part of the current user's cloud id */ |
|
| 44 | - private $currentUserRemote; |
|
| 45 | - /** @var ICloudIdManager */ |
|
| 46 | - private $cloudIdManager; |
|
| 47 | - /** @var ILogger */ |
|
| 48 | - private $logger; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + private $config; |
|
| 41 | + /** @var IClientService */ |
|
| 42 | + private $clientService; |
|
| 43 | + /** @var string remote part of the current user's cloud id */ |
|
| 44 | + private $currentUserRemote; |
|
| 45 | + /** @var ICloudIdManager */ |
|
| 46 | + private $cloudIdManager; |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $logger; |
|
| 49 | 49 | |
| 50 | - public function __construct(IConfig $config, |
|
| 51 | - IClientService $clientService, |
|
| 52 | - IUserSession $userSession, |
|
| 53 | - ICloudIdManager $cloudIdManager, |
|
| 54 | - ILogger $logger) { |
|
| 55 | - $this->config = $config; |
|
| 56 | - $this->clientService = $clientService; |
|
| 57 | - $this->cloudIdManager = $cloudIdManager; |
|
| 58 | - $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
| 59 | - $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
| 60 | - $this->logger = $logger; |
|
| 61 | - } |
|
| 50 | + public function __construct(IConfig $config, |
|
| 51 | + IClientService $clientService, |
|
| 52 | + IUserSession $userSession, |
|
| 53 | + ICloudIdManager $cloudIdManager, |
|
| 54 | + ILogger $logger) { |
|
| 55 | + $this->config = $config; |
|
| 56 | + $this->clientService = $clientService; |
|
| 57 | + $this->cloudIdManager = $cloudIdManager; |
|
| 58 | + $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
| 59 | + $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
| 60 | + $this->logger = $logger; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
| 64 | - $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
| 65 | - $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
|
| 66 | - $hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); |
|
| 63 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
| 64 | + $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
| 65 | + $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
|
| 66 | + $hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); |
|
| 67 | 67 | |
| 68 | - // if case of Global Scale we always search the lookup server |
|
| 69 | - if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 68 | + // if case of Global Scale we always search the lookup server |
|
| 69 | + if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 74 | - if(empty($lookupServerUrl)) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 77 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 78 | - $result = []; |
|
| 73 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 74 | + if(empty($lookupServerUrl)) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 78 | + $result = []; |
|
| 79 | 79 | |
| 80 | - try { |
|
| 81 | - $client = $this->clientService->newClient(); |
|
| 82 | - $response = $client->get( |
|
| 83 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 84 | - [ |
|
| 85 | - 'timeout' => 10, |
|
| 86 | - 'connect_timeout' => 3, |
|
| 87 | - ] |
|
| 88 | - ); |
|
| 80 | + try { |
|
| 81 | + $client = $this->clientService->newClient(); |
|
| 82 | + $response = $client->get( |
|
| 83 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 84 | + [ |
|
| 85 | + 'timeout' => 10, |
|
| 86 | + 'connect_timeout' => 3, |
|
| 87 | + ] |
|
| 88 | + ); |
|
| 89 | 89 | |
| 90 | - $body = json_decode($response->getBody(), true); |
|
| 90 | + $body = json_decode($response->getBody(), true); |
|
| 91 | 91 | |
| 92 | - foreach ($body as $lookup) { |
|
| 93 | - try { |
|
| 94 | - $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
| 95 | - } catch (\Exception $e) { |
|
| 96 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
| 97 | - $this->logger->error($e->getMessage()); |
|
| 98 | - continue; |
|
| 99 | - } |
|
| 100 | - if ($this->currentUserRemote === $remote) { |
|
| 101 | - continue; |
|
| 102 | - } |
|
| 103 | - $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
| 104 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 105 | - $result[] = [ |
|
| 106 | - 'label' => $label, |
|
| 107 | - 'value' => [ |
|
| 108 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 109 | - 'shareWith' => $lookup['federationId'], |
|
| 110 | - ], |
|
| 111 | - 'extra' => $lookup, |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 114 | - } catch (\Exception $e) { |
|
| 115 | - } |
|
| 92 | + foreach ($body as $lookup) { |
|
| 93 | + try { |
|
| 94 | + $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
| 95 | + } catch (\Exception $e) { |
|
| 96 | + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
| 97 | + $this->logger->error($e->getMessage()); |
|
| 98 | + continue; |
|
| 99 | + } |
|
| 100 | + if ($this->currentUserRemote === $remote) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | + $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
| 104 | + $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 105 | + $result[] = [ |
|
| 106 | + 'label' => $label, |
|
| 107 | + 'value' => [ |
|
| 108 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
| 109 | + 'shareWith' => $lookup['federationId'], |
|
| 110 | + ], |
|
| 111 | + 'extra' => $lookup, |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | + } catch (\Exception $e) { |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $type = new SearchResultType('lookup'); |
|
| 118 | - $searchResult->addResultSet($type, $result, []); |
|
| 117 | + $type = new SearchResultType('lookup'); |
|
| 118 | + $searchResult->addResultSet($type, $result, []); |
|
| 119 | 119 | |
| 120 | - return false; |
|
| 121 | - } |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function search($search, $limit, $offset, ISearchResult $searchResult) { |
| 64 | 64 | $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
| 65 | 65 | $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; |
| 66 | - $hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true); |
|
| 66 | + $hasInternetConnection = (bool) $this->config->getSystemValue('has_internet_connection', true); |
|
| 67 | 67 | |
| 68 | 68 | // if case of Global Scale we always search the lookup server |
| 69 | 69 | if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
| 74 | - if(empty($lookupServerUrl)) { |
|
| 74 | + if (empty($lookupServerUrl)) { |
|
| 75 | 75 | return false; |
| 76 | 76 | } |
| 77 | 77 | $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | try { |
| 81 | 81 | $client = $this->clientService->newClient(); |
| 82 | 82 | $response = $client->get( |
| 83 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 83 | + $lookupServerUrl.'/users?search='.urlencode($search), |
|
| 84 | 84 | [ |
| 85 | 85 | 'timeout' => 10, |
| 86 | 86 | 'connect_timeout' => 3, |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | try { |
| 94 | 94 | $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
| 95 | 95 | } catch (\Exception $e) { |
| 96 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); |
|
| 96 | + $this->logger->error('Can not parse federated cloud ID "'.$lookup['federationId'].'"'); |
|
| 97 | 97 | $this->logger->error($e->getMessage()); |
| 98 | 98 | continue; |
| 99 | 99 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | continue; |
| 102 | 102 | } |
| 103 | 103 | $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
| 104 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 104 | + $label = empty($name) ? $lookup['federationId'] : $name.' ('.$lookup['federationId'].')'; |
|
| 105 | 105 | $result[] = [ |
| 106 | 106 | 'label' => $label, |
| 107 | 107 | 'value' => [ |