Skip to content

Commit

Permalink
**Bug Fix:** Corrected a bug in the pro upgrader that prevented beta …
Browse files Browse the repository at this point in the history
…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](wpsharks/comet-cache#909 (comment)).
  • Loading branch information
Jason Caldwell committed Aug 12, 2017
1 parent 3b5671b commit df7c82b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down
14 changes: 7 additions & 7 deletions src/includes/classes/VsUpgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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.
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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.
}
}
Expand All @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 32 additions & 2 deletions src/includes/traits/Plugin/UpdateUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]*/

0 comments on commit df7c82b

Please sign in to comment.