Version1027Date20230504122946.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(private SyncService $syncService,
  19. private LoggerInterface $logger,
  20. private IUserManager $userManager,
  21. private IConfig $config) {
  22. }
  23. /**
  24. * @param IOutput $output
  25. * @param Closure(): ISchemaWrapper $schemaClosure
  26. * @param array $options
  27. */
  28. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  29. if($this->userManager->countSeenUsers() > 100 || array_sum($this->userManager->countUsers()) > 100) {
  30. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
  31. $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.');
  32. return;
  33. }
  34. try {
  35. $this->syncService->syncInstance();
  36. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
  37. } catch (Throwable $e) {
  38. $this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');
  39. $this->logger->error('Could not sync system address books during update', [
  40. 'exception' => $e,
  41. ]);
  42. $output->warning('System address book sync failed. See logs for details');
  43. }
  44. }
  45. }