From 36d5fff1c6cbacbda4b4c623d8b9d909f214167a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 12 May 2014 23:47:05 +0200 Subject: [PATCH 1/6] [ticket/12536] Get Versions Should Not Require Both Stable and Unstable https://tracker.phpbb.com/browse/PHPBB3-12536 PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index e2fdf6ce63..7d59b5cd3a 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -216,10 +216,19 @@ class version_helper if ($this->force_stability !== null) { - return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; + $stability = ($this->force_stability === 'unstable') ? 'unstable' : 'stable'; + } + else + { + $stability = $this->is_stable($this->current_version) ? 'stable' : 'unstable'; } - return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; + if (!isset($info[$stability])) + { + throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + } + + return $info[$stability]; } /** @@ -247,7 +256,7 @@ class version_helper $info = json_decode($info, true); - if (empty($info['stable']) || empty($info['unstable'])) + if (empty($info['stable']) && empty($info['unstable'])) { $this->user->add_lang('acp/common'); From 3dddf1f4bf84d7a97ee47623a868483079ed643e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 12:48:08 +0200 Subject: [PATCH 2/6] [ticket/12536] Return empty array if stability unavailable PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 7d59b5cd3a..4c779c1a5a 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -225,7 +225,7 @@ class version_helper if (!isset($info[$stability])) { - throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + return array(); } return $info[$stability]; From 8b6df0e2f8a0601b43a1c1186f09bf058dadb47b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 12:59:10 +0200 Subject: [PATCH 3/6] [ticket/12536] Update doc block PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 4c779c1a5a..8e1c593094 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -208,7 +208,6 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @return string Version info - * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false) { From e1d9f1c67c9be90ac2f7f6a86ed02f0c22622afa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 15 May 2014 01:14:44 +0200 Subject: [PATCH 4/6] [ticket/12536] Use stable values when unstable are unavailable PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 8e1c593094..4718088ab6 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -215,19 +215,10 @@ class version_helper if ($this->force_stability !== null) { - $stability = ($this->force_stability === 'unstable') ? 'unstable' : 'stable'; - } - else - { - $stability = $this->is_stable($this->current_version) ? 'stable' : 'unstable'; + return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; } - if (!isset($info[$stability])) - { - return array(); - } - - return $info[$stability]; + return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; } /** @@ -271,6 +262,9 @@ class version_helper } } + $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; + $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable']; + $this->cache->put($cache_file, $info, 86400); // 24 hours } From a1e21f0a5cfafb9f195002031618656d0e1abfc8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 15 May 2014 02:10:51 +0200 Subject: [PATCH 5/6] [ticket/12536] Add test cases with empty versions list PHPBB3-12536 --- tests/version/version_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 2e2398bd45..5caad46e10 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -181,6 +181,11 @@ class phpbb_version_helper_test extends phpbb_test_case ), ), ), + array( + '1.1.0', + array(), + array(), + ), ); } @@ -286,6 +291,11 @@ class phpbb_version_helper_test extends phpbb_test_case ), '1.1.0-a2', ), + array( + '1.1.0', + array(), + null, + ), ); } From 8a227b981adae1ec49ad0996f32fe3e5fff33e8a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 26 May 2014 23:46:59 +0200 Subject: [PATCH 6/6] [ticket/12536] Restore missing @throws PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 4718088ab6..76bd477e18 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -208,6 +208,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @return string Version info + * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false) {