@@ -10,6 +10,28 @@ function __construct( $plugin_file_path ) {
1010if ( !$ this ->meets_version_requirements ('1.4b1 ' ) )return ;
1111}
1212
13+ function log_list ($ list ) {
14+ foreach ($ listas $ item ) {
15+ WP_CLI ::log ("- $ item " );
16+ }
17+ }
18+
19+ function kebab_case_to_snake_case ($ value ) {
20+ return preg_replace_callback ('/-(.)/u ' ,function ($ el ) {
21+ return '_ ' .$ el [1 ];
22+ },$ value );
23+ }
24+
25+ function keys_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+
1335function cli_create_profile ($ name ,$ assoc_args ) {
1436$ wpsdb_settings =get_option ('wpsdb_settings ' );
1537
@@ -26,14 +48,18 @@ function cli_create_profile( $name, $assoc_args ) {
2648return $ 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 ' ) {
72106WP_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 ' ] );
91125WP_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