Skip to content

Commit 98fe083

Browse files
committed
Improve version handling for user_migration
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent a2efe13 commit 98fe083

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

lib/public/UserMigration/IExportDestination.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public function addFileAsStream(string $path, $stream): bool;
6666
*/
6767
public function copyFolder(Folder $folder, string $destinationPath): bool;
6868

69+
/**
70+
* @param array<string,int> $versions Migrators and their versions.
71+
*
72+
* @since 24.0.0
73+
*/
74+
public function setMigratorVersions(array $versions): bool;
75+
6976
/**
7077
* Called after export is complete
7178
*

lib/public/UserMigration/IImportSource.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public function getFileAsStream(string $path);
6363
*/
6464
public function copyToFolder(Folder $destination, string $sourcePath): bool;
6565

66+
/**
67+
* @return array<string,int> Migrators and their versions from the export archive.
68+
*
69+
* @since 24.0.0
70+
*/
71+
public function getMigratorVersions(): array;
72+
6673
/**
6774
* Called after import is complete
6875
*

lib/public/UserMigration/IMigrator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function export(
5454
public function import(
5555
IUser $user,
5656
IImportSource $importSource,
57-
OutputInterface $output
57+
OutputInterface $output,
58+
?int $version
5859
): void;
5960

6061
/**
@@ -67,7 +68,12 @@ public function getVersion(): int;
6768
/**
6869
* Checks whether it is able to import a version of the export format for this migrator
6970
*
71+
* @param ?int $version Version stored in the import source for this migrator. Null means this migrator was not listed.
72+
*
7073
* @since 24.0.0
7174
*/
72-
public function canImport(int $version): bool;
75+
public function canImport(
76+
IImportSource $importSource,
77+
?int $version
78+
): bool;
7379
}

lib/public/UserMigration/TMigratorBasicVersionHandling.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
trait TMigratorBasicVersionHandling {
3333
protected int $version = 1;
3434

35+
protected bool $mandatory = false;
36+
3537
/**
3638
* {@inheritDoc}
3739
*/
@@ -42,7 +44,13 @@ public function getVersion(): int {
4244
/**
4345
* {@inheritDoc}
4446
*/
45-
public function canImport(int $version): bool {
47+
public function canImport(
48+
IImportSource $importSource,
49+
?int $version
50+
): bool {
51+
if ($version === null) {
52+
return !$this->mandatory;
53+
}
4654
return ($this->version >= $version);
4755
}
4856
}

0 commit comments

Comments
 (0)