WC_CLI_Update_Command

Allows updates via CLI.

Defined (1)

The class is defined in the following location(s).

/includes/cli/class-wc-cli-update-command.php  
  1. class WC_CLI_Update_Command { 
  2.  
  3. /** 
  4. * Registers the update command. 
  5. */ 
  6. public static function register_commands() { 
  7. WP_CLI::add_command( 'wc update', array( 'WC_CLI_Update_Command', 'update' ) ); 
  8.  
  9. /** 
  10. * Runs all pending WooCommerce database updates. 
  11. */ 
  12. public static function update() { 
  13. global $wpdb; 
  14.  
  15. $wpdb->hide_errors(); 
  16.  
  17. include_once( WC_ABSPATH . 'includes/class-wc-install.php' ); 
  18. include_once( WC_ABSPATH . 'includes/wc-update-functions.php' ); 
  19.  
  20. $current_db_version = get_option( 'woocommerce_db_version' ); 
  21. $update_count = 0; 
  22.  
  23. foreach ( WC_Install::get_db_update_callbacks() as $version => $update_callbacks ) { 
  24. if ( version_compare( $current_db_version, $version, '<' ) ) { 
  25. foreach ( $update_callbacks as $update_callback ) { 
  26. WP_CLI::log( sprintf( __( 'Calling update function: %s', 'woocommerce' ), $update_callback ) ); 
  27. call_user_func( $update_callback ); 
  28. $update_count ++; 
  29.  
  30. WC_Admin_Notices::remove_notice( 'update' ); 
  31. WP_CLI::success( sprintf( __( '%1$d updates complete. Database version is %2$s', 'woocommerce' ), absint( $update_count ), get_option( 'woocommerce_db_version' ) ) );