FederatedSharesDiscoverJob.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(86400);
  25. }
  26. public function run($argument) {
  27. $qb = $this->connection->getQueryBuilder();
  28. $qb->selectDistinct('remote')
  29. ->from('share_external');
  30. $result = $qb->execute();
  31. while ($row = $result->fetch()) {
  32. $this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
  33. try {
  34. $this->ocmDiscoveryService->discover($row['remote'], true);
  35. } catch (OCMProviderException $e) {
  36. $this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]);
  37. }
  38. }
  39. $result->closeCursor();
  40. }
  41. }