SyncFederationAddressBooks.php 2.1 KB

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