1
0

SyncSystemAddressBook.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Command;
  8. use OCA\DAV\CardDAV\SyncService;
  9. use OCP\IConfig;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Helper\ProgressBar;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class SyncSystemAddressBook extends Command {
  15. public function __construct(
  16. private SyncService $syncService,
  17. private IConfig $config,
  18. ) {
  19. parent::__construct();
  20. }
  21. protected function configure(): void {
  22. $this
  23. ->setName('dav:sync-system-addressbook')
  24. ->setDescription('Synchronizes users to the system addressbook');
  25. }
  26. protected function execute(InputInterface $input, OutputInterface $output): int {
  27. $output->writeln('Syncing users ...');
  28. $progress = new ProgressBar($output);
  29. $progress->start();
  30. $this->syncService->syncInstance(function () use ($progress) {
  31. $progress->advance();
  32. });
  33. $progress->finish();
  34. $output->writeln('');
  35. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
  36. return self::SUCCESS;
  37. }
  38. }