syncfederationaddressbooks.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace OCA\Federation\Command;
  3. use OCA\Federation\DbHandler;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Helper\ProgressBar;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. class SyncFederationAddressBooks extends Command {
  9. /** @var \OCA\Federation\SyncFederationAddressBooks */
  10. private $syncService;
  11. /**
  12. * @param \OCA\Federation\SyncFederationAddressBooks $syncService
  13. */
  14. function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
  15. parent::__construct();
  16. $this->syncService = $syncService;
  17. }
  18. protected function configure() {
  19. $this
  20. ->setName('federation:sync-addressbooks')
  21. ->setDescription('Synchronizes addressbooks of all federated clouds');
  22. }
  23. /**
  24. * @param InputInterface $input
  25. * @param OutputInterface $output
  26. * @return int
  27. */
  28. protected function execute(InputInterface $input, OutputInterface $output) {
  29. $progress = new ProgressBar($output);
  30. $progress->start();
  31. $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
  32. if ($ex instanceof \Exception) {
  33. $output->writeln("Error while syncing $url : " . $ex->getMessage());
  34. } else {
  35. $progress->advance();
  36. }
  37. });
  38. $progress->finish();
  39. $output->writeln('');
  40. return 0;
  41. }
  42. }