• Hi, in the admin message requesting a DB update after a plugin upgrade, I read that the update can be triggered via WP CLI with wp wc update. But is there a way to trigger the update process via WP Cron? Or otherwise automated, hooking into another process?

    In our case: we would like to bulk-trigger the db update process after a plugin upgrade on a WordPress Multisite. Maybe setting sub-site cron jobs or hooking into the Network Upgrader on /wp-admin/network/upgrade.php ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @ravanh

    Thanks for reaching out!

    I understand that you would like to trigger the database update process via WP Cron or another automated method after a plugin upgrade on a WordPress Multisite.

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

    Thread Starter Rolf Allard van Hagen

    (@ravanh)

    Hi @xue28 thanks for responding ??

    I’ve found WC_Install::manual_database_update() and WC_Install::run_manual_database_update() which might be useful. But I’ll have to test if the class is (or can be easily made available) after a switch_to_blog() on a multisite install…

    Hi @ravanh

    To test if the WC_Install class is available after a switch_to_blog() on a multisite install, you can follow these steps:

    1. Use the switch_to_blog() function to switch to the desired blog within the multisite installation.
    2. After switching to the blog, you can check if the WC_Install class is available by calling its methods. You mentioned WC_Install::manual_database_update() and WC_Install::run_manual_database_update(), so you can test if you can access and use these methods.
    3. If the WC_Install class is not directly available after the switch_to_blog() function, you may need to include the necessary WooCommerce files or instantiate the class manually.

    Cheers!

    Thread Starter Rolf Allard van Hagen

    (@ravanh)

    Hi @amiralifaroo thanks for the tips ??

    I’m currently considering if something very basic like this would work:

    $sites = get_sites( array( 'fields' => 'ids' ) );
    foreach ( $sites as $blog_id ) {
        switch_to_blog( $blog_id );
        wp_schedule_single_event( time(), 'wp_' . $blog_id . '_wc_updater_cron' );
        restore_current_blog();
    }
    

    The idea is to schedule an event on each blog that will, in turn, trigger the blog’s designated wp_XX_wc_updater_cron action upon the next wp-cron call…

    Thread Starter Rolf Allard van Hagen

    (@ravanh)

    Or is a php file with
    add_filter( 'woocommerce_enable_auto_update_db', '__return_true' );
    in the mu-plugins folder really all that we need?

    Saif

    (@babylon1999)

    Hello @ravanh,

    Or is a php file with
    add_filter( ‘woocommerce_enable_auto_update_db’, ‘__return_true’ );
    in the mu-plugins folder really all that we need?

    This is actually all you need, by default the value is set to false. :?)

    I suggest adding custom solutions to a code-adding plugin like Code Snippets. This way, if the filter name changes or anything unexpected happens in the future, the site won’t crash as it has a Safe Mode feature.

    Let us know if you have any other questions.

    Thread Starter Rolf Allard van Hagen

    (@ravanh)

    Hi @babylon1999 thanks for confirming ??

    About the code snippets plugin approach, this will not be easy to implement across a WordPress Multisite so I’ll go for a custom snippet in mu-plugins I think. And since it is calling a filter, any change to that filter name in the future should not cause any errors only break the functionality. Changes to the expected return value on the other hand, could cause an issue…

    Anyway, thanks for the feedback!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘DB update after plugin upgrade’ is closed to new replies.