Merge pull request #529 from nextcloud/vendor-maintenance-downgrade

Allow downgrades of maintenance accross vendors
This commit is contained in:
Lukas Reschke 2016-08-10 00:25:53 +02:00 committed by GitHub
commit 9fbdb0efe8
4 changed files with 43 additions and 3 deletions

View File

@ -183,6 +183,18 @@ class Updater extends BasicEmitter {
return implode('.', $OC_VersionCanBeUpgradedFrom); return implode('.', $OC_VersionCanBeUpgradedFrom);
} }
/**
* Return vendor from which this version was published
*
* @return string Get the vendor
*/
private function getVendor() {
// this should really be a JSON file
require \OC::$SERVERROOT . '/version.php';
/** @var string $vendor */
return (string) $vendor;
}
/** /**
* Whether an upgrade to a specified version is possible * Whether an upgrade to a specified version is possible
* @param string $oldVersion * @param string $oldVersion
@ -191,8 +203,22 @@ class Updater extends BasicEmitter {
* @return bool * @return bool
*/ */
public function isUpgradePossible($oldVersion, $newVersion, $allowedPreviousVersion) { public function isUpgradePossible($oldVersion, $newVersion, $allowedPreviousVersion) {
return (version_compare($allowedPreviousVersion, $oldVersion, '<=') $allowedUpgrade = (version_compare($allowedPreviousVersion, $oldVersion, '<=')
&& (version_compare($oldVersion, $newVersion, '<=') || $this->config->getSystemValue('debug', false))); && (version_compare($oldVersion, $newVersion, '<=') || $this->config->getSystemValue('debug', false)));
if ($allowedUpgrade) {
return $allowedUpgrade;
}
// Upgrade not allowed, someone switching vendor?
if ($this->getVendor() !== $this->config->getAppValue('core', 'vendor', '')) {
$oldVersion = explode('.', $oldVersion);
$newVersion = explode('.', $newVersion);
return $oldVersion[0] === $newVersion[0] && $oldVersion[1] === $newVersion[1];
}
return false;
} }
/** /**
@ -279,6 +305,7 @@ class Updater extends BasicEmitter {
// only set the final version if everything went well // only set the final version if everything went well
$this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion())); $this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion()));
$this->config->setAppValue('core', 'vendor', $this->getVendor());
} }
} }

View File

@ -989,7 +989,7 @@ class OC_App {
$currentVersion = OC_App::getAppVersion($app); $currentVersion = OC_App::getAppVersion($app);
if ($currentVersion && isset($versions[$app])) { if ($currentVersion && isset($versions[$app])) {
$installedVersion = $versions[$app]; $installedVersion = $versions[$app];
if (version_compare($currentVersion, $installedVersion, '>')) { if (!version_compare($currentVersion, $installedVersion, '=')) {
return true; return true;
} }
} }

View File

@ -137,6 +137,12 @@ class UpdaterTest extends \Test\TestCase {
['8.1.0.0', '8.2.0.0', '8.1', true, true], ['8.1.0.0', '8.2.0.0', '8.1', true, true],
['8.2.0.1', '8.2.0.1', '8.1', true, true], ['8.2.0.1', '8.2.0.1', '8.1', true, true],
['8.3.0.0', '8.2.0.0', '8.1', true, true], ['8.3.0.0', '8.2.0.0', '8.1', true, true],
// Downgrade of maintenance
['9.0.53.0', '9.0.4.0', '8.1', false, false, 'nextcloud'],
// with vendor switch
['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'],
]; ];
} }
@ -148,12 +154,17 @@ class UpdaterTest extends \Test\TestCase {
* @param string $allowedVersion * @param string $allowedVersion
* @param bool $result * @param bool $result
* @param bool $debug * @param bool $debug
* @param string $vendor
*/ */
public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersion, $result, $debug = false) { public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersion, $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)
->willReturn($debug); ->willReturn($debug);
$this->config->expects($this->any())
->method('getAppValue')
->with('core', 'vendor', '')
->willReturn($vendor);
$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion)); $this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersion));
} }

View File

@ -38,3 +38,5 @@ $OC_Channel = 'git';
// The build number // The build number
$OC_Build = ''; $OC_Build = '';
// Vendor of this package
$vendor = 'nextcloud';