class-wc-cli-com-command.php
1 year ago
class-wc-cli-com-extension-command.php
2 years ago
class-wc-cli-rest-command.php
4 weeks ago
class-wc-cli-runner.php
2 years ago
class-wc-cli-tool-command.php
6 years ago
class-wc-cli-tracker-command.php
5 years ago
class-wc-cli-update-command.php
9 months ago
class-wc-cli-com-extension-command.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WC_CLI_COM_Command class file. |
| 4 | * |
| 5 | * @package WooCommerce\CLI |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | if ( ! class_exists( 'Plugin_Command' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Allows to interact with extensions from WCCOM marketplace via CLI. |
| 18 | * |
| 19 | * @version 6.8 |
| 20 | * @package WooCommerce |
| 21 | */ |
| 22 | class WC_CLI_COM_Extension_Command extends Plugin_Command { |
| 23 | /** |
| 24 | * Registers a commands for managing WooCommerce.com extensions. |
| 25 | */ |
| 26 | public static function register_commands() { |
| 27 | WP_CLI::add_command( 'wc com extension', 'WC_CLI_COM_Extension_Command' ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Installs one or more plugins from wccom marketplace. |
| 32 | * |
| 33 | * ## OPTIONS |
| 34 | * |
| 35 | * <extension>... |
| 36 | * : One or more plugins to install. Accepts a plugin slug. |
| 37 | * |
| 38 | * [--force] |
| 39 | * : If set, the command will overwrite any installed version of the plugin, without prompting |
| 40 | * for confirmation. |
| 41 | * |
| 42 | * [--activate] |
| 43 | * : If set, the plugin will be activated immediately after install. |
| 44 | * |
| 45 | * [--activate-network] |
| 46 | * : If set, the plugin will be network activated immediately after install |
| 47 | * |
| 48 | * [--insecure] |
| 49 | * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. |
| 50 | * |
| 51 | * ## EXAMPLES |
| 52 | * |
| 53 | * # Install the latest version from WooCommerce.com and activate |
| 54 | * $ wp wc com extension install automatewoo --activate |
| 55 | * Downloading install package from http://s3.amazonaws.com/bucketname/automatewoo.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef...... |
| 56 | * Using cached file '/home/vagrant/.wp-cli/cache/plugin/automatewoo.zip'... |
| 57 | * Unpacking the package... |
| 58 | * Installing the plugin... |
| 59 | * Plugin installed successfully. |
| 60 | * Activating 'automatewoo'... |
| 61 | * Plugin 'automatewoo' activated. |
| 62 | * Success: Installed 1 of 1 plugins. |
| 63 | * |
| 64 | * # Forcefully re-install an installed plugin |
| 65 | * $ wp wc com extension install automatewoo --force |
| 66 | * Downloading install package from http://s3.amazonaws.com/bucketname/automatewoo.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef... |
| 67 | * Unpacking the package... |
| 68 | * Installing the plugin... |
| 69 | * Removing the old version of the plugin... |
| 70 | * Plugin updated successfully |
| 71 | * Success: Installed 1 of 1 plugins. |
| 72 | * |
| 73 | * @param array $args WP-CLI positional arguments. |
| 74 | * @param array $assoc_args WP-CLI associative arguments. |
| 75 | */ |
| 76 | public function install( $args, $assoc_args ) { |
| 77 | $subscriptions = WC_Helper_Updater::get_available_extensions_downloads_data(); |
| 78 | $extension = reset( $args ); |
| 79 | $extension_package_url = null; |
| 80 | |
| 81 | // Remove `--version` as we don't support it. |
| 82 | unset( $assoc_args['version'] ); |
| 83 | |
| 84 | // Filter by slug. |
| 85 | foreach ( $subscriptions as $subscription ) { |
| 86 | if ( $subscription['slug'] === $extension && ! is_null( $subscription['package'] ) ) { |
| 87 | |
| 88 | $extension_package_url = $subscription['package']; |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // No package found. |
| 94 | if ( is_null( $extension_package_url ) ) { |
| 95 | WP_CLI::warning( sprintf( 'We couldn\'t find a Subscription for \'%s\'', $extension ) ); |
| 96 | WP_CLI\Utils\report_batch_operation_results( $this->item_type, 'install', count( $args ), 0, 1 ); |
| 97 | |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | parent::install( array( $extension_package_url ), $assoc_args ); |
| 102 | } |
| 103 | } |
| 104 |