Skip to content

Commit 45df398

Browse files
committed
Print out token on command line programmatically
1 parent b98a5a4 commit 45df398

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

class/command.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ public function create_profile( $args, $assoc_args ) {
115115
return;
116116
}
117117

118+
/**
119+
* Echo out the DB token. For use in automation.
120+
*
121+
* ## EXAMPLES
122+
*
123+
* wp wpsdb connection-info
124+
*
125+
* @since 1.0
126+
* @subcommand connection-info
127+
*/
128+
public function connection_info( $args, $assoc_args ) {
129+
$result = wpsdb_cli_connection_info();
130+
131+
if ( $result ) {
132+
WP_CLI::log( $result );
133+
return;
134+
}
135+
136+
WP_CLI::warning( $result->get_error_message() );
137+
return;
138+
}
139+
118140
}
119141

120142
WP_CLI::add_command( 'wpsdb', 'WPSDBCLI' );

class/wpsdb-cli.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ function keys_from_kebab_case_to_snake_case( $array ) {
4747
return $result;
4848
}
4949

50+
function cli_connection_info( ) {
51+
$wpsdb_settings = get_option( 'wpsdb_settings' );
52+
53+
if ( $wpsdb_settings['key'] ) {
54+
return $wpsdb_settings['key'];
55+
} else {
56+
return $this->cli_error( __( 'Key could not be found in Migrate DB - this is not expected.', 'wp-sync-db-cli' ) );
57+
}
58+
}
59+
5060
function cli_create_profile( $name, $assoc_args ) {
5161
$wpsdb_settings = get_option( 'wpsdb_settings' );
5262

wp-sync-db-cli.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ function wpsdb_migrate( $profile ) {
3737
return $wpsdb_cli->cli_migration( $profile );
3838
}
3939

40+
function wpsdb_cli_connection_info() {
41+
global $wpsdb_cli;
42+
if( empty( $wpsdb_cli ) ) {
43+
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
44+
}
45+
return $wpsdb_cli->cli_connection_info();
46+
}
47+
4048
function wpdsb_create_profile( $name, $assoc_args ) {
4149
global $wpsdb_cli;
4250
if( empty( $wpsdb_cli ) ) {

0 commit comments

Comments
 (0)