WC_Install::update
Push all needed DB updates to the queue for processing.
Method of the class: WC_Install{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Install::update();
WC_Install::update() WC Install::update code WC 10.3.3
private static function update() {
$current_db_version = get_option( 'woocommerce_db_version' );
$updates = self::get_db_update_callbacks();
$scheduled_time = time();
wc_get_logger()->info(
sprintf( 'Scheduling database updates (from %s)...', $current_db_version ),
array( 'source' => 'wc-updater' )
);
if ( self::is_db_auto_update_enabled() ) {
/**
* Filters the delay in seconds to apply to the scheduling of database updates when automatic updates are
* enabled.
*
* @since 9.9.0
*
* @param int $delay Delay to add (in seconds). Default is 0 (updates will run as soon as possible).
*/
$scheduled_time_delay = absint( apply_filters( 'woocommerce_db_update_schedule_delay', 0 ) );
if ( $scheduled_time_delay > 0 ) {
wc_get_logger()->info(
sprintf( ' Updates will begin running in approximately %s.', human_time_diff( 0, $scheduled_time_delay ) ),
array( 'source' => 'wc-updater' )
);
$scheduled_time += $scheduled_time_delay;
}
}
$loop = 0;
foreach ( $updates as $version => $update_callbacks ) {
if ( version_compare( $current_db_version, $version, '>=' ) ) {
continue;
}
foreach ( $update_callbacks as $update_callback ) {
WC()->queue()->schedule_single(
$scheduled_time + $loop,
'woocommerce_run_update_callback',
array(
'update_callback' => $update_callback,
),
'woocommerce-db-updates'
);
++$loop;
wc_get_logger()->info(
sprintf( ' [%s] Scheduled \'%s\'.', $version, $update_callback ),
array( 'source' => 'wc-updater' )
);
}
}
// After the callbacks finish, update the db version to the current WC db version.
$wc_db_version = array_key_last( $updates );
$wc_db_version = version_compare( WC()->version, $wc_db_version, '>' ) ? WC()->version : $wc_db_version;
$success = true;
if ( version_compare( $current_db_version, $wc_db_version, '<' ) &&
! WC()->queue()->get_next( 'woocommerce_update_db_to_current_version' ) ) {
$success = WC()->queue()->schedule_single(
$scheduled_time + $loop,
'woocommerce_update_db_to_current_version',
array(
'version' => $wc_db_version,
),
'woocommerce-db-updates'
) > 0;
}
if ( ! $success ) {
wc_get_logger()->error( 'There was an error scheduling database updates.', array( 'source' => 'wc-updater' ) );
// Revert back to nudge so updates are not missed.
if ( self::is_db_auto_update_enabled() ) {
self::add_update_db_notice();
}
return;
}
wc_get_logger()->info( 'Database updates scheduled.', array( 'source' => 'wc-updater' ) );
}