Skip to content

Commit 0229bbc

Browse files
authored
Update the install and update commands to support beta releases (#30)
* update install command to support version=beta * update update command to support version=beta * Add GF_CLI_Root::get_beta_plugin_info limit beta to gf and check beta version against stable version * update docblocks * Add GF_CLI_Root::get_slug Fix an issue where appending -beta to the slug can install old beta versions e.g. gravityformsdropbox-beta * fix typo * bump version; update change log
1 parent a23cf0a commit 0229bbc

File tree

4 files changed

+82
-20
lines changed

4 files changed

+82
-20
lines changed

change_log.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
= 1.3.1 =
2+
- Added support for using `--version=beta` with the `wp gf install` and `wp gf update` commands. Add-On beta releases are not currently supported.
3+
14
= 1.3 =
25
- Fixed an error occurring when using the `wp gf form notification create` command.
36

cli.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Gravity Forms CLI
44
Plugin URI: https://gravityforms.com
55
Description: Manage Gravity Forms with the WP CLI.
6-
Version: 1.3
6+
Version: 1.3.1
77
Author: Rocketgenius
88
Author URI: https://gravityforms.com
99
License: GPL-2.0+
@@ -30,7 +30,7 @@
3030
defined( 'ABSPATH' ) || die();
3131

3232
// Defines the current version of the CLI add-on
33-
define( 'GF_CLI_VERSION', '1.3' );
33+
define( 'GF_CLI_VERSION', '1.3.1' );
3434

3535
define( 'GF_CLI_MIN_GF_VERSION', '1.9.17.8' );
3636

includes/class-gf-cli-root.php

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GF_CLI_Root extends WP_CLI_Command {
2929
* wp gf version gravityformspolls
3030
*/
3131
public function version( $args, $assoc_args ) {
32-
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
32+
$slug = $this->get_slug( $args );
3333

3434
if ( $slug == 'gravityforms' ) {
3535
if ( class_exists( 'GFForms' ) ) {
@@ -51,7 +51,7 @@ public function version( $args, $assoc_args ) {
5151
}
5252

5353
if ( ! $addon_found ) {
54-
WP_CLI::error( 'Invalid pluging slug: ' . $slug );
54+
WP_CLI::error( 'Invalid plugin slug: ' . $slug );
5555
}
5656
}
5757
}
@@ -71,7 +71,7 @@ public function version( $args, $assoc_args ) {
7171
* : The license key if not already available in the GF_LICENSE_KEY constant.
7272
*
7373
* [--version=<version>]
74-
* : The version to be installed. Accepted values: auto-update, hotfix. Default: hotfix.
74+
* : The version to be installed. Accepted values: auto-update, hotfix, or beta. Default: hotfix.
7575
*
7676
* [--force]
7777
* : If set, the command will overwrite any installed version of the plugin, without prompting for confirmation.
@@ -92,9 +92,8 @@ public function version( $args, $assoc_args ) {
9292
* @synopsis [<slug>] [--key=<key>] [--version=<version>] [--force] [--activate] [--activate-network]
9393
*/
9494
public function install( $args, $assoc_args ) {
95-
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
96-
97-
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
95+
$slug = $this->get_slug( $args, true );
96+
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
9897

9998
if ( empty( $key ) ) {
10099
WP_CLI::error( 'A valid license key must be specified either in the GF_LICENSE_KEY constant or the --key option.' );
@@ -104,9 +103,8 @@ public function install( $args, $assoc_args ) {
104103

105104
$key = md5( $key );
106105

107-
$plugin_info = $this->get_plugin_info( $slug, $key );
108-
109-
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
106+
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
107+
$plugin_info = $version === 'beta' ? $this->get_beta_plugin_info( $slug, $key ) : $this->get_plugin_info( $slug, $key );
110108

111109
if ( $version == 'hotfix' ) {
112110
$download_url = isset( $plugin_info['download_url_latest'] ) ? $plugin_info['download_url_latest'] : '';
@@ -171,7 +169,7 @@ public function install( $args, $assoc_args ) {
171169
* : The license key if not already available in the GF_LICENSE_KEY constant.
172170
*
173171
* [--version=<version>]
174-
* : The version to be installed. Accepted values: auto-update, hotfix. Default: hotfix.
172+
* : The version to be installed. Accepted values: auto-update, hotfix, or beta. Default: hotfix.
175173
*
176174
*
177175
* ## EXAMPLES
@@ -187,9 +185,8 @@ public function update( $args, $assoc_args ) {
187185
WP_CLI::error( 'Gravity Forms is not active.' );
188186
}
189187

190-
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
191-
192-
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
188+
$slug = $this->get_slug( $args, true );
189+
$key = isset( $assoc_args['key'] ) ? $assoc_args['key'] : $key = $this->get_key();
193190

194191
if ( empty( $key ) ) {
195192
$key = GFCommon::get_key();
@@ -202,9 +199,8 @@ public function update( $args, $assoc_args ) {
202199
WP_CLI::error( 'A valid license key must be saved in the settings or specified in the GF_LICENSE_KEY constant or the --key option.' );
203200
}
204201

205-
$plugin_info = $this->get_plugin_info( $slug, $key );
206-
207-
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
202+
$version = isset( $assoc_args['version'] ) ? $assoc_args['version'] : 'hotfix';
203+
$plugin_info = $version === 'beta' ? $this->get_beta_plugin_info( $slug, $key ) : $this->get_plugin_info( $slug, $key );
208204

209205
if ( $version == 'hotfix' ) {
210206
$available_version = isset( $plugin_info['version_latest'] ) ? $plugin_info['version_latest'] : '';
@@ -266,7 +262,7 @@ public function update( $args, $assoc_args ) {
266262
*/
267263
public function setup( $args, $assoc_args ) {
268264

269-
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
265+
$slug = $this->get_slug( $args );
270266

271267
$force = WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
272268

@@ -321,7 +317,7 @@ public function setup( $args, $assoc_args ) {
321317
* @alias check-update
322318
*/
323319
public function check_update( $args, $assoc_args ) {
324-
$slug = isset( $args[0] ) ? $args[0] : 'gravityforms';
320+
$slug = $this->get_slug( $args );
325321

326322
$plugin_info = $this->get_plugin_info( $slug );
327323

@@ -381,4 +377,64 @@ private function get_plugin_info( $slug, $key = '' ) {
381377
$plugin_info = unserialize( $body );
382378
return $plugin_info;
383379
}
380+
381+
/**
382+
* Gets the plugin info for beta releases.
383+
*
384+
* @since 1.4
385+
*
386+
* @param string $slug The plugin or add-on slug.
387+
* @param string $key The license key.
388+
*
389+
* @return mixed
390+
* @throws \WP_CLI\ExitException
391+
*/
392+
private function get_beta_plugin_info( $slug, $key = '' ) {
393+
if ( $slug !== 'gravityforms' ) {
394+
WP_CLI::error( '--version=beta is not currently supported by add-ons.' );
395+
}
396+
397+
$beta_info = $this->get_plugin_info( $slug . '-beta', $key );
398+
$beta_version = isset( $beta_info['version'] ) ? $beta_info['version'] : '';
399+
$no_beta_msg = 'There is no beta release available at this time.';
400+
401+
if ( empty( $beta_version ) ) {
402+
WP_CLI::error( $no_beta_msg );
403+
}
404+
405+
$stable_info = $this->get_plugin_info( $slug, $key );
406+
$stable_version = isset( $stable_info['version'] ) ? $stable_info['version'] : '';
407+
408+
if ( $stable_version && version_compare( $stable_version, $beta_version, '>=' ) ) {
409+
WP_CLI::error( $no_beta_msg );
410+
}
411+
412+
return $beta_info;
413+
}
414+
415+
/**
416+
* Gets the plugin slug for the current command.
417+
*
418+
* @since 1.4
419+
*
420+
* @param array $args The command arguments.
421+
* @param false $beta_check Should we check for the -beta suffix and display an error if found?
422+
*
423+
* @return string
424+
* @throws \WP_CLI\ExitException
425+
*/
426+
private function get_slug( $args, $beta_check = false ) {
427+
if ( empty( $args[0] ) ) {
428+
return 'gravityforms';
429+
}
430+
431+
$slug = $args[0];
432+
433+
if ( $beta_check && strpos( $slug, '-beta' ) ) {
434+
WP_CLI::error( 'Appending -beta to the slug is not supported. Use --version=beta instead.' );
435+
}
436+
437+
return $slug;
438+
}
439+
384440
}

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ If you have any ideas for improvements please submit your idea at https://www.gr
185185

186186
== ChangeLog ==
187187

188+
= 1.3.1 =
189+
- Added support for using `--version=beta` with the `wp gf install` and `wp gf update` commands. Add-On beta releases are not currently supported.
190+
188191
= 1.3 =
189192
- Fixed an error occurring when using the `wp gf form notification create` command.
190193

0 commit comments

Comments
 (0)