Merge pull request #25597 from woocommerce/try/obw-jn-as-race-cond

Try to fix the setup wizard trouble on JN
This commit is contained in:
Peter Fabian 2020-02-07 13:04:06 +01:00 committed by GitHub
commit 1441d8c07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions

View File

@ -39,3 +39,10 @@ find ./packages/woocommerce-admin -iname '*.js' -exec sed -i.bak -e "s/, 'woocom
# Cleanup backup files
find ./packages -name "*.bak" -type f -delete
output 2 "Done!"
# Apply patches
output 2 "Applying patch #450 to Action Schduler"
cd packages/action-scheduler
curl -O https://patch-diff.githubusercontent.com/raw/woocommerce/action-scheduler/pull/450.patch
patch -p1 < 450.patch
output 2 "Done!"

View File

@ -49,7 +49,12 @@ class WC_Admin_Notices {
add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
// to avoid.
if ( ! WC_Install::is_new_install() || ! wc_is_running_from_async_action_scheduler() ) {
add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
}
if ( current_user_can( 'manage_woocommerce' ) ) {
add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );

View File

@ -127,6 +127,12 @@ class WC_Admin {
* For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters.
*/
public function admin_redirects() {
// Don't run this fn from Action Scheduler requests, as it would clear _wc_activation_redirect transient.
// That means OBW would never be shown.
if ( wc_is_running_from_async_action_scheduler() ) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended
// Nonced plugin install redirects (whitelisted).
if ( ! empty( $_GET['wc-install-plugin-redirect'] ) ) {

View File

@ -319,7 +319,7 @@ class WC_Install {
* @since 3.2.0
* @return boolean
*/
private static function is_new_install() {
public static function is_new_install() {
$product_count = array_sum( (array) wp_count_posts( 'product' ) );
return is_null( get_option( 'woocommerce_version', null ) ) || ( 0 === $product_count && -1 === wc_get_page_id( 'shop' ) );

View File

@ -2273,3 +2273,13 @@ function wc_load_cart() {
WC()->initialize_session();
WC()->initialize_cart();
}
/**
* Test whether the context of execution comes from async action scheduler.
*
* @since 4.0.0
* @return bool
*/
function wc_is_running_from_async_action_scheduler() {
return isset( $_REQUEST['action'] ) && 'as_async_request_queue_runner' === $_REQUEST['action'];
}