diff --git a/src/Response.php b/src/Response.php index c8d2208..20ef8d4 100644 --- a/src/Response.php +++ b/src/Response.php @@ -112,10 +112,15 @@ private function getUpdateVersion() : array { } if ($this->channel === 'enterprise' && isset($enterprise)) { + if (version_compare($this->version, $enterprise['version']) === 1 + && version_compare($this->version, $stable['version']) === -1 + && $this->hasSameMajorVersion($this->version, $stable['version'])) { + return $stable; + } if (version_compare($this->version, $enterprise['version']) === -1 || $isMacOs) { return $enterprise; } - return []; // do not fall back to stable in case there is no enterprise update + return []; // Otherwise do not fall back to stable when there is no enterprise update } if (version_compare($this->version, $stable['version']) == -1 || $isMacOs) { @@ -125,6 +130,10 @@ private function getUpdateVersion() : array { return []; } + private function hasSameMajorVersion(string $currentVersion, string $updateVersion): bool { + return explode('.', $currentVersion, 2)[0] === explode('.', $updateVersion, 2)[0]; + } + private function getLegacyChannel(): ?string { // Outdated platforms (Qt5 era): // - macOS < 11 diff --git a/tests/unit/ResponseTest.php b/tests/unit/ResponseTest.php index e9e55fd..79788d1 100644 --- a/tests/unit/ResponseTest.php +++ b/tests/unit/ResponseTest.php @@ -140,6 +140,34 @@ public function updateDataProvider(): array $configThrottle = $config; $configThrottle['nextcloud']['stable']['release'] = (new \DateTime())->sub(new \DateInterval('PT6H'))->format('Y-m-d H:m'); + $configEnterprisePatchFallback = $config; + $configEnterprisePatchFallback['nextcloud']['enterprise']['win32'] = [ + 'version' => '4.0.10', + 'versionstring' => 'Nextcloud Client 4.0.10', + 'downloadurl' => 'https://download.nextcloud.com/desktop/stable/Nextcloud-4.0.10-setup.exe', + ]; + $configEnterprisePatchFallback['nextcloud']['stable']['win32'] = [ + 'version' => '33.0.5', + 'versionstring' => 'Nextcloud Client 33.0.5', + 'downloadurl' => 'https://download.nextcloud.com/desktop/stable/Nextcloud-33.0.5-setup.exe', + ]; + $configEnterprisePatchFallback['nextcloud']['enterprise']['macos'] = array_merge( + $configEnterprisePatchFallback['nextcloud']['enterprise']['macos'], + [ + 'version' => '4.0.10', + 'versionstring' => 'Nextcloud Client 4.0.10', + ] + ); + $configEnterprisePatchFallback['nextcloud']['stable']['macos'] = array_merge( + $configEnterprisePatchFallback['nextcloud']['stable']['macos'], + [ + 'version' => '33.0.5', + 'versionstring' => 'Nextcloud Client 33.0.5', + 'downloadurl' => 'https://download.nextcloud.com/desktop/stable/Nextcloud-33.0.5.pkg', + 'sparkleDownloadUrl' => 'https://download.nextcloud.com/desktop/stable/Nextcloud-33.0.5.pkg.tbz', + ] + ); + return [ // #0 Update segment is already allowed [ @@ -990,7 +1018,89 @@ public function updateDataProvider(): array ' - ], + ], + // #43 Manually upgraded enterprise client gets stable patches from its current major version + [ + 'nextcloud', + 'win32', + '33.0.2', + '', + '11', + '10.0.26080', + 'enterprise', + false, + false, + $configEnterprisePatchFallback, + ' +33.0.5Nextcloud Client 33.0.5https://download.nextcloud.com/desktop/stable/Nextcloud-33.0.5-setup.exe +' + ], + // #44 Enterprise fallback does not move a manually upgraded client to another major version + [ + 'nextcloud', + 'win32', + '32.0.2', + '', + '11', + '10.0.26080', + 'enterprise', + false, + false, + $configEnterprisePatchFallback, + ' + +' + ], + // #45 Manually upgraded macOS enterprise client gets stable patches via Sparkle + [ + 'nextcloud', + 'macos', + '33.0.2', + '', + '14.0', + '22.00.00', + 'enterprise', + true, + false, + $configEnterprisePatchFallback, + ' + + + Download Channel + Most recent changes with links to updates. + en + + Nextcloud Client 33.0.5 + Wed, 13 July 16 21:07:31 +0200 + + 11.0 + + 33.0.0 + 33.0.0.0 + 33.0.1 + 33.0.1.0 + + https://download.nextcloud.com/desktop/stable/Nextcloud-33.0.5.pkg + + +' + ], + // #46 Enterprise fallback does not offer an update when the stable patch is already installed + [ + 'nextcloud', + 'win32', + '33.0.5', + '', + '11', + '10.0.26080', + 'enterprise', + false, + false, + $configEnterprisePatchFallback, + ' + +' + ], ]; }