diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c603ee3..a9839652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - **Bug Fix** (Pro): The HTML Compressor was returning an empty string upon encountering an invalid UTF-8 sequence. See [Issue #871](https://github.com/websharks/comet-cache/issues/871) reported by a Comet Cache user. - **Compatibility** (Pro): Many improvements to the Pro software update system, including changes to the API Endpoints and the Proxy Fallback endpoint. See [Issue #879](https://github.com/websharks/comet-cache/issues/879) and [Issue #315](https://github.com/websharks/comet-cache-pro/pull/315) for full details. - **Compatibility**: Fixed a WooCommerce compatibility issue that was generating a "Notice: id was called incorrectly. Product properties should not be accessed directly." Props @vestaxpdx. See [Issue #896](https://github.com/websharks/comet-cache/issues/896). +- **Bug Fix:** Corrected a bug in the pro upgrader that prevented beta releases from being installed whenever they were desired by a site owner. Even when a site owner explicitly enabled beta release updates, they were not coming through due to problematic calls to `version_compare()` against a version with a dev-state suffix. This same bug was causing some oddities in version-specific upgrade routines, and in upgrade routines in general whenever a beta release was installed on top of an existing formal release state; i.e., when existing, previous version did not have a dev-state suffix, which is typical. Fixed all in this release. See [Issue #909 comment](https://github.com/websharks/comet-cache/issues/909#issuecomment-321953490). = v170220 = diff --git a/src/includes/classes/VsUpgrades.php b/src/includes/classes/VsUpgrades.php index 9e3b7845..59ae8235 100644 --- a/src/includes/classes/VsUpgrades.php +++ b/src/includes/classes/VsUpgrades.php @@ -54,7 +54,7 @@ protected function runHandlers() */ protected function fromLte150807() { - if (version_compare($this->prev_version, '150807', '<=')) { + if ($this->versionCompare($this->prev_version, '150807', '<=', true)) { delete_site_option(GLOBAL_NS.'_errors'); // No longer necessary. if (is_multisite() && is_array($child_blogs = $this->plugin->getBlogs())) { @@ -92,7 +92,7 @@ protected function fromLte150807() */ protected function fromLte151107() { - if (version_compare($this->prev_version, '151107', '<=')) { + if ($this->versionCompare($this->prev_version, '151107', '<=', true)) { if (is_array($existing_options = get_site_option(GLOBAL_NS.'_options'))) { if (!empty($existing_options['cache_clear_xml_sitemap_patterns']) && mb_strpos($existing_options['cache_clear_xml_sitemap_patterns'], '**') === false) { $this->plugin->options['cache_clear_xml_sitemap_patterns'] = str_replace('*', '**', $existing_options['cache_clear_xml_sitemap_patterns']); @@ -131,7 +131,7 @@ protected function fromLte151107() */ protected function fromLte151114() { - if (version_compare($this->prev_version, '151114', '<=')) { + if ($this->versionCompare($this->prev_version, '151114', '<=', true)) { if (!$this->plugin->isApache()) { return; // Not running the Apache web server. } @@ -214,7 +214,7 @@ protected function fromZenCache() */ protected function fromLte160227() { - if (version_compare($this->prev_version, '160227', '<=')) { + if ($this->versionCompare($this->prev_version, '160227', '<=', true)) { if (is_array($existing_options = get_site_option(GLOBAL_NS.'_options'))) { $this->plugin->options['cache_clear_term_other_enable'] = $this->plugin->default_options['cache_clear_term_other_enable']; if ($this->plugin->options !== $existing_options) { @@ -235,7 +235,7 @@ protected function fromLte160227() */ protected function fromLte160521() { - if (version_compare($this->prev_version, '160521', '<=')) { + if ($this->versionCompare($this->prev_version, '160521', '<=', true)) { $this->plugin->dismissMainNotice('allow_url_fopen_disabled'); $this->plugin->removeAdvancedCache(); @@ -264,7 +264,7 @@ protected function fromLte160521() */ protected function fromLte160709() { - if (version_compare($this->prev_version, '160709', '<=')) { + if ($this->versionCompare($this->prev_version, '160709', '<=', true)) { $this->plugin->dismissMainNotice('new-pro-version-available'); // Dismiss any existing notices like this; upgrade notices are handled by WordPress now. } } @@ -275,7 +275,7 @@ protected function fromLte160709() */ protected function fromLte161108() { - if (version_compare($this->prev_version, '161108', '<=')) { + if ($this->versionCompare($this->prev_version, '161108', '<=', true)) { if (is_array($existing_options = get_site_option(GLOBAL_NS.'_options'))) { if (IS_PRO && isset($existing_options['htmlc_css_exclusions']) && empty($existing_options['htmlc_css_exclusions'])) { $this->plugin->options['htmlc_css_exclusions'] = $this->plugin->default_options['htmlc_css_exclusions']; diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index 832cebc2..296ebc05 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -53,7 +53,7 @@ public function checkVersion() { $prev_version = $this->options['version']; - if (version_compare($prev_version, VERSION, '>=')) { + if ($this->versionCompare($prev_version, VERSION, '>=', true)) { return; // Nothing to do; up-to-date. } $this->options = $this->getOptions(false, true); diff --git a/src/includes/traits/Plugin/UpdateUtils.php b/src/includes/traits/Plugin/UpdateUtils.php index 865b1c86..23362220 100644 --- a/src/includes/traits/Plugin/UpdateUtils.php +++ b/src/includes/traits/Plugin/UpdateUtils.php @@ -41,7 +41,7 @@ public function maybeCheckLatestProVersion() } if ($latest_pro_version && preg_match('/^[0-9]{6}/u', $latest_pro_version)) { $this->updateOptions(['latest_pro_version' => $latest_pro_version]); - if (version_compare($latest_pro_version, VERSION, '>')) { + if ($this->versionCompare($latest_pro_version, VERSION, '>', true)) { $this->maybeCheckLatestProPackage(); } } @@ -155,7 +155,7 @@ public function onGetSiteTransientUpdatePlugins($report) $latest_version = $this->options['latest_pro_version']; $latest_package = $this->options['latest_pro_package']; - if ($latest_version && $latest_package && version_compare($latest_version, VERSION, '>')) { + if ($latest_version && $latest_package && $this->versionCompare($latest_version, VERSION, '>', true)) { $report->response[$plugin_basename] = (object) [ 'id' => 0, 'url' => $plugin_url, @@ -191,5 +191,35 @@ public function maybeAutoUpdateInBackground($update, $item) return $update; // Unchanged in this case. } } + + /** + * Version compare. + * + * @since 17xxxx Version compare. + * + * @param string $one Version one. + * @param string $two Version two. + * @param string $operator Comparison operator. + * @param bool $maybe_strip_dev_state Maybe strip dev-state. + * + * @return bool True or false. + */ + public function versionCompare($one, $two, $operator, $maybe_strip_dev_state = false) + { + $one = (string) $one; + $two = (string) $two; + $operator = (string) $operator; + + // NOTE: Stripping dev-state suffix. + // The method must be called with `$maybe_strip_dev_state = true`, + // AND, the site owner must have explicitly enabled beta releases. + + if ($maybe_strip_dev_state && !$this->options['pro_update_check_stable']) { + $regex = '/\-(?:dev|rc|alpha|beta|pl).*$/ui'; + $one = preg_replace($regex, '', $one); + $two = preg_replace($regex, '', $two); + } + return (bool) version_compare($one, $two, $operator); + } } /*[/pro]*/