0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-24 08:56:48 +00:00
nextcloud_server/apps/lookup_server_connector/lib/UpdateLookupServer.php
Andy Scherzinger cc1686dba9
chore: Add SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2024-05-31 10:38:47 +02:00

68 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\LookupServerConnector;
use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IUser;
/**
* Class UpdateLookupServer
*
* @package OCA\LookupServerConnector
*/
class UpdateLookupServer {
/** @var IConfig */
private $config;
/** @var IJobList */
private $jobList;
/**
* @param IJobList $jobList
* @param IConfig $config
*/
public function __construct(IJobList $jobList,
IConfig $config) {
$this->config = $config;
$this->jobList = $jobList;
}
/**
* @param IUser $user
*/
public function userUpdated(IUser $user): void {
if (!$this->shouldUpdateLookupServer()) {
return;
}
// Reset retry counter
$this->config->deleteUserValue(
$user->getUID(),
'lookup_server_connector',
'update_retries'
);
$this->jobList->add(RetryJob::class, ['userId' => $user->getUID()]);
}
/**
* check if we should update the lookup server, we only do it if
*
* + we have an internet connection
* + the lookup server update was not disabled by the admin
* + we have a valid lookup server URL
*
* @return bool
*/
private function shouldUpdateLookupServer(): bool {
return $this->config->getSystemValueBool('has_internet_connection', true) === true &&
$this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes' &&
$this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
}
}