UpdateLookupServer.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
  5. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Bjoern Schiessle <bjoern@schiessle.org>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\LookupServerConnector;
  29. use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
  30. use OCP\BackgroundJob\IJobList;
  31. use OCP\IConfig;
  32. use OCP\IUser;
  33. /**
  34. * Class UpdateLookupServer
  35. *
  36. * @package OCA\LookupServerConnector
  37. */
  38. class UpdateLookupServer {
  39. /** @var IConfig */
  40. private $config;
  41. /** @var IJobList */
  42. private $jobList;
  43. /**
  44. * @param IJobList $jobList
  45. * @param IConfig $config
  46. */
  47. public function __construct(IJobList $jobList,
  48. IConfig $config) {
  49. $this->config = $config;
  50. $this->jobList = $jobList;
  51. }
  52. /**
  53. * @param IUser $user
  54. */
  55. public function userUpdated(IUser $user): void {
  56. if (!$this->shouldUpdateLookupServer()) {
  57. return;
  58. }
  59. // Reset retry counter
  60. $this->config->deleteUserValue(
  61. $user->getUID(),
  62. 'lookup_server_connector',
  63. 'update_retries'
  64. );
  65. $this->jobList->add(RetryJob::class, ['userId' => $user->getUID()]);
  66. }
  67. /**
  68. * check if we should update the lookup server, we only do it if
  69. *
  70. * + we have an internet connection
  71. * + the lookup server update was not disabled by the admin
  72. * + we have a valid lookup server URL
  73. *
  74. * @return bool
  75. */
  76. private function shouldUpdateLookupServer(): bool {
  77. return $this->config->getSystemValueBool('has_internet_connection', true) === true &&
  78. $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') === 'yes' &&
  79. $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
  80. }
  81. }