Merge pull request #18818 from woocommerce/fix/prevent-unsupported-downgrade

Don't call WC_Install::install() on downgrades
This commit is contained in:
Mike Jolley 2018-02-06 12:46:42 +00:00 committed by GitHub
commit 8fb8039b23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -2,8 +2,6 @@
/**
* Installation related functions and actions.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Classes
* @version 3.0.0
*/
@ -141,7 +139,7 @@ class WC_Install {
* This check is done on all requests and runs if the versions do not match.
*/
public static function check_version() {
if ( ! defined( 'IFRAME_REQUEST' ) && get_option( 'woocommerce_version' ) !== WC()->version ) {
if ( ! defined( 'IFRAME_REQUEST' ) && version_compare( get_option( 'woocommerce_version' ), WC()->version, '<' ) ) {
self::install();
do_action( 'woocommerce_updated' );
}

View File

@ -11,16 +11,22 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
*/
public function test_check_version() {
update_option( 'woocommerce_version', ( (float) WC()->version - 1 ) );
update_option( 'woocommerce_db_version', WC()->version );
WC_Install::check_version();
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
update_option( 'woocommerce_version', WC()->version );
update_option( 'woocommerce_db_version', WC()->version );
WC_Install::check_version();
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
update_option( 'woocommerce_version', (float) WC()->version + 1 );
WC_Install::check_version();
$this->assertTrue(
did_action( 'woocommerce_updated' ) === 1,
'WC_Install::check_version() should not call install routine when the WC version stored in the database is bigger than the version in the code as downgrades are not supported.'
);
}
/**
@ -33,12 +39,12 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
define( 'WC_REMOVE_ALL_DATA', true );
}
include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' );
include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php';
delete_transient( 'wc_installing' );
WC_Install::install();
$this->assertEquals( WC()->version, get_option( 'woocommerce_version' ), print_r( array( 'Stored version' => get_option( 'woocommerce_version' ), 'WC Version' => WC()->version ), true ) );
$this->assertEquals( WC()->version, get_option( 'woocommerce_version' ) );
}
/**
@ -87,7 +93,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
define( 'WP_UNINSTALL_PLUGIN', true );
define( 'WC_REMOVE_ALL_DATA', true );
}
include( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php' );
include dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/uninstall.php';
WC_Install::create_roles();