aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/UserMigration/TMigratorBasicVersionHandling.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/UserMigration/TMigratorBasicVersionHandling.php')
-rw-r--r--lib/public/UserMigration/TMigratorBasicVersionHandling.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/public/UserMigration/TMigratorBasicVersionHandling.php b/lib/public/UserMigration/TMigratorBasicVersionHandling.php
new file mode 100644
index 00000000000..b33425a023d
--- /dev/null
+++ b/lib/public/UserMigration/TMigratorBasicVersionHandling.php
@@ -0,0 +1,42 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCP\UserMigration;
+
+/**
+ * Basic version handling: we can import older versions but not newer ones
+ * @since 24.0.0
+ */
+trait TMigratorBasicVersionHandling {
+ protected int $version = 1;
+
+ protected bool $mandatory = false;
+
+ /**
+ * {@inheritDoc}
+ * @since 24.0.0
+ */
+ public function getVersion(): int {
+ return $this->version;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @since 24.0.0
+ */
+ public function canImport(
+ IImportSource $importSource,
+ ): bool {
+ $version = $importSource->getMigratorVersion($this->getId());
+ if ($version === null) {
+ return !$this->mandatory;
+ }
+ return ($this->version >= $version);
+ }
+}