summaryrefslogtreecommitdiffstats
path: root/apps/lookup_server_connector
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2019-01-07 12:15:11 +0100
committerBjoern Schiessle <bjoern@schiessle.org>2019-01-07 12:15:11 +0100
commitd4134982f5dbe6b1edab47e72de4f383ad7b40b8 (patch)
tree1a8771fbc793428df8a1793cc6c85d7300c38823 /apps/lookup_server_connector
parent35a372dadd54db42d16bc65f071e4aed0c306b83 (diff)
downloadnextcloud-server-d4134982f5dbe6b1edab47e72de4f383ad7b40b8.tar.gz
nextcloud-server-d4134982f5dbe6b1edab47e72de4f383ad7b40b8.zip
improve lookup server behaviour
Don't try to connect to the lookup server if the lookup server was disabled by the admin or an empty lookup server URL was given Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/lookup_server_connector')
-rw-r--r--apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php21
-rw-r--r--apps/lookup_server_connector/lib/UpdateLookupServer.php20
2 files changed, 39 insertions, 2 deletions
diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
index 5a7212a6522..3b110ead1e3 100644
--- a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
+++ b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
@@ -75,7 +75,7 @@ class RetryJob extends Job {
}
protected function run($argument) {
- if ($argument['retryNo'] === 5 || empty($this->lookupServer)) {
+ if ($this->killBackgroundJob((int)$argument['retryNo'])) {
return;
}
@@ -110,4 +110,23 @@ class RetryJob extends Job {
protected function shouldRun($argument) {
return !isset($argument['lastRun']) || ((time() - $argument['lastRun']) > $this->interval);
}
+
+ /**
+ * check if we should kill the background job
+ *
+ * The lookup server should no longer be contacted if:
+ *
+ * - max retries are reached (set to 5)
+ * - lookup server was disabled by the admin
+ * - no valid lookup server URL given
+ *
+ * @param int $retryCount
+ * @return bool
+ */
+ protected function killBackgroundJob($retryCount) {
+ $maxTriesReached = $retryCount >= 5;
+ $lookupServerDisabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes';
+
+ return $maxTriesReached || $lookupServerDisabled || empty($this->lookupServer);
+ }
}
diff --git a/apps/lookup_server_connector/lib/UpdateLookupServer.php b/apps/lookup_server_connector/lib/UpdateLookupServer.php
index 7902ede8816..727dff70cbb 100644
--- a/apps/lookup_server_connector/lib/UpdateLookupServer.php
+++ b/apps/lookup_server_connector/lib/UpdateLookupServer.php
@@ -46,6 +46,8 @@ class UpdateLookupServer {
private $jobList;
/** @var string URL point to lookup server */
private $lookupServer;
+ /** @var bool */
+ private $lookupServerEnabled;
/**
* @param AccountManager $accountManager
@@ -68,6 +70,8 @@ class UpdateLookupServer {
return;
}
+ $this->lookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes';
+
$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
if(!empty($this->lookupServer)) {
$this->lookupServer = rtrim($this->lookupServer, '/');
@@ -79,7 +83,8 @@ class UpdateLookupServer {
* @param IUser $user
*/
public function userUpdated(IUser $user) {
- if(empty($this->lookupServer)) {
+
+ if (!$this->shouldUpdateLookupServer()) {
return;
}
@@ -150,4 +155,17 @@ class UpdateLookupServer {
);
}
}
+
+ /**
+ * check if we should update the lookup server, we only do it if
+ *
+ * * we have a valid URL
+ * * the lookup server update was enabled by the admin
+ *
+ * @return bool
+ */
+ private function shouldUpdateLookupServer() {
+ return $this->lookupServerEnabled || !empty($this->lookupServer);
+ }
+
}