@@ -43,6 +43,11 @@ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, LoggerAw
43
43
*/
44
44
protected $ isMySqlAvailable = NULL ;
45
45
46
+ /**
47
+ * @var array
48
+ */
49
+ protected $ drupalVmStatus = [];
50
+
46
51
/**
47
52
* The constructor.
48
53
*
@@ -56,6 +61,7 @@ public function __construct(Executor $executor) {
56
61
public function clearState () {
57
62
$ this ->isDrupalInstalled = NULL ;
58
63
$ this ->isMySqlAvailable = NULL ;
64
+ $ this ->drupalVmStatus = [];
59
65
}
60
66
61
67
/**
@@ -234,11 +240,10 @@ public function isDrupalVmConfigPresent() {
234
240
* TRUE if Drupal VM is initialized for the local machine.
235
241
*/
236
242
public function isDrupalVmLocallyInitialized () {
237
- // We assume that if the local drush alias is ${project.machine_name.local},
238
- // rather than self, then Drupal VM is being used locally.
239
- $ drush_local_alias = $ this ->getConfigValue ('drush.aliases.local ' );
240
- $ expected_vm_alias = $ this ->getConfigValue ('project.machine_name ' ) . '.local ' ;
241
- $ initialized = ($ drush_local_alias == $ expected_vm_alias ) && file_exists ($ this ->getConfigValue ('repo.root ' ) . '/box/config.yml ' );
243
+ $ status = $ this ->getDrupalVmStatus ();
244
+ $ machine_name = $ this ->getConfigValue ('project.machine_name ' );
245
+ $ initialized = !empty ($ status [$ machine_name ])
246
+ && file_exists ($ this ->getConfigValue ('repo.root ' ) . '/box/config.yml ' );
242
247
$ statement = $ initialized ? "is " : "is not " ;
243
248
$ this ->logger ->debug ("Drupal VM $ statement initialized. " );
244
249
@@ -256,14 +261,11 @@ public function isDrupalVmBooted() {
256
261
return FALSE ;
257
262
}
258
263
259
- $ result = $ this ->executor ->execute ("vagrant status " )
260
- ->printOutput (FALSE )
261
- ->printMetadata (FALSE )
262
- ->interactive (FALSE )
263
- ->run ();
264
- $ output = $ result ->getMessage ();
264
+ $ status = $ this ->getDrupalVmStatus ();
265
+ $ machine_name = $ this ->getConfigValue ('project.machine_name ' );
266
+ $ booted = !empty ($ status [$ machine_name ]['state ' ])
267
+ && $ status [$ machine_name ]['state ' ] == 'running ' ;
265
268
266
- $ booted = strstr ($ output , "running " );
267
269
$ statement = $ booted ? "is " : "is not " ;
268
270
$ this ->logger ->debug ("Drupal VM $ statement booted. " );
269
271
@@ -504,4 +506,40 @@ public function isSimpleSamlPhpInstalled() {
504
506
return $ this ->getConfig ()->has ('simplesamlphp ' ) && $ this ->getConfigValue ('simplesamlphp ' );
505
507
}
506
508
509
+ /**
510
+ * Gets the value of $this->drupalVmStatus. Sets it if empty.
511
+ *
512
+ * @return array
513
+ * An array of status data.
514
+ */
515
+ protected function getDrupalVmStatus () {
516
+ if (empty ($ this ->drupalVmStatus )) {
517
+ $ this ->setDrupalVmStatus ();
518
+ }
519
+ return $ this ->drupalVmStatus ;
520
+ }
521
+
522
+ /**
523
+ * Sets $this->drupalVmStatus by executing `vagrant status`.
524
+ */
525
+ protected function setDrupalVmStatus () {
526
+ $ result = $ this ->executor ->execute ("vagrant status --machine-readable " )
527
+ ->printOutput (FALSE )
528
+ ->printMetadata (FALSE )
529
+ ->interactive (FALSE )
530
+ ->run ();
531
+ $ output = $ result ->getOutputData ();
532
+ if (!$ result ->wasSuccessful () || !$ output ) {
533
+ return FALSE ;
534
+ }
535
+ $ lines = explode ("\n" , $ output );
536
+ foreach ($ lines as $ line ) {
537
+ if (count ($ line ) < 4 ) {
538
+ continue ;
539
+ }
540
+ list ($ timestamp , $ target , $ type , $ data ) = explode (', ' , $ line );
541
+ $ this ->drupalVmStatus [$ target ][$ type ] = $ data ;
542
+ }
543
+ }
544
+
507
545
}
0 commit comments