From 44752c0dbfe11afb58de8956a79fbe5ec0f3e127 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Mon, 14 Apr 2014 19:09:06 +0200 Subject: [PATCH] [ticket/11366] Moving to \phpbb\version_helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + bug fix (missing exception) + Using \phpbb\version_helper So, now, the version file have a new format : { "stable": { "": { "current": "", [ "announcement": "", ] [ "download": "", ] }, "": { ... } }, "unstable": { } } PHPBB3-11366 --- phpBB/adm/style/acp_ext_details.html | 36 ++-- phpBB/adm/style/acp_ext_list.html | 11 +- phpBB/includes/acp/acp_extensions.php | 77 ++++--- phpBB/language/en/acp/extensions.php | 2 +- phpBB/phpbb/extension/version_helper.php | 257 ----------------------- 5 files changed, 72 insertions(+), 311 deletions(-) delete mode 100644 phpBB/phpbb/extension/version_helper.php diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 435c36ccc6..95b23395dd 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -62,22 +62,26 @@
{L_LATEST_VERSION} -
-
-
{LATEST_VERSION}
-
- -
-
-
{L_DOWNLOAD} {META_NAME} {LATEST_VERSION}
-
- - -
-
-
{L_RELEASE_ANNOUNCEMENT}
-
- + +
+
+
+
{updates_available.current}
+
+ +
+
+
{L_DOWNLOAD} {META_NAME} {LATEST_VERSION}
+
+ + +
+
+
{L_RELEASE_ANNOUNCEMENT}
+
+ +
+
diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index d612a959e8..2e949e5c3b 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -7,12 +7,11 @@

{L_EXTENSIONS_EXPLAIN}

