Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions class/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ public function migrate( $args, $assoc_args ) {
return;
}

/**
* List all profiles.
*
* ## EXAMPLES
*
* wp wpsdb profiles
*
*/

public function profiles() {
$result = wpsdb_profiles();

if ( $result ) {
WP_CLI::log( __( $result, 'wp-sync-db-cli' ) );
return;
}

WP_CLI::warning( __( 'You have no profiles.', 'wp-sync-db-cli' ) );
return;
}

}

WP_CLI::add_command( 'wpsdb', 'WPSDBCLI' );
10 changes: 10 additions & 0 deletions class/wpsdb-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ function __construct( $plugin_file_path ) {
if( ! $this->meets_version_requirements( '1.4b1' ) ) return;
}

function cli_profiles() {
$wpsdb_settings = get_option( 'wpsdb_settings' );
$profiles = [];
foreach ($wpsdb_settings['profiles'] as $index => $profile) {
$id = $index + 1;
array_push($profiles, "\t{$id} | {$profile['action']} => {$profile['name']}");
}
return implode("\n", $profiles);;
}

function cli_migration( $profile ) {
global $wpsdb;
$wpsdb_settings = get_option( 'wpsdb_settings' );
Expand Down
8 changes: 8 additions & 0 deletions wp-sync-db-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ function wpsdb_migrate( $profile ) {
}
return $wpsdb_cli->cli_migration( $profile );
}

function wpsdb_profiles() {
global $wpsdb_cli;
if( empty( $wpsdb_cli ) ) {
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
}
return $wpsdb_cli->cli_profiles();
}