Merge pull request #20241 from woocommerce/update/update-routine
Break up update routine and allow it run to multuple times
This commit is contained in:
commit
89daaebbca
|
@ -93,7 +93,7 @@ class WC_Background_Updater extends WC_Background_Process {
|
|||
* item from the queue.
|
||||
*
|
||||
* @param string $callback Update callback function.
|
||||
* @return mixed
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function task( $callback ) {
|
||||
wc_maybe_define_constant( 'WC_UPDATING', true );
|
||||
|
@ -102,15 +102,22 @@ class WC_Background_Updater extends WC_Background_Process {
|
|||
|
||||
include_once dirname( __FILE__ ) . '/wc-update-functions.php';
|
||||
|
||||
$result = false;
|
||||
|
||||
if ( is_callable( $callback ) ) {
|
||||
$logger->info( sprintf( 'Running %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||
call_user_func( $callback );
|
||||
$logger->info( sprintf( 'Finished %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||
$result = (bool) call_user_func( $callback );
|
||||
|
||||
if ( $result ) {
|
||||
$logger->info( sprintf( '%s callback needs to run again', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||
} else {
|
||||
$logger->info( sprintf( 'Finished running %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||
}
|
||||
} else {
|
||||
$logger->notice( sprintf( 'Could not find %s callback', $callback ), array( 'source' => 'wc_db_updates' ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
return $result ? $callback : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,6 +101,7 @@ class WC_Install {
|
|||
),
|
||||
'3.4.0' => array(
|
||||
'wc_update_340_states',
|
||||
'wc_update_340_state',
|
||||
'wc_update_340_last_active',
|
||||
'wc_update_340_db_version',
|
||||
),
|
||||
|
|
|
@ -1638,8 +1638,6 @@ function wc_update_330_db_version() {
|
|||
* Update state codes for Ireland and BD.
|
||||
*/
|
||||
function wc_update_340_states() {
|
||||
global $wpdb;
|
||||
|
||||
$country_states = array(
|
||||
'IE' => array(
|
||||
'CK' => 'CO',
|
||||
|
@ -1714,6 +1712,23 @@ function wc_update_340_states() {
|
|||
),
|
||||
);
|
||||
|
||||
update_option( 'woocommerce_update_340_states', $country_states );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update next state in the queue.
|
||||
*
|
||||
* @return bool True to run again, false if completed.
|
||||
*/
|
||||
function wc_update_340_state() {
|
||||
global $wpdb;
|
||||
|
||||
$country_states = array_filter( (array) get_option( 'woocommerce_update_340_states', array() ) );
|
||||
|
||||
if ( empty( $country_states ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $country_states as $country => $states ) {
|
||||
foreach ( $states as $old => $new ) {
|
||||
$wpdb->query(
|
||||
|
@ -1743,8 +1758,22 @@ function wc_update_340_states() {
|
|||
'tax_rate_state' => strtoupper( $old ),
|
||||
)
|
||||
);
|
||||
unset( $country_states[ $country ][ $old ] );
|
||||
|
||||
if ( empty( $country_states[ $country ] ) ) {
|
||||
unset( $country_states[ $country ] );
|
||||
}
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $country_states ) ) {
|
||||
return update_option( 'woocommerce_update_340_states', $country_states );
|
||||
}
|
||||
|
||||
delete_option( 'woocommerce_update_340_states' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue