1
0

Version1027Date20230504122946.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Migration;
  8. use Closure;
  9. use OCA\DAV\CardDAV\SyncService;
  10. use OCP\DB\ISchemaWrapper;
  11. use OCP\IConfig;
  12. use OCP\IUserManager;
  13. use OCP\Migration\IOutput;
  14. use OCP\Migration\SimpleMigrationStep;
  15. use Psr\Log\LoggerInterface;
  16. use Throwable;
  17. class Version1027Date20230504122946 extends SimpleMigrationStep {
  18. public function __construct(
  19. private SyncService $syncService,
  20. private LoggerInterface $logger,
  21. private IUserManager $userManager,
  22. private IConfig $config,
  23. ) {
  24. }
  25. /**
  26. * @param IOutput $output
  27. * @param Closure(): ISchemaWrapper $schemaClosure
  28. * @param array $options
  29. */
  30. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  31. if ($this->userManager->countSeenUsers() > 100 || array_sum($this->userManager->countUsers()) > 100) {
  32. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
  33. $output->info('Could not sync system address books during update - too many user records have been found. Please call occ dav:sync-system-addressbook manually.');
  34. return;
  35. }
  36. try {
  37. $this->syncService->syncInstance();
  38. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
  39. } catch (Throwable $e) {
  40. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
  41. $this->logger->error('Could not sync system address books during update', [
  42. 'exception' => $e,
  43. ]);
  44. $output->warning('System address book sync failed. See logs for details');
  45. }
  46. }
  47. }