1
0

SyncSystemAddressBook.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 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\DAV\Command;
  25. use OCA\DAV\CardDAV\SyncService;
  26. use OCP\IConfig;
  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 SyncSystemAddressBook extends Command {
  32. public function __construct(
  33. private SyncService $syncService,
  34. private IConfig $config,
  35. ) {
  36. parent::__construct();
  37. }
  38. protected function configure(): void {
  39. $this
  40. ->setName('dav:sync-system-addressbook')
  41. ->setDescription('Synchronizes users to the system addressbook');
  42. }
  43. protected function execute(InputInterface $input, OutputInterface $output): int {
  44. $output->writeln('Syncing users ...');
  45. $progress = new ProgressBar($output);
  46. $progress->start();
  47. $this->syncService->syncInstance(function () use ($progress) {
  48. $progress->advance();
  49. });
  50. $progress->finish();
  51. $output->writeln('');
  52. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
  53. return self::SUCCESS;
  54. }
  55. }