Prevent migration from ownCloud 11 to Nextcloud 12
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
33ca69166a
commit
18d7701d09
|
@ -157,9 +157,9 @@ class Updater extends BasicEmitter {
|
||||||
/**
|
/**
|
||||||
* Return version from which this version is allowed to upgrade from
|
* Return version from which this version is allowed to upgrade from
|
||||||
*
|
*
|
||||||
* @return string allowed previous version
|
* @return array allowed previous versions per vendor
|
||||||
*/
|
*/
|
||||||
private function getAllowedPreviousVersion() {
|
private function getAllowedPreviousVersions() {
|
||||||
// this should really be a JSON file
|
// this should really be a JSON file
|
||||||
require \OC::$SERVERROOT . '/version.php';
|
require \OC::$SERVERROOT . '/version.php';
|
||||||
/** @var array $OC_VersionCanBeUpgradedFrom */
|
/** @var array $OC_VersionCanBeUpgradedFrom */
|
||||||
|
@ -182,26 +182,22 @@ class Updater extends BasicEmitter {
|
||||||
* Whether an upgrade to a specified version is possible
|
* Whether an upgrade to a specified version is possible
|
||||||
* @param string $oldVersion
|
* @param string $oldVersion
|
||||||
* @param string $newVersion
|
* @param string $newVersion
|
||||||
* @param string $allowedPreviousVersion
|
* @param array $allowedPreviousVersions
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isUpgradePossible($oldVersion, $newVersion, $allowedPreviousVersion) {
|
public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
|
||||||
$allowedUpgrade = (version_compare($allowedPreviousVersion, $oldVersion, '<=')
|
$version = explode('.', $oldVersion);
|
||||||
&& (version_compare($oldVersion, $newVersion, '<=') || $this->config->getSystemValue('debug', false)));
|
$majorMinor = $version[0] . '.' . $version[1];
|
||||||
|
|
||||||
if ($allowedUpgrade) {
|
$currentVendor = $this->config->getAppValue('core', 'vendor', '');
|
||||||
return $allowedUpgrade;
|
if ($currentVendor === 'nextcloud') {
|
||||||
|
return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
|
||||||
|
&& (version_compare($oldVersion, $newVersion, '<=') ||
|
||||||
|
$this->config->getSystemValue('debug', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upgrade not allowed, someone switching vendor?
|
// Check if the instance can be migrated
|
||||||
if ($this->getVendor() !== $this->config->getAppValue('core', 'vendor', '')) {
|
return isset($allowedPreviousVersions[$currentVendor][$majorMinor]);
|
||||||
$oldVersion = explode('.', $oldVersion);
|
|
||||||
$newVersion = explode('.', $newVersion);
|
|
||||||
|
|
||||||
return $oldVersion[0] === $newVersion[0] && $oldVersion[1] === $newVersion[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,8 +211,8 @@ class Updater extends BasicEmitter {
|
||||||
*/
|
*/
|
||||||
private function doUpgrade($currentVersion, $installedVersion) {
|
private function doUpgrade($currentVersion, $installedVersion) {
|
||||||
// Stop update if the update is over several major versions
|
// Stop update if the update is over several major versions
|
||||||
$allowedPreviousVersion = $this->getAllowedPreviousVersion();
|
$allowedPreviousVersions = $this->getAllowedPreviousVersions();
|
||||||
if (!self::isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersion)) {
|
if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
|
||||||
throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
|
throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,93 +56,32 @@ class UpdaterTest extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $baseUrl
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildUpdateUrl($baseUrl) {
|
|
||||||
return $baseUrl . '?version='.implode('x', \OCP\Util::getVersion()).'xinstalledatxlastupdatedatx'.\OC_Util::getChannel().'xx';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function versionCompatibilityTestData() {
|
public function versionCompatibilityTestData() {
|
||||||
return [
|
return [
|
||||||
['1', '2', '1', true],
|
// Upgrade with invalid version
|
||||||
['2', '2', '2', true],
|
['9.1.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
|
||||||
['6.0.5.0', '6.0.6.0', '5.0', true],
|
['10.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], false],
|
||||||
['5.0.6.0', '7.0.4.0', '6.0', false],
|
// Upgrad with valid version
|
||||||
// allow upgrading within the same major release
|
['11.0.1.13', '11.0.2.25', ['nextcloud' => ['11.0' => true]], true],
|
||||||
['8.0.0.0', '8.0.0.0', '8.0', true],
|
// Downgrade with valid version
|
||||||
['8.0.0.0', '8.0.0.4', '8.0', true],
|
['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], false],
|
||||||
['8.0.0.0', '8.0.1.0', '8.0', true],
|
['11.0.2.25', '11.0.1.13', ['nextcloud' => ['11.0' => true]], true, true],
|
||||||
['8.0.0.0', '8.0.2.0', '8.0', true],
|
// Downgrade with invalid version
|
||||||
// does not allow downgrading within the same major release
|
['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false],
|
||||||
['8.0.1.0', '8.0.0.0', '8.0', false],
|
['11.0.2.25', '10.0.1.13', ['nextcloud' => ['10.0' => true]], false, true],
|
||||||
['8.0.2.0', '8.0.1.0', '8.0', false],
|
|
||||||
['8.0.0.4', '8.0.0.0', '8.0', false],
|
|
||||||
// allows upgrading within the patch version
|
|
||||||
['8.0.0.0', '8.0.0.1', '8.0', true],
|
|
||||||
['8.0.0.0', '8.0.0.2', '8.0', true],
|
|
||||||
// does not allow downgrading within the same major release
|
|
||||||
['8.0.0.1', '8.0.0.0', '8.0', false],
|
|
||||||
['8.0.0.2', '8.0.0.0', '8.0', false],
|
|
||||||
// allow upgrading to the next major release
|
|
||||||
['8.0.0.0', '8.1.0.0', '8.0', true],
|
|
||||||
['8.0.0.0', '8.1.1.0', '8.0', true],
|
|
||||||
['8.0.0.0', '8.1.1.5', '8.0', true],
|
|
||||||
['8.0.0.2', '8.1.1.5', '8.0', true],
|
|
||||||
['8.1.0.0', '8.2.0.0', '8.1', true],
|
|
||||||
['8.1.0.2', '8.2.0.4', '8.1', true],
|
|
||||||
['8.1.0.5', '8.2.0.1', '8.1', true],
|
|
||||||
['8.1.0.0', '8.2.1.0', '8.1', true],
|
|
||||||
['8.1.0.2', '8.2.1.5', '8.1', true],
|
|
||||||
['8.1.0.5', '8.2.1.1', '8.1', true],
|
|
||||||
// does not allow downgrading to the previous major release
|
|
||||||
['8.1.0.0', '8.0.0.0', '7.0', false],
|
|
||||||
['8.1.1.0', '8.0.0.0', '7.0', false],
|
|
||||||
// does not allow skipping major releases
|
|
||||||
['8.0.0.0', '8.2.0.0', '8.1', false],
|
|
||||||
['8.0.0.0', '8.2.1.0', '8.1', false],
|
|
||||||
['8.0.0.0', '9.0.1.0', '8.2', false],
|
|
||||||
['8.0.0.0', '10.0.0.0', '9.3', false],
|
|
||||||
// allows updating to the next major release
|
|
||||||
['8.2.0.0', '9.0.0.0', '8.2', true],
|
|
||||||
['8.2.0.0', '9.0.0.0', '8.2', true],
|
|
||||||
['8.2.0.0', '9.0.1.0', '8.2', true],
|
|
||||||
['8.2.0.0', '9.0.1.1', '8.2', true],
|
|
||||||
['8.2.0.2', '9.0.1.1', '8.2', true],
|
|
||||||
['8.2.2.0', '9.0.1.0', '8.2', true],
|
|
||||||
['8.2.2.2', '9.0.1.1', '8.2', true],
|
|
||||||
['9.0.0.0', '9.1.0.0', '9.0', true],
|
|
||||||
['9.0.0.0', '9.1.0.2', '9.0', true],
|
|
||||||
['9.0.0.2', '9.1.0.1', '9.0', true],
|
|
||||||
['9.1.0.0', '9.2.0.0', '9.1', true],
|
|
||||||
['9.2.0.0', '9.3.0.0', '9.2', true],
|
|
||||||
['9.3.0.0', '10.0.0.0', '9.3', true],
|
|
||||||
// does not allow updating to the next major release (first number)
|
|
||||||
['9.0.0.0', '8.2.0.0', '8.1', false],
|
|
||||||
// other cases
|
|
||||||
['8.0.0.0', '8.1.5.0', '8.0', true],
|
|
||||||
['8.2.0.0', '9.0.0.0', '8.2', true],
|
|
||||||
['8.2.0.0', '9.1.0.0', '9.0', false],
|
|
||||||
['9.0.0.0', '8.1.0.0', '8.0', false],
|
|
||||||
['9.0.0.0', '8.0.0.0', '7.0', false],
|
|
||||||
['9.1.0.0', '8.0.0.0', '7.0', false],
|
|
||||||
['8.2.0.0', '8.1.0.0', '8.0', false],
|
|
||||||
|
|
||||||
// With debug enabled
|
// Migration with unknown vendor
|
||||||
['8.0.0.0', '8.2.0.0', '8.1', false, true],
|
['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, false, 'owncloud'],
|
||||||
['8.1.0.0', '8.2.0.0', '8.1', true, true],
|
['9.1.1.13', '11.0.2.25', ['nextcloud' => ['9.1' => true]], false, true, 'owncloud'],
|
||||||
['8.2.0.1', '8.2.0.1', '8.1', true, true],
|
// Migration with unsupported vendor version
|
||||||
['8.3.0.0', '8.2.0.0', '8.1', true, true],
|
['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, false, 'owncloud'],
|
||||||
|
['9.1.1.13', '11.0.2.25', ['owncloud' => ['10.0' => true]], false, true, 'owncloud'],
|
||||||
// Downgrade of maintenance
|
// Migration with valid vendor version
|
||||||
['9.0.53.0', '9.0.4.0', '8.1', false, false, 'nextcloud'],
|
['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, false, 'owncloud'],
|
||||||
// with vendor switch
|
['9.1.1.13', '11.0.2.25', ['owncloud' => ['9.1' => true]], true, true, 'owncloud'],
|
||||||
['9.0.53.0', '9.0.4.0', '8.1', true, false, ''],
|
|
||||||
['9.0.53.0', '9.0.4.0', '8.1', true, false, 'owncloud'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +90,12 @@ class UpdaterTest extends TestCase {
|
||||||
*
|
*
|
||||||
* @param string $oldVersion
|
* @param string $oldVersion
|
||||||
* @param string $newVersion
|
* @param string $newVersion
|
||||||
* @param string $allowedVersion
|
* @param array $allowedVersions
|
||||||
* @param bool $result
|
* @param bool $result
|
||||||
* @param bool $debug
|
* @param bool $debug
|
||||||
* @param string $vendor
|
* @param string $vendor
|
||||||
*/
|
*/
|
||||||
public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersion, $result, $debug = false, $vendor = 'nextcloud') {
|
public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersions, $result, $debug = false, $vendor = 'nextcloud') {
|
||||||
$this->config->expects($this->any())
|
$this->config->expects($this->any())
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('debug', false)
|
->with('debug', false)
|
||||||
|
@ -166,7 +105,7 @@ class UpdaterTest extends TestCase {
|
||||||
->with('core', 'vendor', '')
|
->with('core', 'vendor', '')
|
||||||
->willReturn($vendor);
|
->willReturn($vendor);
|
||||||
|
|
||||||
$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion));
|
$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetSkip3rdPartyAppsDisable() {
|
public function testSetSkip3rdPartyAppsDisable() {
|
||||||
|
|
10
version.php
10
version.php
|
@ -31,7 +31,15 @@ $OC_Version = array(12, 0, 0, 12);
|
||||||
// The human readable string
|
// The human readable string
|
||||||
$OC_VersionString = '12.0 alpha';
|
$OC_VersionString = '12.0 alpha';
|
||||||
|
|
||||||
$OC_VersionCanBeUpgradedFrom = array(11);
|
$OC_VersionCanBeUpgradedFrom = [
|
||||||
|
'nextcloud' => [
|
||||||
|
'11.0' => true,
|
||||||
|
'12.0' => true,
|
||||||
|
],
|
||||||
|
'owncloud' => [
|
||||||
|
'10.0' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
// default Nextcloud channel
|
// default Nextcloud channel
|
||||||
$OC_Channel = 'git';
|
$OC_Channel = 'git';
|
||||||
|
|
Loading…
Reference in New Issue