SyncFederationAddressBooks.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Federation\Command;
  26. use OCA\Federation\SyncFederationAddressBooks as SyncService;
  27. use Symfony\Component\Console\Command\Command;
  28. use Symfony\Component\Console\Helper\ProgressBar;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. class SyncFederationAddressBooks extends Command {
  32. private SyncService $syncService;
  33. public function __construct(SyncService $syncService) {
  34. parent::__construct();
  35. $this->syncService = $syncService;
  36. }
  37. protected function configure() {
  38. $this
  39. ->setName('federation:sync-addressbooks')
  40. ->setDescription('Synchronizes addressbooks of all federated clouds');
  41. }
  42. protected function execute(InputInterface $input, OutputInterface $output): int {
  43. $progress = new ProgressBar($output);
  44. $progress->start();
  45. $this->syncService->syncThemAll(function ($url, $ex) use ($progress, $output) {
  46. if ($ex instanceof \Exception) {
  47. $output->writeln("Error while syncing $url : " . $ex->getMessage());
  48. } else {
  49. $progress->advance();
  50. }
  51. });
  52. $progress->finish();
  53. $output->writeln('');
  54. return 0;
  55. }
  56. }