diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-09-09 11:08:55 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-09-09 11:08:55 +0200 |
commit | c4c9c5ffad9a67c6f0b19a567ac99aa6e97840de (patch) | |
tree | 491bad7bcdb7a365bd20a17c20fa43745bdbecee /lib | |
parent | acee9d4750657cd8b48c92990b0200ae29f3fa8f (diff) | |
parent | 6ccbf4bce64bc7016d65f270c22f37fdbca8e21f (diff) | |
download | nextcloud-server-c4c9c5ffad9a67c6f0b19a567ac99aa6e97840de.tar.gz nextcloud-server-c4c9c5ffad9a67c6f0b19a567ac99aa6e97840de.zip |
Merge pull request #18684 from owncloud/explicit-upgrade-version
Explicit upgrade version + prevent downgrades
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/updater.php | 28 | ||||
-rw-r--r-- | lib/private/util.php | 6 |
2 files changed, 23 insertions, 11 deletions
diff --git a/lib/private/updater.php b/lib/private/updater.php index f73fa8ff655..71e9732c307 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -212,19 +212,26 @@ class Updater extends BasicEmitter { } /** + * Return version from which this version is allowed to upgrade from + * + * @return string allowed previous version + */ + private function getAllowedPreviousVersion() { + // this should really be a JSON file + require \OC::$SERVERROOT . '/version.php'; + return implode('.', $OC_VersionCanBeUpgradedFrom); + } + + /** * Whether an upgrade to a specified version is possible * @param string $oldVersion * @param string $newVersion + * @param string $allowedPreviousVersion * @return bool */ - public function isUpgradePossible($oldVersion, $newVersion) { - $oldVersion = explode('.', $oldVersion); - $newVersion = explode('.', $newVersion); - - if($newVersion[0] > ($oldVersion[0] + 1) || $oldVersion[0] > $newVersion[0]) { - return false; - } - return true; + public function isUpgradePossible($oldVersion, $newVersion, $allowedPreviousVersion) { + return (version_compare($allowedPreviousVersion, $oldVersion, '<=') + && version_compare($oldVersion, $newVersion, '<=')); } /** @@ -259,8 +266,9 @@ class Updater extends BasicEmitter { */ private function doUpgrade($currentVersion, $installedVersion) { // Stop update if the update is over several major versions - if (!self::isUpgradePossible($installedVersion, $currentVersion)) { - throw new \Exception('Updates between multiple major versions are unsupported.'); + $allowedPreviousVersion = $this->getAllowedPreviousVersion(); + if (!self::isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersion)) { + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); } // Update .htaccess files diff --git a/lib/private/util.php b/lib/private/util.php index f110d618f77..eb1de5be5a4 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -1456,8 +1456,12 @@ class OC_Util { if ($config->getSystemValue('installed', false)) { $installedVersion = $config->getSystemValue('version', '0.0.0'); $currentVersion = implode('.', OC_Util::getVersion()); - if (version_compare($currentVersion, $installedVersion, '>')) { + $versionDiff = version_compare($currentVersion, $installedVersion); + if ($versionDiff > 0) { return true; + } else if ($versionDiff < 0) { + // downgrade attempt, throw exception + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); } // also check for upgrades for apps (independently from the user) |