@@ -30,105 +30,105 @@ |
||
30 | 30 | use OCP\ILogger; |
31 | 31 | |
32 | 32 | class RetryJob extends Job { |
33 | - /** @var IClientService */ |
|
34 | - private $clientService; |
|
35 | - /** @var IJobList */ |
|
36 | - private $jobList; |
|
37 | - /** @var string */ |
|
38 | - private $lookupServer; |
|
39 | - /** @var int how much time should be between two, will be increased for each retry */ |
|
40 | - private $interval = 100; |
|
33 | + /** @var IClientService */ |
|
34 | + private $clientService; |
|
35 | + /** @var IJobList */ |
|
36 | + private $jobList; |
|
37 | + /** @var string */ |
|
38 | + private $lookupServer; |
|
39 | + /** @var int how much time should be between two, will be increased for each retry */ |
|
40 | + private $interval = 100; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IClientService $clientService |
|
44 | - * @param IJobList $jobList |
|
45 | - * @param IConfig $config |
|
46 | - */ |
|
47 | - public function __construct(IClientService $clientService, |
|
48 | - IJobList $jobList, |
|
49 | - IConfig $config) { |
|
50 | - $this->clientService = $clientService; |
|
51 | - $this->jobList = $jobList; |
|
42 | + /** |
|
43 | + * @param IClientService $clientService |
|
44 | + * @param IJobList $jobList |
|
45 | + * @param IConfig $config |
|
46 | + */ |
|
47 | + public function __construct(IClientService $clientService, |
|
48 | + IJobList $jobList, |
|
49 | + IConfig $config) { |
|
50 | + $this->clientService = $clientService; |
|
51 | + $this->jobList = $jobList; |
|
52 | 52 | |
53 | - if ($config->getSystemValue('has_internet_connection', true) === false) { |
|
54 | - return; |
|
55 | - } |
|
53 | + if ($config->getSystemValue('has_internet_connection', true) === false) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
58 | - if (!empty($this->lookupServer)) { |
|
59 | - $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
60 | - $this->lookupServer .= '/users'; |
|
61 | - } |
|
62 | - } |
|
57 | + $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
58 | + if (!empty($this->lookupServer)) { |
|
59 | + $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
60 | + $this->lookupServer .= '/users'; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * run the job, then remove it from the jobList |
|
66 | - * |
|
67 | - * @param JobList $jobList |
|
68 | - * @param ILogger|null $logger |
|
69 | - */ |
|
70 | - public function execute($jobList, ILogger $logger = null) { |
|
71 | - if ($this->shouldRun($this->argument)) { |
|
72 | - parent::execute($jobList, $logger); |
|
73 | - $jobList->remove($this, $this->argument); |
|
74 | - } |
|
75 | - } |
|
64 | + /** |
|
65 | + * run the job, then remove it from the jobList |
|
66 | + * |
|
67 | + * @param JobList $jobList |
|
68 | + * @param ILogger|null $logger |
|
69 | + */ |
|
70 | + public function execute($jobList, ILogger $logger = null) { |
|
71 | + if ($this->shouldRun($this->argument)) { |
|
72 | + parent::execute($jobList, $logger); |
|
73 | + $jobList->remove($this, $this->argument); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - protected function run($argument) { |
|
78 | - if ($this->killBackgroundJob((int)$argument['retryNo'])) { |
|
79 | - return; |
|
80 | - } |
|
77 | + protected function run($argument) { |
|
78 | + if ($this->killBackgroundJob((int)$argument['retryNo'])) { |
|
79 | + return; |
|
80 | + } |
|
81 | 81 | |
82 | - $client = $this->clientService->newClient(); |
|
82 | + $client = $this->clientService->newClient(); |
|
83 | 83 | |
84 | - try { |
|
85 | - $client->post($this->lookupServer, |
|
86 | - [ |
|
87 | - 'body' => json_encode($argument['dataArray']), |
|
88 | - 'timeout' => 10, |
|
89 | - 'connect_timeout' => 3, |
|
90 | - ] |
|
91 | - ); |
|
92 | - } catch (\Exception $e) { |
|
93 | - $this->jobList->add(RetryJob::class, |
|
94 | - [ |
|
95 | - 'dataArray' => $argument['dataArray'], |
|
96 | - 'retryNo' => $argument['retryNo'] + 1, |
|
97 | - 'lastRun' => time(), |
|
98 | - ] |
|
99 | - ); |
|
84 | + try { |
|
85 | + $client->post($this->lookupServer, |
|
86 | + [ |
|
87 | + 'body' => json_encode($argument['dataArray']), |
|
88 | + 'timeout' => 10, |
|
89 | + 'connect_timeout' => 3, |
|
90 | + ] |
|
91 | + ); |
|
92 | + } catch (\Exception $e) { |
|
93 | + $this->jobList->add(RetryJob::class, |
|
94 | + [ |
|
95 | + 'dataArray' => $argument['dataArray'], |
|
96 | + 'retryNo' => $argument['retryNo'] + 1, |
|
97 | + 'lastRun' => time(), |
|
98 | + ] |
|
99 | + ); |
|
100 | 100 | |
101 | - } |
|
102 | - } |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * test if it is time for the next run |
|
106 | - * |
|
107 | - * @param array $argument |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - protected function shouldRun($argument) { |
|
111 | - $retryNo = (int)$argument['retryNo']; |
|
112 | - $delay = $this->interval * 6 ** $retryNo; |
|
113 | - return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay); |
|
114 | - } |
|
104 | + /** |
|
105 | + * test if it is time for the next run |
|
106 | + * |
|
107 | + * @param array $argument |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + protected function shouldRun($argument) { |
|
111 | + $retryNo = (int)$argument['retryNo']; |
|
112 | + $delay = $this->interval * 6 ** $retryNo; |
|
113 | + return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * check if we should kill the background job |
|
118 | - * |
|
119 | - * The lookup server should no longer be contacted if: |
|
120 | - * |
|
121 | - * - max retries are reached (set to 5) |
|
122 | - * - lookup server was disabled by the admin |
|
123 | - * - no valid lookup server URL given |
|
124 | - * |
|
125 | - * @param int $retryCount |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - protected function killBackgroundJob($retryCount) { |
|
129 | - $maxTriesReached = $retryCount >= 5; |
|
130 | - $lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes'; |
|
116 | + /** |
|
117 | + * check if we should kill the background job |
|
118 | + * |
|
119 | + * The lookup server should no longer be contacted if: |
|
120 | + * |
|
121 | + * - max retries are reached (set to 5) |
|
122 | + * - lookup server was disabled by the admin |
|
123 | + * - no valid lookup server URL given |
|
124 | + * |
|
125 | + * @param int $retryCount |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + protected function killBackgroundJob($retryCount) { |
|
129 | + $maxTriesReached = $retryCount >= 5; |
|
130 | + $lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes'; |
|
131 | 131 | |
132 | - return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer); |
|
133 | - } |
|
132 | + return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer); |
|
133 | + } |
|
134 | 134 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | protected function run($argument) { |
78 | - if ($this->killBackgroundJob((int)$argument['retryNo'])) { |
|
78 | + if ($this->killBackgroundJob((int) $argument['retryNo'])) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | protected function shouldRun($argument) { |
111 | - $retryNo = (int)$argument['retryNo']; |
|
111 | + $retryNo = (int) $argument['retryNo']; |
|
112 | 112 | $delay = $this->interval * 6 ** $retryNo; |
113 | 113 | return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $delay); |
114 | 114 | } |
@@ -36,136 +36,136 @@ |
||
36 | 36 | * @package OCA\LookupServerConnector |
37 | 37 | */ |
38 | 38 | class UpdateLookupServer { |
39 | - /** @var AccountManager */ |
|
40 | - private $accountManager; |
|
41 | - /** @var IClientService */ |
|
42 | - private $clientService; |
|
43 | - /** @var Signer */ |
|
44 | - private $signer; |
|
45 | - /** @var IJobList */ |
|
46 | - private $jobList; |
|
47 | - /** @var string URL point to lookup server */ |
|
48 | - private $lookupServer; |
|
49 | - /** @var bool */ |
|
50 | - private $lookupServerEnabled; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param AccountManager $accountManager |
|
54 | - * @param IClientService $clientService |
|
55 | - * @param Signer $signer |
|
56 | - * @param IJobList $jobList |
|
57 | - * @param IConfig $config |
|
58 | - */ |
|
59 | - public function __construct(AccountManager $accountManager, |
|
60 | - IClientService $clientService, |
|
61 | - Signer $signer, |
|
62 | - IJobList $jobList, |
|
63 | - IConfig $config) { |
|
64 | - $this->accountManager = $accountManager; |
|
65 | - $this->clientService = $clientService; |
|
66 | - $this->signer = $signer; |
|
67 | - $this->jobList = $jobList; |
|
68 | - |
|
69 | - if($config->getSystemValue('has_internet_connection', true) === false) { |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - $this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes'; |
|
74 | - |
|
75 | - $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
76 | - if(!empty($this->lookupServer)) { |
|
77 | - $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
78 | - $this->lookupServer .= '/users'; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param IUser $user |
|
84 | - */ |
|
85 | - public function userUpdated(IUser $user) { |
|
86 | - |
|
87 | - if (!$this->shouldUpdateLookupServer()) { |
|
88 | - return; |
|
89 | - } |
|
90 | - |
|
91 | - $userData = $this->accountManager->getUser($user); |
|
92 | - $publicData = []; |
|
93 | - |
|
94 | - foreach ($userData as $key => $data) { |
|
95 | - if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { |
|
96 | - $publicData[$key] = $data; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - $this->sendToLookupServer($user, $publicData); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * send public user data to the lookup server |
|
105 | - * |
|
106 | - * @param IUser $user |
|
107 | - * @param array $publicData |
|
108 | - */ |
|
109 | - protected function sendToLookupServer(IUser $user, array $publicData) { |
|
110 | - |
|
111 | - $dataArray = ['federationId' => $user->getCloudId()]; |
|
112 | - |
|
113 | - if (!empty($publicData)) { |
|
114 | - $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; |
|
115 | - $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; |
|
116 | - $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; |
|
117 | - $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; |
|
118 | - $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; |
|
119 | - $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; |
|
120 | - $dataArray['twitter_signature'] = isset($publicData[AccountManager::PROPERTY_TWITTER]['signature']) ? $publicData[AccountManager::PROPERTY_TWITTER]['signature'] : ''; |
|
121 | - $dataArray['website_signature'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]['signature']) ? $publicData[AccountManager::PROPERTY_WEBSITE]['signature'] : ''; |
|
122 | - $dataArray['verificationStatus'] = |
|
123 | - [ |
|
124 | - AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', |
|
125 | - AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', |
|
126 | - ]; |
|
127 | - } |
|
128 | - |
|
129 | - $dataArray = $this->signer->sign('lookupserver', $dataArray, $user); |
|
130 | - $httpClient = $this->clientService->newClient(); |
|
131 | - try { |
|
132 | - if (empty($publicData)) { |
|
133 | - $httpClient->delete($this->lookupServer, |
|
134 | - [ |
|
135 | - 'body' => json_encode($dataArray), |
|
136 | - 'timeout' => 10, |
|
137 | - 'connect_timeout' => 3, |
|
138 | - ] |
|
139 | - ); |
|
140 | - } else { |
|
141 | - $httpClient->post($this->lookupServer, |
|
142 | - [ |
|
143 | - 'body' => json_encode($dataArray), |
|
144 | - 'timeout' => 10, |
|
145 | - 'connect_timeout' => 3, |
|
146 | - ] |
|
147 | - ); |
|
148 | - } |
|
149 | - } catch (\Exception $e) { |
|
150 | - $this->jobList->add(RetryJob::class, |
|
151 | - [ |
|
152 | - 'dataArray' => $dataArray, |
|
153 | - 'retryNo' => 0, |
|
154 | - ] |
|
155 | - ); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * check if we should update the lookup server, we only do it if |
|
161 | - * |
|
162 | - * * we have a valid URL |
|
163 | - * * the lookup server update was enabled by the admin |
|
164 | - * |
|
165 | - * @return bool |
|
166 | - */ |
|
167 | - private function shouldUpdateLookupServer() { |
|
168 | - return $this->lookupServerEnabled || !empty($this->lookupServer); |
|
169 | - } |
|
39 | + /** @var AccountManager */ |
|
40 | + private $accountManager; |
|
41 | + /** @var IClientService */ |
|
42 | + private $clientService; |
|
43 | + /** @var Signer */ |
|
44 | + private $signer; |
|
45 | + /** @var IJobList */ |
|
46 | + private $jobList; |
|
47 | + /** @var string URL point to lookup server */ |
|
48 | + private $lookupServer; |
|
49 | + /** @var bool */ |
|
50 | + private $lookupServerEnabled; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param AccountManager $accountManager |
|
54 | + * @param IClientService $clientService |
|
55 | + * @param Signer $signer |
|
56 | + * @param IJobList $jobList |
|
57 | + * @param IConfig $config |
|
58 | + */ |
|
59 | + public function __construct(AccountManager $accountManager, |
|
60 | + IClientService $clientService, |
|
61 | + Signer $signer, |
|
62 | + IJobList $jobList, |
|
63 | + IConfig $config) { |
|
64 | + $this->accountManager = $accountManager; |
|
65 | + $this->clientService = $clientService; |
|
66 | + $this->signer = $signer; |
|
67 | + $this->jobList = $jobList; |
|
68 | + |
|
69 | + if($config->getSystemValue('has_internet_connection', true) === false) { |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + $this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes'; |
|
74 | + |
|
75 | + $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
76 | + if(!empty($this->lookupServer)) { |
|
77 | + $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
78 | + $this->lookupServer .= '/users'; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param IUser $user |
|
84 | + */ |
|
85 | + public function userUpdated(IUser $user) { |
|
86 | + |
|
87 | + if (!$this->shouldUpdateLookupServer()) { |
|
88 | + return; |
|
89 | + } |
|
90 | + |
|
91 | + $userData = $this->accountManager->getUser($user); |
|
92 | + $publicData = []; |
|
93 | + |
|
94 | + foreach ($userData as $key => $data) { |
|
95 | + if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { |
|
96 | + $publicData[$key] = $data; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + $this->sendToLookupServer($user, $publicData); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * send public user data to the lookup server |
|
105 | + * |
|
106 | + * @param IUser $user |
|
107 | + * @param array $publicData |
|
108 | + */ |
|
109 | + protected function sendToLookupServer(IUser $user, array $publicData) { |
|
110 | + |
|
111 | + $dataArray = ['federationId' => $user->getCloudId()]; |
|
112 | + |
|
113 | + if (!empty($publicData)) { |
|
114 | + $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : ''; |
|
115 | + $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : ''; |
|
116 | + $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : ''; |
|
117 | + $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : ''; |
|
118 | + $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : ''; |
|
119 | + $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : ''; |
|
120 | + $dataArray['twitter_signature'] = isset($publicData[AccountManager::PROPERTY_TWITTER]['signature']) ? $publicData[AccountManager::PROPERTY_TWITTER]['signature'] : ''; |
|
121 | + $dataArray['website_signature'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]['signature']) ? $publicData[AccountManager::PROPERTY_WEBSITE]['signature'] : ''; |
|
122 | + $dataArray['verificationStatus'] = |
|
123 | + [ |
|
124 | + AccountManager::PROPERTY_WEBSITE => isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['verified'] : '', |
|
125 | + AccountManager::PROPERTY_TWITTER => isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['verified'] : '', |
|
126 | + ]; |
|
127 | + } |
|
128 | + |
|
129 | + $dataArray = $this->signer->sign('lookupserver', $dataArray, $user); |
|
130 | + $httpClient = $this->clientService->newClient(); |
|
131 | + try { |
|
132 | + if (empty($publicData)) { |
|
133 | + $httpClient->delete($this->lookupServer, |
|
134 | + [ |
|
135 | + 'body' => json_encode($dataArray), |
|
136 | + 'timeout' => 10, |
|
137 | + 'connect_timeout' => 3, |
|
138 | + ] |
|
139 | + ); |
|
140 | + } else { |
|
141 | + $httpClient->post($this->lookupServer, |
|
142 | + [ |
|
143 | + 'body' => json_encode($dataArray), |
|
144 | + 'timeout' => 10, |
|
145 | + 'connect_timeout' => 3, |
|
146 | + ] |
|
147 | + ); |
|
148 | + } |
|
149 | + } catch (\Exception $e) { |
|
150 | + $this->jobList->add(RetryJob::class, |
|
151 | + [ |
|
152 | + 'dataArray' => $dataArray, |
|
153 | + 'retryNo' => 0, |
|
154 | + ] |
|
155 | + ); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * check if we should update the lookup server, we only do it if |
|
161 | + * |
|
162 | + * * we have a valid URL |
|
163 | + * * the lookup server update was enabled by the admin |
|
164 | + * |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | + private function shouldUpdateLookupServer() { |
|
168 | + return $this->lookupServerEnabled || !empty($this->lookupServer); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
@@ -66,14 +66,14 @@ |
||
66 | 66 | $this->signer = $signer; |
67 | 67 | $this->jobList = $jobList; |
68 | 68 | |
69 | - if($config->getSystemValue('has_internet_connection', true) === false) { |
|
69 | + if ($config->getSystemValue('has_internet_connection', true) === false) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes'; |
74 | 74 | |
75 | 75 | $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
76 | - if(!empty($this->lookupServer)) { |
|
76 | + if (!empty($this->lookupServer)) { |
|
77 | 77 | $this->lookupServer = rtrim($this->lookupServer, '/'); |
78 | 78 | $this->lookupServer .= '/users'; |
79 | 79 | } |