@@ -40,6 +40,15 @@ class WordPressSetup extends Command
40
40
const FLEXIBLE_ENV = 'Flexible Environment ' ;
41
41
const STANDARD_ENV = 'Standard Environment ' ;
42
42
43
+ const DEFAULT_DB_REGION = 'us-central1 ' ;
44
+
45
+ private static $ availableDbRegions = array (
46
+ 'us-central1 ' ,
47
+ 'us-east1 ' ,
48
+ 'europe-west1 ' ,
49
+ 'asia-east1 ' ,
50
+ );
51
+
43
52
protected function configure ()
44
53
{
45
54
$ this
@@ -63,13 +72,29 @@ protected function configure()
63
72
'Directory for the new project ' ,
64
73
self ::DEFAULT_DIR
65
74
)
75
+ ->addOption (
76
+ 'sql_gen ' ,
77
+ '' ,
78
+ InputOption::VALUE_OPTIONAL ,
79
+ sprintf ('Cloud SQL generation to use; 2: %s, 1: %s ' ,
80
+ 'Second Generation ' ,
81
+ 'First Generation ' ),
82
+ 2
83
+ )
66
84
->addOption (
67
85
'project_id ' ,
68
86
'p ' ,
69
87
InputOption::VALUE_OPTIONAL ,
70
88
'Google Cloud project id ' ,
71
89
''
72
90
)
91
+ ->addOption (
92
+ 'db_region ' ,
93
+ null ,
94
+ InputOption::VALUE_OPTIONAL ,
95
+ 'Cloud SQL region ' ,
96
+ ''
97
+ )
73
98
->addOption (
74
99
'db_instance ' ,
75
100
null ,
@@ -225,15 +250,53 @@ protected function execute(InputInterface $input, OutputInterface $output)
225
250
$ q ->setErrorMessage ('Environment %s is invalid. ' );
226
251
$ env = $ helper ->ask ($ input , $ output , $ q );
227
252
}
228
- $ output ->writeln ('Creating a new project for: ' . $ env );
253
+ $ output ->writeln ('Creating a new project for: ' . $ env
254
+ . ' ' );
255
+
256
+ // Determine the Cloud SQL Generation to use.
257
+ $ sql_gen = $ input ->getOption ('sql_gen ' );
258
+ switch ($ sql_gen ) {
259
+ case '1 ' :
260
+ if ($ env === self ::FLEXIBLE_ENV ) {
261
+ $ output ->writeln ('You can not use '
262
+ . 'Cloud SQL First Generation with '
263
+ . self ::FLEXIBLE_ENV . '. ' );
264
+ return self ::DEFAULT_ERROR ;
265
+ }
266
+ $ db_connection_pattern = '%s:%s ' ;
267
+ break ;
268
+ case '2 ' :
269
+ $ db_region = $ input ->getOption ('db_region ' );
270
+ if (! in_array ($ db_region , self ::$ availableDbRegions )) {
271
+ $ q = new ChoiceQuestion (
272
+ 'Please select the region of your Cloud SQL instance '
273
+ . '(defaults to ' . self ::DEFAULT_DB_REGION . ') ' ,
274
+ self ::$ availableDbRegions ,
275
+ self ::DEFAULT_DB_REGION
276
+ );
277
+ $ q ->setErrorMessage ('DB region %s is invalid. ' );
278
+ $ db_region = $ helper ->ask ($ input , $ output , $ q );
279
+ $ output ->writeln ('Using a db_region: ' . $ db_region
280
+ . ' ' );
281
+ }
282
+ $ db_connection_pattern = "%s: $ db_region:%s " ;
283
+ break ;
284
+ default :
285
+ $ output ->writeln (
286
+ sprintf (
287
+ 'Invalid value for sql_gen: %s. ' ,
288
+ $ sql_gen
289
+ )
290
+ );
291
+ return self ::DEFAULT_ERROR ;
292
+ }
229
293
230
294
$ output ->writeln ('Downloading the WordPress archive... ' );
231
295
$ wpUrl = $ input ->getOption ('wordpress_url ' );
232
296
$ project ->downloadArchive ('the WordPress archive ' , $ wpUrl );
233
297
if (!$ this ->report ($ output , $ project )) {
234
298
return self ::DEFAULT_ERROR ;
235
299
}
236
-
237
300
$ output ->writeln ('Downloading the Batcache plugin... ' );
238
301
$ project ->downloadArchive (
239
302
'Batcache plugin ' , self ::LATEST_BATCACHE ,
@@ -301,6 +364,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
301
364
}
302
365
$ params = array ();
303
366
$ this ->askParameters ($ keys , $ params , $ input , $ output , $ helper );
367
+ $ params ['db_connection ' ] = sprintf (
368
+ $ db_connection_pattern ,
369
+ $ params ['project_id ' ],
370
+ $ params ['db_instance ' ]
371
+ );
304
372
$ q = new ConfirmationQuestion (
305
373
'Do you want to use the same db user and password for '
306
374
. 'local run? (Y/n) ' ,
0 commit comments