- + - @@ -25,10 +24,9 @@ - @@ -44,15 +42,14 @@ - + -
{L_EXTENSION_NAME} {L_CURRENT_VERSION}{L_LATEST_VERSION} {L_EXTENSION_OPTIONS} {L_EXTENSION_ACTIONS}
{enabled.META_DISPLAY_NAME}{enabled.META_VERSION} - style="color: #228822;"style="color: #BC2A4D;">{enabled.LATEST_VERSION}{L_VERSIONCHECK_FORCE_UPDATE} ] + style="color: #228822;"style="color: #BC2A4D;">{enabled.META_VERSION}{L_VERSIONCHECK_FORCE_UPDATE} ] {L_DETAILS}
{L_EXTENSIONS_DISABLED}{L_EXTENSIONS_DISABLED}
{disabled.META_DISPLAY_NAME}{disabled.META_VERSION} - style="color: #228822;"style="color: #BC2A4D;">{disabled.LATEST_VERSION}{L_VERSIONCHECK_FORCE_UPDATE} ] + style="color: #228822;"style="color: #BC2A4D;">{disabled.META_VERSION}{L_VERSIONCHECK_FORCE_UPDATE} ] diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index ac26621b89..0aeb0968a4 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -251,9 +251,18 @@ class acp_extensions try { - $infos = array(); - $this->version_check($md_manager, $infos, $request->variable('versioncheck_force', false)); - $template->assign_vars($infos); + $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false)); + + $template->assign_vars(array( + 'S_UP_TO_DATE' => empty($updates_available), + 'S_VERSIONCHECK' => true, + 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')), + )); + + foreach ($updates_available as $branch => $version_data) + { + $template->assign_block_vars('updates_available', $version_data); + } } catch (\RuntimeException $e) { @@ -295,7 +304,15 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $this->version_check($md_manager, $enabled_extension_meta_data[$name]); + $updates = $this->version_check($md_manager); + + $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; + $enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); + } + catch (\RuntimeException $e) + { + $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false; } catch(\phpbb\extension\exception $e) { @@ -343,7 +360,15 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $this->version_check($md_manager, $disabled_extension_meta_data[$name]); + $updates = $this->version_check($md_manager); + + $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; + $disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); + } + catch (\RuntimeException $e) + { + $disabeld_extension_meta_data[$name]['S_VERSIONCHECK'] = false; } catch(\phpbb\extension\exception $e) { @@ -394,7 +419,15 @@ class acp_extensions 'META_VERSION' => $meta['version'], ); - $this->version_check($md_manager, $available_extension_meta_data[$name]); + $updates = $this->version_check($md_manager); + + $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); + $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true; + $available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); + } + catch (\RuntimeException $e) + { + $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; } catch(\phpbb\extension\exception $e) { @@ -439,13 +472,12 @@ class acp_extensions } /** - * Check the version and dump to the template + * Check the version and return the availables updates. * * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check. - * @param array $array_dest The array to bind to the template. * @param bool $force Ignores cached data. Default to false. */ - private function version_check(\phpbb\extension\metadata_manager $md_manager, &$array_dest, $force = false) + private function version_check(\phpbb\extension\metadata_manager $md_manager, $force = false) { $meta = $md_manager->get_metadata('all'); @@ -453,29 +485,14 @@ class acp_extensions { throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK')); } + + $meta_vc = $meta['extra']['version-check']; - $version_helper = new \phpbb\extension\version_helper($this->cache, $this->user); - $version_helper->set_metadata($meta); + $version_helper = new \phpbb\version_helper($this->cache, $this->config, $this->user); + $version_helper->set_current_version($meta['version']); + $version_helper->set_file_location($meta_vc['host'], $meta_vc['directory'], $meta_vc['filename']); - try - { - $version_helper->get_version($force); - $version_compare = $version_helper->is_uptodate(); - - $array_dest = array_merge($array_dest, array( - 'S_VERSIONCHECK' => true, - 'S_UP_TO_DATE' => $version_compare, - 'LATEST_VERSION' => $version_helper->get_latest_version(), - 'LATEST_DOWNLOAD' => $version_helper->get_latest_download_link(), - 'LATEST_ANNOUNCEMENT' => $version_helper->get_latest_announcement_link(), - 'UP_TO_DATE_MSG' => $this->user->lang($version_compare ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')), - 'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')), - )); - } - catch(\RuntimeException $e) - { - $array_dest['S_VERSIONCHECK'] = false; - } + return $updates = $version_helper->get_suggested_updates(true); } /** diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 85aef7c2d3..3a54dcf004 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -110,7 +110,7 @@ $lang = array_merge($lang, array( 'NOT_UP_TO_DATE' => '%s is not up to date', 'UP_TO_DATE' => '%s is up to date', 'ANNOUNCEMENT_TOPIC' => 'Release Announcement', - 'DOWNLOAD_LATEST' => 'Download Latest Version', + 'DOWNLOAD_LATEST' => 'Download Version', 'NO_VERSIONCHECK' => 'No informations about how get the latest version.', // 'NO_INFO' => 'Version server could not be contacted', )); diff --git a/phpBB/phpbb/extension/version_helper.php b/phpBB/phpbb/extension/version_helper.php deleted file mode 100644 index 5d7d4121f0..0000000000 --- a/phpBB/phpbb/extension/version_helper.php +++ /dev/null @@ -1,257 +0,0 @@ -cache = $cache; - $this->user = $user; - } - - /** - * Set the informations concerning the current version from the metadata - * - * @param array $metadata - * @throws \RuntimeException - */ - public function set_metadata($metadata) - { - if (! isset($metadata['extra']['version-check'])) - { - throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK')); - } - - $meta_vc = $metadata['extra']['version-check']; - - $this->set_file_location($meta_vc['host'], $meta_vc['directory'], $meta_vc['filename']); - $this->set_extension($metadata['name']); - $this->set_current_version($metadata['version']); - } - - /** - * Set the name of the extention - * - * @param string Name of the extension - * @return version_helper - */ - public function set_extension($extension) - { - $this->extension = $extension; - - return $this; - } - - /** - * Set location to the file - * - * @param string $host Host (e.g. version.phpbb.com) - * @param string $path Path to file (e.g. /phpbb) - * @param string $file File name (Default: composer.json) - * @return version_helper - */ - public function set_file_location($host, $path, $file = 'composer.json') - { - $this->host = $host; - $this->path = $path; - $this->file = $file; - - return $this; - } - - /** - * Set current version - * - * @param string $version The current version - * @return version_helper - */ - public function set_current_version($version) - { - $this->current_version = $version; - - return $this; - } - - /** - * Wrapper for version_compare() that allows using uppercase A and B - * for alpha and beta releases. - * - * See http://www.php.net/manual/en/function.version-compare.php - * - * @param string $version1 First version number - * @param string $version2 Second version number - * @param string $operator Comparison operator (optional) - * - * @return mixed Boolean (true, false) if comparison operator is specified. - * Integer (-1, 0, 1) otherwise. - */ - public function compare($version1, $version2, $operator = null) - { - return phpbb_version_compare($version1, $version2, $operator); - } - - /** - * Say if the extension is up to date or not - * - * The informations about the lastest version are retrieved if needed - * - * @return bool true if the version is up to date - * @throws \RuntimeException - */ - public function is_uptodate() - { - if (empty($this->latest_version_metadata)) - { - $this->get_version(); - } - - return $this->compare($this->current_version, $this->latest_version_metadata['version'], '>='); - } - - /** - * Return the latest version number - * - * @return The latest version number ready to be displayed. - */ - public function get_latest_version() { - if (empty($this->latest_version_metadata)) - { - $this->get_version(); - } - - return htmlspecialchars($this->latest_version_metadata['version']); - } - - /** - * Return the latest download link - * - * @return The latest download link if existed, an empty string otherwise. - */ - public function get_latest_download_link() { - if (empty($this->latest_version_metadata)) - { - $this->get_version(); - } - - return isset($this->latest_version_metadata['extra']['download']) ? $this->latest_version_metadata['extra']['download']: ''; - } - - /** - * Return the latest announcement link - * - * @return The latest announcement link if existed, an empty string otherwise. - */ - public function get_latest_announcement_link() { - if (empty($this->latest_version_metadata)) - { - $this->get_version(); - } - - return isset($this->latest_version_metadata['extra']['announcement']) ? $this->latest_version_metadata['extra']['announcement']: ''; - } - - /** - * Obtains the latest version information - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @return string Version info - * @throws \RuntimeException - */ - public function get_version($force_update = false) - { -echo 'Force : ' . $force_update; - $cache_file = 'versioncheck_ext_' . $this->extension . ':' . $this->host . $this->path . $this->file; - - $info = $this->cache->get($cache_file); - - if ($info === false || $force_update) - { - $errstr = $errno = ''; - $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); - - if (!empty($errstr)) - { - throw new \RuntimeException($errstr); - } - - $info = json_decode($info, true); - - if (empty($info['version'])) - { - $this->user->add_lang('acp/common'); - - throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); - } - - // Replace & with & on announcement and download links - if (isset($info['extra']['announcement'])) - { - $info['extra']['announcement'] = str_replace('&', '&', $info['extra']['announcement']); - } - - if (isset($info['extra']['download'])) - { - $info['extra']['download'] = str_replace('&', '&', $info['extra']['download']); - } - - $this->cache->put($cache_file, $info, 86400); // 24 hours - } - - $this->latest_version_metadata = $info; - - return $info; - } -}