Update db version to match the WC version after running update callbacks.

This is the behaviour that normally happens when a user updates version by version, but if the user skips several versions, db version and WC version could diverge.
This commit is contained in:
Peter Fabian 2021-12-06 14:50:25 +01:00
parent 313d40d396
commit feaf225526
1 changed files with 15 additions and 0 deletions

View File

@ -180,6 +180,7 @@ class WC_Install {
add_action( 'admin_init', array( __CLASS__, 'wc_admin_db_update_notice' ) );
add_action( 'admin_init', array( __CLASS__, 'add_admin_note_after_page_created' ) );
add_action( 'woocommerce_run_update_callback', array( __CLASS__, 'run_update_callback' ) );
add_action( 'woocommerce_update_db_to_current_version', array( __CLASS__, 'update_db_version' ) );
add_action( 'admin_init', array( __CLASS__, 'install_actions' ) );
add_action( 'woocommerce_page_created', array( __CLASS__, 'page_created' ), 10, 2 );
add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) );
@ -487,6 +488,20 @@ class WC_Install {
}
}
}
// After the callbacks finish, update the db version to the current WC version.
$current_wc_version = WC()->version;
if ( version_compare( $current_db_version, $current_wc_version, '<' ) &&
! WC()->queue()->get_next( 'woocommerce_update_db_to_current_version' ) ) {
WC()->queue()->schedule_single(
time() + $loop,
'woocommerce_update_db_to_current_version',
array(
'version' => $current_wc_version,
),
'woocommerce-db-updates'
);
}
}
/**