Merge pull request #12583 from woocommerce/cli-updates
Update CLI callback
This commit is contained in:
commit
a9f8ccd77c
|
@ -22,6 +22,7 @@ class WC_CLI {
|
|||
require_once __DIR__ . '/cli/class-wc-cli-runner.php';
|
||||
require_once __DIR__ . '/cli/class-wc-cli-rest-command.php';
|
||||
require_once __DIR__ . '/cli/class-wc-cli-tool-command.php';
|
||||
require_once __DIR__ . '/cli/class-wc-cli-update-command.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +30,7 @@ class WC_CLI {
|
|||
*/
|
||||
private function hooks() {
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Runner::after_wp_load' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Tool_Command::register_tool_commands' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Tool_Command::register_commands' );
|
||||
WP_CLI::add_hook( 'after_wp_load', 'WC_CLI_Update_Command::register_commands' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ class WC_Install {
|
|||
'wc_update_270_grouped_products',
|
||||
'wc_update_270_settings',
|
||||
'wc_update_270_product_visibility',
|
||||
'wc_update_270_db_version',
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -223,6 +224,16 @@ class WC_Install {
|
|||
add_option( 'woocommerce_version', WC()->version );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of DB update callbacks.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return array
|
||||
*/
|
||||
public static function get_db_update_callbacks() {
|
||||
return self::$db_updates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push all needed DB updates to the queue for processing.
|
||||
*/
|
||||
|
@ -231,7 +242,7 @@ class WC_Install {
|
|||
$logger = wc_get_logger();
|
||||
$update_queued = false;
|
||||
|
||||
foreach ( self::$db_updates as $version => $update_callbacks ) {
|
||||
foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
|
||||
if ( version_compare( $current_db_version, $version, '<' ) ) {
|
||||
foreach ( $update_callbacks as $update_callback ) {
|
||||
$logger->add( 'wc_db_updates', sprintf( 'Queuing %s - %s', $version, $update_callback ) );
|
||||
|
|
|
@ -15,7 +15,7 @@ class WC_CLI_Tool_Command {
|
|||
* since we only want to enable certain actions on the system status
|
||||
* tools endpoints.
|
||||
*/
|
||||
public static function register_tool_commands() {
|
||||
public static function register_commands() {
|
||||
global $wp_rest_server;
|
||||
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wc/v1/system_status/tools' );
|
||||
|
@ -86,7 +86,6 @@ class WC_CLI_Tool_Command {
|
|||
'when' => ! empty( $command_args['when'] ) ? $command_args['when'] : '',
|
||||
'before_invoke' => $before_invoke,
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* Allows updates via CLI.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @package WooCommerce
|
||||
*/
|
||||
class WC_CLI_Update_Command {
|
||||
|
||||
/**
|
||||
* Registers the update command.
|
||||
*/
|
||||
public static function register_commands() {
|
||||
WP_CLI::add_command( 'wc update', array( 'WC_CLI_Update_Command', 'update' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all pending WooCommerce database updates.
|
||||
*/
|
||||
public static function update() {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->hide_errors();
|
||||
|
||||
include_once( WC_ABSPATH . 'includes/class-wc-install.php' );
|
||||
include_once( WC_ABSPATH . 'includes/wc-update-functions.php' );
|
||||
|
||||
$current_db_version = get_option( 'woocommerce_db_version' );
|
||||
$update_count = 0;
|
||||
|
||||
foreach ( WC_Install::get_db_update_callbacks() as $version => $update_callbacks ) {
|
||||
if ( version_compare( $current_db_version, $version, '<' ) ) {
|
||||
foreach ( $update_callbacks as $update_callback ) {
|
||||
WP_CLI::log( sprintf( __( 'Calling update function: %s', 'woocommerce' ), $update_callback ) );
|
||||
call_user_func( $update_callback );
|
||||
$update_count ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WC_Admin_Notices::remove_notice( 'update' );
|
||||
WP_CLI::success( sprintf( __( '%1$d updates complete. Database version is %2$s', 'woocommerce' ), absint( $update_count ), get_option( 'woocommerce_db_version' ) ) );
|
||||
}
|
||||
}
|
|
@ -1070,3 +1070,10 @@ function wc_update_270_product_visibility() {
|
|||
$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->term_relationships} SELECT post_id, %d, 0 FROM {$wpdb->postmeta} WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 5;", $rating_term->term_id ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update DB Version.
|
||||
*/
|
||||
function wc_update_270_db_version() {
|
||||
WC_Install::update_db_version( '2.7.0' );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue