summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-02-15 09:56:45 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-02-17 11:31:03 +0100
commit67fb1b92d6ad278377931e62f5f4af809b8cbe28 (patch)
treed58473e21c5d8bcf0ea8f551776fd87cbd15f5ba /lib
parentb06a622a609ed9c980a14d16d8dd67c95df1a79e (diff)
downloadnextcloud-server-67fb1b92d6ad278377931e62f5f4af809b8cbe28.tar.gz
nextcloud-server-67fb1b92d6ad278377931e62f5f4af809b8cbe28.zip
Improve version handling for user_migration
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/public/UserMigration/IExportDestination.php7
-rw-r--r--lib/public/UserMigration/IImportSource.php7
-rw-r--r--lib/public/UserMigration/IMigrator.php10
-rw-r--r--lib/public/UserMigration/TMigratorBasicVersionHandling.php10
4 files changed, 31 insertions, 3 deletions
diff --git a/lib/public/UserMigration/IExportDestination.php b/lib/public/UserMigration/IExportDestination.php
index 5446e8d57f2..a721efcdf93 100644
--- a/lib/public/UserMigration/IExportDestination.php
+++ b/lib/public/UserMigration/IExportDestination.php
@@ -67,6 +67,13 @@ interface IExportDestination {
public function copyFolder(Folder $folder, string $destinationPath): bool;
/**
+ * @param array<string,int> $versions Migrators and their versions.
+ *
+ * @since 24.0.0
+ */
+ public function setMigratorVersions(array $versions): bool;
+
+ /**
* Called after export is complete
*
* @since 24.0.0
diff --git a/lib/public/UserMigration/IImportSource.php b/lib/public/UserMigration/IImportSource.php
index 36f8686cb81..53680010df5 100644
--- a/lib/public/UserMigration/IImportSource.php
+++ b/lib/public/UserMigration/IImportSource.php
@@ -64,6 +64,13 @@ interface IImportSource {
public function copyToFolder(Folder $destination, string $sourcePath): bool;
/**
+ * @return array<string,int> Migrators and their versions from the export archive.
+ *
+ * @since 24.0.0
+ */
+ public function getMigratorVersions(): array;
+
+ /**
* Called after import is complete
*
* @since 24.0.0
diff --git a/lib/public/UserMigration/IMigrator.php b/lib/public/UserMigration/IMigrator.php
index ab18d41a94f..5a09bf4246b 100644
--- a/lib/public/UserMigration/IMigrator.php
+++ b/lib/public/UserMigration/IMigrator.php
@@ -54,7 +54,8 @@ interface IMigrator {
public function import(
IUser $user,
IImportSource $importSource,
- OutputInterface $output
+ OutputInterface $output,
+ ?int $version
): void;
/**
@@ -67,7 +68,12 @@ interface IMigrator {
/**
* Checks whether it is able to import a version of the export format for this migrator
*
+ * @param ?int $version Version stored in the import source for this migrator. Null means this migrator was not listed.
+ *
* @since 24.0.0
*/
- public function canImport(int $version): bool;
+ public function canImport(
+ IImportSource $importSource,
+ ?int $version
+ ): bool;
}
diff --git a/lib/public/UserMigration/TMigratorBasicVersionHandling.php b/lib/public/UserMigration/TMigratorBasicVersionHandling.php
index cb51e34c4b9..6b695ec45d9 100644
--- a/lib/public/UserMigration/TMigratorBasicVersionHandling.php
+++ b/lib/public/UserMigration/TMigratorBasicVersionHandling.php
@@ -32,6 +32,8 @@ namespace OCP\UserMigration;
trait TMigratorBasicVersionHandling {
protected int $version = 1;
+ protected bool $mandatory = false;
+
/**
* {@inheritDoc}
*/
@@ -42,7 +44,13 @@ trait TMigratorBasicVersionHandling {
/**
* {@inheritDoc}
*/
- public function canImport(int $version): bool {
+ public function canImport(
+ IImportSource $importSource,
+ ?int $version
+ ): bool {
+ if ($version === null) {
+ return !$this->mandatory;
+ }
return ($this->version >= $version);
}
}