2022-02-14 15:48:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2022-02-14 15:48:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCP\UserMigration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic version handling: we can import older versions but not newer ones
|
2022-03-14 08:09:28 +00:00
|
|
|
* @since 24.0.0
|
2022-02-14 15:48:08 +00:00
|
|
|
*/
|
|
|
|
trait TMigratorBasicVersionHandling {
|
|
|
|
protected int $version = 1;
|
|
|
|
|
2022-02-15 08:56:45 +00:00
|
|
|
protected bool $mandatory = false;
|
|
|
|
|
2022-02-14 15:48:08 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2022-02-21 17:20:27 +00:00
|
|
|
* @since 24.0.0
|
2022-02-14 15:48:08 +00:00
|
|
|
*/
|
|
|
|
public function getVersion(): int {
|
|
|
|
return $this->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2022-02-21 17:20:27 +00:00
|
|
|
* @since 24.0.0
|
2022-02-14 15:48:08 +00:00
|
|
|
*/
|
2022-02-15 08:56:45 +00:00
|
|
|
public function canImport(
|
2022-02-17 17:09:14 +00:00
|
|
|
IImportSource $importSource,
|
2022-02-15 08:56:45 +00:00
|
|
|
): bool {
|
2022-04-11 08:53:51 +00:00
|
|
|
$version = $importSource->getMigratorVersion($this->getId());
|
2022-02-15 08:56:45 +00:00
|
|
|
if ($version === null) {
|
|
|
|
return !$this->mandatory;
|
|
|
|
}
|
2022-02-14 15:48:08 +00:00
|
|
|
return ($this->version >= $version);
|
|
|
|
}
|
|
|
|
}
|