aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/UserMigration/TMigratorBasicVersionHandling.php
blob: f679c8e87ae65ab2e92f82e8661afb35633f0d7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
	}
}