FederatedSharesDiscoverJob.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Sharing\BackgroundJob;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\TimedJob;
  10. use OCP\IDBConnection;
  11. use OCP\OCM\Exceptions\OCMProviderException;
  12. use OCP\OCM\IOCMDiscoveryService;
  13. use OCP\OCS\IDiscoveryService;
  14. use Psr\Log\LoggerInterface;
  15. class FederatedSharesDiscoverJob extends TimedJob {
  16. public function __construct(
  17. ITimeFactory $time,
  18. private IDBConnection $connection,
  19. private IDiscoveryService $discoveryService,
  20. private IOCMDiscoveryService $ocmDiscoveryService,
  21. private LoggerInterface $logger,
  22. ) {
  23. parent::__construct($time);
  24. $this->setInterval(24 * 60 * 60);
  25. $this->setTimeSensitivity(self::TIME_INSENSITIVE);
  26. }
  27. public function run($argument) {
  28. $qb = $this->connection->getQueryBuilder();
  29. $qb->selectDistinct('remote')
  30. ->from('share_external');
  31. $result = $qb->executeQuery();
  32. while ($row = $result->fetch()) {
  33. $this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
  34. try {
  35. $this->ocmDiscoveryService->discover($row['remote'], true);
  36. } catch (OCMProviderException $e) {
  37. $this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]);
  38. }
  39. }
  40. $result->closeCursor();
  41. }
  42. }