SyncFederationAddressBooks.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. private SyncService $syncService;
  15. public function __construct(SyncService $syncService) {
  16. parent::__construct();
  17. $this->syncService = $syncService;
  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) {
  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. }