1
0

TMigratorBasicVersionHandling.php 792 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\UserMigration;
  8. /**
  9. * Basic version handling: we can import older versions but not newer ones
  10. * @since 24.0.0
  11. */
  12. trait TMigratorBasicVersionHandling {
  13. protected int $version = 1;
  14. protected bool $mandatory = false;
  15. /**
  16. * {@inheritDoc}
  17. * @since 24.0.0
  18. */
  19. public function getVersion(): int {
  20. return $this->version;
  21. }
  22. /**
  23. * {@inheritDoc}
  24. * @since 24.0.0
  25. */
  26. public function canImport(
  27. IImportSource $importSource
  28. ): bool {
  29. $version = $importSource->getMigratorVersion($this->getId());
  30. if ($version === null) {
  31. return !$this->mandatory;
  32. }
  33. return ($this->version >= $version);
  34. }
  35. }