Merge pull request #18818 from woocommerce/fix/prevent-unsupported-downgrade
Don't call WC_Install::install() on downgrades
This commit is contained in:
commit
8fb8039b23
|
@ -2,8 +2,6 @@
|
||||||
/**
|
/**
|
||||||
* Installation related functions and actions.
|
* Installation related functions and actions.
|
||||||
*
|
*
|
||||||
* @author WooThemes
|
|
||||||
* @category Admin
|
|
||||||
* @package WooCommerce/Classes
|
* @package WooCommerce/Classes
|
||||||
* @version 3.0.0
|
* @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.
|
* This check is done on all requests and runs if the versions do not match.
|
||||||
*/
|
*/
|
||||||
public static function check_version() {
|
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();
|
self::install();
|
||||||
do_action( 'woocommerce_updated' );
|
do_action( 'woocommerce_updated' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,22 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_check_version() {
|
public function test_check_version() {
|
||||||
update_option( 'woocommerce_version', ( (float) WC()->version - 1 ) );
|
update_option( 'woocommerce_version', ( (float) WC()->version - 1 ) );
|
||||||
update_option( 'woocommerce_db_version', WC()->version );
|
|
||||||
WC_Install::check_version();
|
WC_Install::check_version();
|
||||||
|
|
||||||
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
|
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
|
||||||
|
|
||||||
update_option( 'woocommerce_version', WC()->version );
|
update_option( 'woocommerce_version', WC()->version );
|
||||||
update_option( 'woocommerce_db_version', WC()->version );
|
|
||||||
WC_Install::check_version();
|
WC_Install::check_version();
|
||||||
|
|
||||||
$this->assertTrue( did_action( 'woocommerce_updated' ) === 1 );
|
$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 );
|
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' );
|
delete_transient( 'wc_installing' );
|
||||||
|
|
||||||
WC_Install::install();
|
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( 'WP_UNINSTALL_PLUGIN', true );
|
||||||
define( 'WC_REMOVE_ALL_DATA', 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();
|
WC_Install::create_roles();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue