Skip to content

Commit

Permalink
Allowing Inspector state to be cleared. (#1559)
Browse files Browse the repository at this point in the history
* Allowing Inspector state to be cleared.

* Fixing misleading typo.
  • Loading branch information
grasmash authored May 31, 2017
1 parent 56587dd commit f83ae6f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Robo/Blt.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function configureContainer($container) {
$container->add('executor', Executor::class)
->withArgument('builder');

$container->add('inspector', Inspector::class)
$container->share('inspector', Inspector::class)
->withArgument('executor');

$container->inflector(InspectorAwareInterface::class)
Expand Down
11 changes: 7 additions & 4 deletions src/Robo/Commands/Blt/DoctorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,28 @@ public function doctor() {
&& !$this->getInspector()->isVmCli()) {
$result = $this->executeDoctorInsideVm();
if ($result->wasSuccessful()) {
return $result;
return $result->getExitCode();
}
}

// Try BLT doctor with default alias. This might be a Drupal VM alias.
$alias = $this->getConfigValue('drush.alias');
$this->say('Attempting to run doctor on host machine...');
$result = $this->executeDoctorOnHost($alias);

// If default alias failed, try again using @self alias.
if (!$result->wasSuccessful() && $alias != 'self') {
$this->logger->warning("Unable to run the doctor using @$alias. Trying with @self...");
$this->logger->warning("Unable to run the doctor using alias '@$alias'. Trying with '@self'...");
$this->executeDoctorOnHost('self');
}

// If @self fails, try without any alias.
if (!$result->wasSuccessful() && $alias != '') {
$this->logger->warning("Unable to run the doctor using @self. Trying without alias...");
$this->logger->warning("Unable to run the doctor using alias '@self'. Trying without alias...");
$this->executeDoctorOnHost('');
}

return $result;
return $result->getExitCode();
}

/**
Expand Down Expand Up @@ -73,6 +74,8 @@ protected function executeDoctorOnHost($alias) {
->alias($alias)
->uri("")
->includePath($this->getConfigValue('blt.root') . '/drush')
->printOutput(FALSE)
->printMetadata(FALSE)
->run();

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Robo/Commands/Setup/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BuildCommand extends BltTasks {
* @aliases setup:all
*/
public function setup() {
$this->say("Setting up local environment for @{$this->getConfigValue('site')}...");
$this->say("Setting up local environment for site '{$this->getConfigValue('site')}'...");
$status_code = $this->invokeCommands([
'setup:build',
'setup:hash-salt',
Expand Down
33 changes: 23 additions & 10 deletions src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, LoggerAw
*/
protected $executor;

/**
* @var null
*/
protected $isDrupalInstalled = NULL;

/**
* @var null
*/
protected $isMySqlAvailable = NULL;

/**
* The constructor.
*
Expand All @@ -43,6 +53,11 @@ public function __construct(Executor $executor) {
$this->executor = $executor;
}

public function clearState() {
$this->isDrupalInstalled = NULL;
$this->isMySqlAvailable = NULL;
}

/**
* Determines if the repository root directory exists.
*
Expand Down Expand Up @@ -123,20 +138,19 @@ public function isDrupalSettingsFileValid() {
/**
* Checks that Drupal is installed, caches result.
*
* This method caches its result in state.drupal.installed value.
* This method caches its result in $this->drupalIsInstalled.
*
* @return bool
* TRUE if Drupal is installed.
*/
public function isDrupalInstalled() {
// This will only run once per command. If Drupal is installed mid-command,
// this value needs to be changed.
if (is_null($this->getConfigValue('state.drupal.installed'))) {
$installed = $this->getDrupalInstalled();
$this->getConfig()->set('state.drupal.installed', $installed);
if (is_null($this->isDrupalInstalled)) {
$this->isDrupalInstalled = $this->getDrupalInstalled();
}

return $this->getConfigValue('state.drupal.installed');
return $this->isDrupalInstalled;
}

/**
Expand Down Expand Up @@ -171,18 +185,17 @@ public function getDrushStatus() {
/**
* Determines if MySQL is available, caches result.
*
* This method caches its result in state.mysql.available config.
* This method caches its result in $this->mySqlAvailable.
*
* @return bool
* TRUE if MySQL is available.
*/
public function isMySqlAvailable() {
if (is_null($this->getConfigValue('state.mysql.available'))) {
$mysql_available = $this->getMySqlAvailable();
$this->getConfig()->set('state.mysql.available', $mysql_available);
if (is_null($this->isMySqlAvailable)) {
$this->isMySqlAvailable = $this->getMySqlAvailable();
}

return $this->getConfigValue('state.mysql.available');
return $this->isMySqlAvailable;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Robo/Wizards/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function wizardInstallDrupal() {
->execute("$bin/blt setup")
->detectInteractive()
->run();
$this->getInspector()->clearState();
}
}
}
Expand Down

0 comments on commit f83ae6f

Please sign in to comment.