Skip to content

Commit bf3fe91

Browse files
committed
Convert old args to new for backward compatibility
Signed-off-by: Riddhesh Sanghvi <[email protected]>
1 parent 399aa4d commit bf3fe91

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/Site_Command.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static function get_site_types() {
6363
public function __invoke( $args, $assoc_args ) {
6464

6565
$site_types = self::get_site_types();
66+
$assoc_args = $this->convert_old_args_to_new_args( $args, $assoc_args );
6667

6768
if ( isset( $assoc_args['type'] ) ) {
6869
$type = $assoc_args['type'];
@@ -134,4 +135,65 @@ private function determine_type( $args ) {
134135

135136
return $type;
136137
}
138+
139+
/**
140+
* Convert EE v3 args to the newer syntax of arguments.
141+
*
142+
* @param array $args Commandline arguments passed.
143+
* @param array $assoc_args Commandline associative arguments passed.
144+
*
145+
* @return array Updated $assoc_args.
146+
*/
147+
private function convert_old_args_to_new_args( $args, $assoc_args ) {
148+
149+
$ee3_compat_array_map_to_type = [
150+
'wp' => [ 'type' => 'wp' ],
151+
'wpsubdom' => [ 'type' => 'wp', 'mu' => 'subdom' ],
152+
'wpsubdir' => [ 'type' => 'wp', 'mu' => 'subdir' ],
153+
'wpredis' => [ 'type' => 'wp', 'cache' => true ],
154+
'html' => [ 'type' => 'html' ],
155+
'php' => [ 'type' => 'php' ],
156+
'mysql' => [ 'type' => 'php', 'with-db' => true ],
157+
'le' => [ 'ssl' => 'le' ],
158+
'letsencrypt' => [ 'ssl' => 'le' ],
159+
];
160+
161+
foreach ( $ee3_compat_array_map_to_type as $from => $to ) {
162+
if ( isset( $assoc_args[ $from ] ) ) {
163+
$assoc_args = array_merge( $assoc_args, $to );
164+
unset( $assoc_args[ $from ] );
165+
}
166+
}
167+
168+
// ee3 backward compatibility flags
169+
$wp_compat_array_map = [
170+
'user' => 'admin-user',
171+
'pass' => 'admin-pass',
172+
'email' => 'admin-email',
173+
];
174+
175+
foreach ( $wp_compat_array_map as $from => $to ) {
176+
if ( isset( $assoc_args[ $from ] ) ) {
177+
$assoc_args[ $to ] = $assoc_args[ $from ];
178+
unset( $assoc_args[ $from ] );
179+
}
180+
}
181+
182+
// backward compatibility error for deprecated flags.
183+
$unsupported_create_old_args = array(
184+
'w3tc',
185+
'wpsc',
186+
'wpfc',
187+
'pagespeed',
188+
);
189+
190+
$old_arg = array_intersect( $unsupported_create_old_args, array_keys( $assoc_args ) );
191+
192+
$old_args = implode( ' --', $old_arg );
193+
if ( isset( $args[1] ) && 'create' === $args[1] && ! empty ( $old_arg ) ) {
194+
\EE::error( "Sorry, --$old_args flag/s is/are no longer supported in EE v4.\nPlease run `ee help " . implode( ' ', $args ) . '`.' );
195+
}
196+
197+
return $assoc_args;
198+
}
137199
}

0 commit comments

Comments
 (0)