UpdateLookupServer.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /**
  19. * @param IJobList $jobList
  20. * @param IConfig $config
  21. */
  22. public function __construct(
  23. private IJobList $jobList,
  24. private IConfig $config,
  25. ) {
  26. }
  27. /**
  28. * @param IUser $user
  29. */
  30. public function userUpdated(IUser $user): void {
  31. if (!$this->shouldUpdateLookupServer()) {
  32. return;
  33. }
  34. // Reset retry counter
  35. $this->config->deleteUserValue(
  36. $user->getUID(),
  37. 'lookup_server_connector',
  38. 'update_retries'
  39. );
  40. $this->jobList->add(RetryJob::class, ['userId' => $user->getUID()]);
  41. }
  42. /**
  43. * check if we should update the lookup server, we only do it if
  44. *
  45. * + we have an internet connection
  46. * + the lookup server update was not disabled by the admin
  47. * + we have a valid lookup server URL
  48. *
  49. * @return bool
  50. */
  51. private function shouldUpdateLookupServer(): bool {
  52. return $this->config->getSystemValueBool('has_internet_connection', true) === true &&
  53. $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes' &&
  54. $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
  55. }
  56. }