Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a99813

Browse files
committed
Add functionality to improve interoperation with the rest of WP-CLI
1 parent679603b commit2a99813

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

‎class/command.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ public function migrate( $args, $assoc_args ) {
5757
publicfunctioncreate_profile($args,$assoc_args ) {
5858
$name =$args[0];
5959

60-
if ( !isset($assoc_args['remote_wordpress'] ) || !isset($assoc_args['token'] ) ) {
60+
if ( !isset($assoc_args['remote-wordpress'] ) || !isset($assoc_args['token'] ) ) {
6161
$error_lines =array();
6262
$error_lines[] =__('Connection information to remote WordPress installation for migration is required.' );
63-
$error_lines[] =__('Set with --remote_wordpress and --token flag.' );
63+
$error_lines[] =__('Set with --remote-wordpress and --token flag.' );
6464
WP_CLI::error_multi_line($error_lines );
6565
return;
6666
}
6767

6868
$result =wpdsb_create_profile($name,$assoc_args );
6969

7070
if (true ===$result ) {
71-
WP_CLI::success(__('Profile created.','wp-sync-db-cli' ) );
71+
WP_CLI::success(sprintf(__('Profile%1$screated.','wp-sync-db-cli' ),$name ) );
7272
return;
7373
}
7474

‎class/wpsdb-cli.php‎

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ function __construct( $plugin_file_path ) {
1010
if( !$this->meets_version_requirements('1.4b1' ) )return;
1111
}
1212

13+
functionlog_list($list ) {
14+
foreach ($listas$item ) {
15+
WP_CLI::log("-$item" );
16+
}
17+
}
18+
19+
functionkebab_case_to_snake_case($value) {
20+
returnpreg_replace_callback('/-(.)/u',function($el) {
21+
return'_' .$el[1];
22+
},$value);
23+
}
24+
25+
functionkeys_from_kebab_case_to_snake_case($array ) {
26+
$result = [];
27+
28+
foreach ($arrayas$key =>$value) {
29+
$result[$this->kebab_case_to_snake_case($key ) ] =$value;
30+
}
31+
32+
return$result;
33+
}
34+
1335
functioncli_create_profile($name,$assoc_args ) {
1436
$wpsdb_settings =get_option('wpsdb_settings' );
1537

@@ -26,14 +48,18 @@ function cli_create_profile( $name, $assoc_args ) {
2648
return$this->cli_error(sprintf(__('Profile with the name %1$s already exists.','wp-sync-db-cli' ),$name ) );
2749
}
2850

51+
WP_CLI::log(sprintf(__('Creating database migration profile with name %1$s.','wp-sync-db-cli' ),$name ) );
52+
2953
$new_profile =array();
3054

3155
$new_profile["name"] =$name;
3256
$new_profile["create_new_profile"] =$name;
3357

3458
$new_profile["action"] ="pull";
3559

36-
$new_profile['connection_info'] =implode("\n",array($assoc_args['remote_wordpress'],$assoc_args['token'] ) );
60+
$new_profile['connection_info'] =implode("\n",array($assoc_args['remote-wordpress'],$assoc_args['token'] ) );
61+
unset($assoc_args['remote-wordpress'] );
62+
unset($assoc_args['token'] );
3763

3864
$new_profile["table_migrate_option"] ='migrate_only_with_prefix';
3965

@@ -63,12 +89,20 @@ function cli_create_profile( $name, $assoc_args ) {
6389
$new_profile["save_migration_profile"] ="1";
6490
$new_profile["save_migration_profile_option"] ="new";
6591

66-
$new_profile =array_merge($new_profile,$assoc_args );
92+
$new_profile =array_merge($new_profile,$this->keys_from_kebab_case_to_snake_case($assoc_args ) );
93+
94+
if (isset($assoc_args['exclude-post-types'] ) ) {
95+
$new_profile['exclude_post_types'] ='1';
96+
$new_profile['select_post_types'] =explode(',',$assoc_args['exclude-post-types'] );
6797

68-
if (isset($assoc_args['select_tables'] ) ) {
98+
WP_CLI::log(__('Excluding WordPress post types from migration profile:','wp-sync-db-cli' ) );
99+
$this->log_list($new_profile['select_post_types'] );
100+
}
101+
102+
if (isset($assoc_args['migrate-tables'] ) ) {
69103
$new_profile["table_migrate_option"] ='migrate_select';
70104

71-
if ($new_profile["select_tables"] ==='outlandish' ) {
105+
if ($new_profile["migrate-tables"] ==='outlandish' ) {
72106
WP_CLI::log(__('Selecting Outlandish default WordPress tables for migraton.','wp-sync-db-cli' ) );
73107
$new_profile["select_tables"] =array(
74108
"wp_commentmeta",
@@ -87,12 +121,9 @@ function cli_create_profile( $name, $assoc_args ) {
87121
"wp_users",
88122
);
89123
}else {
90-
$new_profile["select_tables"] =explode(',',$assoc_args['select_tables'] );
124+
$new_profile["select_tables"] =explode(',',$assoc_args['migrate-tables'] );
91125
WP_CLI::log(__('The following tables are selected for migration:','wp-sync-db-cli' ) );
92-
93-
foreach ($new_profile["select_tables"]as$table ) {
94-
WP_CLI::log("-$table" );
95-
}
126+
$this->log_list($new_profile["select_tables"] );
96127
}
97128
}
98129

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp