SyncFederationAddressBooks.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Federation\Command;
  8. use OCA\Federation\SyncFederationAddressBooks as SyncService;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Helper\ProgressBar;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class SyncFederationAddressBooks extends Command {
  14. public function __construct(
  15. private SyncService $syncService,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure() {
  20. $this
  21. ->setName('federation:sync-addressbooks')
  22. ->setDescription('Synchronizes addressbooks of all federated clouds');
  23. }
  24. protected function execute(InputInterface $input, OutputInterface $output): int {
  25. $progress = new ProgressBar($output);
  26. $progress->start();
  27. $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output): void {
  28. if ($ex instanceof \Exception) {
  29. $output->writeln("Error while syncing $url : " . $ex->getMessage());
  30. } else {
  31. $progress->advance();
  32. }
  33. });
  34. $progress->finish();
  35. $output->writeln('');
  36. return 0;
  37. }
  38. }