diff options
author | Matthieu Gallien <matthieu.gallien@nextcloud.com> | 2022-05-24 12:01:34 +0300 |
---|---|---|
committer | Matthieu Gallien <matthieu.gallien@nextcloud.com> | 2022-05-24 12:32:35 +0300 |
commit | 2a799bdb1b0a96cd20008ad7b348d18d178ac476 (patch) | |
tree | c0c18a7b8c0d32daa0f0c139d03db1eada9f94b4 | |
parent | e27af2fca469611205041c9d129a0114b59fc8b3 (diff) |
let's ignore updateSegment and immediately provide latest releasenoLongerDelayUpdate
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | src/Response.php | 28 | ||||
-rw-r--r-- | tests/unit/ResponseTest.php | 38 |
3 files changed, 7 insertions, 61 deletions
@@ -86,7 +86,6 @@ $buildArch = isset($_GET['buildArch']) ? (string)$_GET['buildArch'] : "x86_64"; $currentArch = isset($_GET['currentArch']) ? (string)$_GET['currentArch'] : "x86_64"; $version = isset($_GET['version']) ? (string)$_GET['version'] : null; $isSparkle = isset($_GET['sparkle']) ? true : false; -$updateSegment = isset($_GET['updatesegment']) ? (int)$_GET['updatesegment'] : -1; $channel = isset($_GET['channel']) ? (string)$_GET['channel'] : 'stable'; if($oem === null || $platform === null || $version === null) { @@ -102,7 +101,6 @@ $response = new \ClientUpdateServer\Response( $version, $channel, $isSparkle, - $updateSegment, $config ); echo $response->buildResponse(); diff --git a/src/Response.php b/src/Response.php index 32aa640..fe9fe42 100644 --- a/src/Response.php +++ b/src/Response.php @@ -33,8 +33,6 @@ class Response { private $channel; /** @var bool */ private $isSparkle; - /** @var int */ - private $updateSegment; /** @var array */ private $config; @@ -43,14 +41,12 @@ class Response { string $version, string $channel, bool $isSparkle, - int $updateSegment, array $config) { $this->oem = $oem; $this->platform = $platform; $this->version = $version; $this->channel = $channel; $this->isSparkle = $isSparkle; - $this->updateSegment = $updateSegment; $this->config = $config; } @@ -87,27 +83,15 @@ class Response { } $releaseDate = new \DateTime($this->config[$this->oem][$this->channel]['release']); - $throttleDate = new \DateTime(); + $stable = $this->config[$this->oem]['stable'][$this->platform]; + $beta = $this->config[$this->oem]['beta'][$this->platform]; - if ($this->updateSegment === -1) { - $this->updateSegment = random_int(0, 99); + if ($this->channel == 'beta' && version_compare($stable['version'], $beta['version']) == -1) { + return $beta; } - // updateSegment is 0-99, so even fine grained control would possible - $chunks = floor($this->updateSegment / 10); - $throttleDate->sub(new \DateInterval('PT' . (12 * $chunks) . 'H')); - - if ($throttleDate >= $releaseDate) { - $stable = $this->config[$this->oem]['stable'][$this->platform]; - $beta = $this->config[$this->oem]['beta'][$this->platform]; - - if ($this->channel == 'beta' && version_compare($stable['version'], $beta['version']) == -1) { - return $beta; - } - - if (version_compare($this->version, $stable['version']) == -1) { - return $stable; - } + if (version_compare($this->version, $stable['version']) == -1) { + return $stable; } return []; diff --git a/tests/unit/ResponseTest.php b/tests/unit/ResponseTest.php index 9fd1322..e59f00d 100644 --- a/tests/unit/ResponseTest.php +++ b/tests/unit/ResponseTest.php @@ -88,25 +88,11 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - 5, $configThrottle, '<?xml version="1.0"?> <owncloudclient><version>2.2.2.6192</version><versionstring>Nextcloud Client 2.2.2 (build 6192)</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/ownCloud-2.2.2.6192-setup.exe</downloadurl></owncloudclient> ' ], - // #1 Update segment is not yet allowed - [ - 'nextcloud', - 'win32', - '1.9.0', - 'stable', - false, - 95, - $configThrottle, - '<?xml version="1.0"?> -<owncloudclient/> -' - ], // #2 Updates for client available [ 'nextcloud', @@ -114,7 +100,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.2.6192</version><versionstring>Nextcloud Client 2.2.2 (build 6192)</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/ownCloud-2.2.2.6192-setup.exe</downloadurl></owncloudclient> @@ -127,7 +112,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', true, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.2.6192</version><versionstring>Nextcloud Client 2.2.2 (build 6192)</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/ownCloud-2.2.2.6192-setup.exe</downloadurl></owncloudclient> @@ -140,7 +124,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.2</version><versionstring>Nextcloud Client 2.2.2</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/Nextcloud-2.2.2-x64.AppImage</downloadurl><web>https://nextcloud.com/install/#install-clients</web></owncloudclient> @@ -153,7 +136,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.2.3472</version><versionstring>Nextcloud Client 2.2.2 (build 3472)</versionstring><downloadurl>https://download.owncloud.com/desktop/stable/ownCloud-2.2.2.3472.pkg</downloadurl><sparkleDownloadUrl>https://download.owncloud.com/desktop/stable/ownCloud-2.2.2.3472.pkg.tbz</sparkleDownloadUrl><signature>MC0CFQDmXR6biDmNVW7TvMh0bfPPTzCvtwIUCzASgpzYdi4lltOnwbFCeQwgDjY=</signature><length>62738920</length></owncloudclient> @@ -166,7 +148,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', true, - -1, $config, '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> @@ -188,7 +169,6 @@ class ResponseTest extends TestCase { '1.9.0', 'beta', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.3-rc3</version><versionstring>Nextcloud Client 2.2.3-rc3</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/Nextcloud-2.2.3-rc3-x86.msi</downloadurl><web>https://nextcloud.com/install/#install-clients</web></owncloudclient> @@ -201,7 +181,6 @@ class ResponseTest extends TestCase { '2.2.3-rc1', 'beta', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.3-rc3</version><versionstring>Nextcloud Client 2.2.3-rc3</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/Nextcloud-2.2.3-rc3-x86.msi</downloadurl><web>https://nextcloud.com/install/#install-clients</web></owncloudclient> @@ -214,7 +193,6 @@ class ResponseTest extends TestCase { '2.2.2-rc1', 'beta', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient><version>2.2.2</version><versionstring>Nextcloud Client 2.2.2</versionstring><downloadurl>https://download.nextcloud.com/desktop/stable/Nextcloud-2.2.2-x64.AppImage</downloadurl><web>https://nextcloud.com/install/#install-clients</web></owncloudclient> @@ -227,7 +205,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -240,7 +217,6 @@ class ResponseTest extends TestCase { '1.9.0', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -253,7 +229,6 @@ class ResponseTest extends TestCase { '2.2.2.6192', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -266,7 +241,6 @@ class ResponseTest extends TestCase { '2.2.6192', 'stable', true, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -279,7 +253,6 @@ class ResponseTest extends TestCase { '2.2.2', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -292,7 +265,6 @@ class ResponseTest extends TestCase { '2.2.2.3472', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -305,7 +277,6 @@ class ResponseTest extends TestCase { '2.2.2.3472', 'stable', true, - -1, $config, '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> @@ -322,7 +293,6 @@ class ResponseTest extends TestCase { '2.3', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -335,7 +305,6 @@ class ResponseTest extends TestCase { '2.3', 'stable', true, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -348,7 +317,6 @@ class ResponseTest extends TestCase { '2.3', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -361,7 +329,6 @@ class ResponseTest extends TestCase { '2.3', 'stable', false, - -1, $config, '<?xml version="1.0"?> <owncloudclient/> @@ -374,7 +341,6 @@ class ResponseTest extends TestCase { '2.3', 'stable', true, - -1, $config, '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> @@ -395,7 +361,6 @@ class ResponseTest extends TestCase { * @param string $version * @param string $channel * @param bool $isSparkle - * @param int $updateSegment * @param array $config * @param string $expected */ @@ -404,11 +369,10 @@ class ResponseTest extends TestCase { string $version, string $channel, bool $isSparkle, - int $updateSegment, array $config, string $expected) { $response = $this->getMockBuilder('\ClientUpdateServer\Response') - ->setConstructorArgs([$oem, $platform, $version, $channel, $isSparkle, $updateSegment, $config]) + ->setConstructorArgs([$oem, $platform, $version, $channel, $isSparkle, $config]) ->setMethods(['getCurrentTimeStamp']) ->getMock(); $response |