This commit is contained in:
Joshua T Flowers 2020-05-09 01:26:46 +03:00 committed by GitHub
parent dd8a625e90
commit d08a788756
1 changed files with 10 additions and 25 deletions

View File

@ -71,41 +71,25 @@ class Install {
// Add wc-admin report tables to list of WooCommerce tables. // Add wc-admin report tables to list of WooCommerce tables.
add_filter( 'woocommerce_install_get_tables', array( __CLASS__, 'add_tables' ) ); add_filter( 'woocommerce_install_get_tables', array( __CLASS__, 'add_tables' ) );
// Migrate option names by filtering their default values.
// This attaches a targeted filter for each migrated option name that will retreive
// the old value and use it as the default for the new option. This default
// will be used in the first retreival of the new option.
foreach ( self::$migrated_options as $new_option => $old_option ) {
add_filter( "default_option_{$new_option}", array( __CLASS__, 'handle_option_migration' ), 10, 2 );
}
} }
/** /**
* Migrate option values to their new keys/names. * Migrate option values to their new keys/names.
*
* @param mixed $default Default value for the option.
* @param string $new_option Option name.
* @return mixed Migrated option value.
*/ */
public static function handle_option_migration( $default, $new_option ) { public static function migrate_options() {
if ( isset( self::$migrated_options[ $new_option ] ) ) { wc_maybe_define_constant( 'WC_ADMIN_MIGRATING_OPTIONS', true );
wc_maybe_define_constant( 'WC_ADMIN_MIGRATING_OPTIONS', true );
// Avoid infinite loops - this filter is applied in add_option(), update_option(), and get_option(). foreach ( self::$migrated_options as $new_option => $old_option ) {
remove_filter( "default_option_{$new_option}", array( __CLASS__, 'handle_option_migration' ), 10, 2 ); $old_option_value = get_option( $old_option, false );
// Migrate the old option value. // Continue if no option value was previously set.
$old_option_name = self::$migrated_options[ $new_option ]; if ( false === $old_option_value ) {
$old_option_value = get_option( $old_option_name, $default ); continue;
}
update_option( $new_option, $old_option_value ); update_option( $new_option, $old_option_value );
delete_option( $old_option_name ); delete_option( $old_option );
return $old_option_value;
} }
return $default;
} }
/** /**
@ -157,6 +141,7 @@ class Install {
set_transient( 'wc_admin_installing', 'yes', MINUTE_IN_SECONDS * 10 ); set_transient( 'wc_admin_installing', 'yes', MINUTE_IN_SECONDS * 10 );
wc_maybe_define_constant( 'WC_ADMIN_INSTALLING', true ); wc_maybe_define_constant( 'WC_ADMIN_INSTALLING', true );
self::migrate_options();
self::create_tables(); self::create_tables();
self::create_events(); self::create_events();
self::delete_obsolete_notes(); self::delete_obsolete_notes();