You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateLookupServer.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\LookupServerConnector;
  8. use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
  9. use OCP\BackgroundJob\IJobList;
  10. use OCP\IConfig;
  11. use OCP\IUser;
  12. /**
  13. * Class UpdateLookupServer
  14. *
  15. * @package OCA\LookupServerConnector
  16. */
  17. class UpdateLookupServer {
  18. /** @var IConfig */
  19. private $config;
  20. /** @var IJobList */
  21. private $jobList;
  22. /**
  23. * @param IJobList $jobList
  24. * @param IConfig $config
  25. */
  26. public function __construct(IJobList $jobList,
  27. IConfig $config) {
  28. $this->config = $config;
  29. $this->jobList = $jobList;
  30. }
  31. /**
  32. * @param IUser $user
  33. */
  34. public function userUpdated(IUser $user): void {
  35. if (!$this->shouldUpdateLookupServer()) {
  36. return;
  37. }
  38. // Reset retry counter
  39. $this->config->deleteUserValue(
  40. $user->getUID(),
  41. 'lookup_server_connector',
  42. 'update_retries'
  43. );
  44. $this->jobList->add(RetryJob::class, ['userId' => $user->getUID()]);
  45. }
  46. /**
  47. * check if we should update the lookup server, we only do it if
  48. *
  49. * + we have an internet connection
  50. * + the lookup server update was not disabled by the admin
  51. * + we have a valid lookup server URL
  52. *
  53. * @return bool
  54. */
  55. private function shouldUpdateLookupServer(): bool {
  56. return $this->config->getSystemValueBool('has_internet_connection', true) === true &&
  57. $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes' &&
  58. $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
  59. }
  60. }