Add a new set of CLI commands to WooCommerce Beta Tester (#36339)
This commit is contained in:
parent
262b2ecebd
commit
11b46d4f77
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add a wp cli command for activating live branches.
|
|
@ -153,6 +153,13 @@ Copy and paste the system status report from **WooCommerce > System Status** in
|
|||
* @return string
|
||||
*/
|
||||
protected function construct_ssr() {
|
||||
// This function depends on the WC core global being available. Sometimes, such as when we deactivate
|
||||
// WC to install a live branches version, WC will not be available and cause a crash if we don't exit early
|
||||
// here.
|
||||
if ( ! class_exists( 'WC' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( version_compare( WC()->version, '3.6', '<' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
@ -332,7 +339,7 @@ Copy and paste the system status report from **WooCommerce > System Status** in
|
|||
$items_to_remove = array( 'wc-beta-tester-settings', 'wc-beta-tester-version-picker', 'wc-beta-tester' );
|
||||
if ( isset( $submenu['plugins.php'] ) ) {
|
||||
foreach ( $submenu['plugins.php'] as $key => $menu ) {
|
||||
if ( in_array( $menu[2], $items_to_remove ) ) {
|
||||
if ( in_array( $menu[2], $items_to_remove, true ) ) {
|
||||
unset( $submenu['plugins.php'][ $key ] );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Beta Tester CLI controls
|
||||
*
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_CLI_Command' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Control your local WooCommerce Beta Tester plugin.
|
||||
*/
|
||||
class WC_Beta_Tester_CLI extends WP_CLI_Command {
|
||||
|
||||
/**
|
||||
* Install a live branch of the WooCommerce plugin
|
||||
*
|
||||
* ## Options
|
||||
* <branch>
|
||||
* : The branch to install.
|
||||
*
|
||||
* ## Examples
|
||||
*
|
||||
* wp wc-beta-tester install update/some-branch
|
||||
*
|
||||
* @param array $args Arguments passed to CLI.
|
||||
*/
|
||||
public function install( $args ) {
|
||||
$installer = new WC_Beta_Tester_Live_Branches_Installer();
|
||||
|
||||
$branch = $args[0];
|
||||
|
||||
$info = $installer->get_branch_info_from_manifest( $branch );
|
||||
|
||||
if ( ! $info ) {
|
||||
WP_CLI::error( "Could not find branch $branch in manifest" );
|
||||
} else {
|
||||
$install_result = $installer->install( $info->download_url, $info->branch, $info->version );
|
||||
|
||||
if ( is_wp_error( $install_result ) ) {
|
||||
WP_CLI::error( $install_result->get_error_message() );
|
||||
}
|
||||
|
||||
WP_CLI::success( "Installed $branch" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate WooCommerce.
|
||||
*
|
||||
* ## Examples
|
||||
* wp wc-beta-tester deactivate_woocommerce
|
||||
*/
|
||||
public function deactivate_woocommerce() {
|
||||
$installer = new WC_Beta_Tester_Live_Branches_Installer();
|
||||
$installer->deactivate_woocommerce();
|
||||
|
||||
WP_CLI::success( 'Deactivated WooCommerce' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a live branch of the WooCommerce plugin.
|
||||
*
|
||||
* ## Options
|
||||
* <branch>
|
||||
* : The branch to activate.
|
||||
*
|
||||
* ## Examples
|
||||
*
|
||||
* wp wc-beta-tester activate update/some-branch*
|
||||
*
|
||||
* @param array $args Arguments passed to CLI.
|
||||
*/
|
||||
public function activate( $args ) {
|
||||
$installer = new WC_Beta_Tester_Live_Branches_Installer();
|
||||
$branch = $args[0];
|
||||
$info = $installer->get_branch_info_from_manifest( $branch );
|
||||
|
||||
if ( ! $info ) {
|
||||
WP_CLI::error( "Could not find branch $branch in manifest" );
|
||||
} else {
|
||||
$installer->activate( $info->version );
|
||||
|
||||
WP_CLI::success( "Activated $branch" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,26 @@ class WC_Beta_Tester_Live_Branches_Installer {
|
|||
return $wp_filesystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the download url of a WooCommerce plugin version from the manifest.
|
||||
*
|
||||
* @param string $branch The name of the branch.
|
||||
*/
|
||||
public function get_branch_info_from_manifest( $branch ) {
|
||||
$response = wp_remote_get( 'https://betadownload.jetpack.me/woocommerce-branches.json' );
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
$obj = json_decode( $body );
|
||||
|
||||
foreach ( $obj->pr as $key => $value ) {
|
||||
if ( $value->branch === $branch ) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a WooCommerce plugin version by download url.
|
||||
*
|
||||
|
|
|
@ -109,7 +109,7 @@ const BranchInfo = ( { branch }: { branch: Branch } ) => {
|
|||
|
||||
const WooCommerceVersionInfo = () => {
|
||||
// @ts-ignore
|
||||
const version = window?.wc?.WC_VERSION || 'unknown';
|
||||
const version = window?.wc?.wcSettings?.WC_VERSION || 'unknown';
|
||||
|
||||
return (
|
||||
<p>
|
||||
|
@ -136,6 +136,8 @@ export const BranchList = ( { branches }: { branches: Branch[] } ) => {
|
|||
uninstalledBranches[ 0 ]
|
||||
);
|
||||
|
||||
const installedBranchesExist = !! installedBranches.length;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card elevation={ 3 } css={ cardStyle }>
|
||||
|
@ -188,7 +190,7 @@ export const BranchList = ( { branches }: { branches: Branch[] } ) => {
|
|||
</CardBody>
|
||||
<CardFooter></CardFooter>
|
||||
</Card>
|
||||
{ installedBranches.length && (
|
||||
{ installedBranchesExist && (
|
||||
<Card elevation={ 3 } css={ cardStyle }>
|
||||
<CardHeader>
|
||||
<h2>Other Installed Branches</h2>
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
require_once dirname( __FILE__ ) . '/includes/class-wc-beta-tester-cli.php';
|
||||
WP_CLI::add_command( 'wc-beta-tester', WC_Beta_Tester_CLI::class );
|
||||
}
|
||||
|
||||
// Define WC_BETA_TESTER_FILE.
|
||||
if ( ! defined( 'WC_BETA_TESTER_FILE' ) ) {
|
||||
define( 'WC_BETA_TESTER_FILE', __FILE__ );
|
||||
|
@ -63,7 +69,7 @@ function _wc_beta_tester_bootstrap() {
|
|||
}
|
||||
|
||||
// Load admin.
|
||||
require( 'plugin.php' );
|
||||
require 'plugin.php';
|
||||
}
|
||||
|
||||
add_action( 'plugins_loaded', '_wc_beta_tester_bootstrap' );
|
||||
|
@ -75,12 +81,12 @@ function add_extension_register_script() {
|
|||
$script_path = '/build/index.js';
|
||||
$script_asset_path = dirname( __FILE__ ) . '/build/index.asset.php';
|
||||
$script_asset = file_exists( $script_asset_path )
|
||||
? require( $script_asset_path )
|
||||
? require $script_asset_path
|
||||
: array(
|
||||
'dependencies' => array(),
|
||||
'version' => filemtime( $script_path ),
|
||||
);
|
||||
$script_url = plugins_url( $script_path, __FILE__ );
|
||||
$script_url = plugins_url( $script_path, __FILE__ );
|
||||
|
||||
wp_register_script(
|
||||
'woocommerce-admin-test-helper',
|
||||
|
|
Loading…
Reference in New Issue