Skip to content

Commit ed45fab

Browse files
committed
Write Drupal Console site target to ~/.console/sites/terra.{appname}.yml
1 parent db95719 commit ed45fab

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/terra/Command/Environment/EnvironmentEnable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
}
7171

7272
// Write drush alias.
73-
$drush_alias_file_path = "{$_SERVER['HOME']}/.drush/{$app_name}.aliases.drushrc.php";
73+
$drush_alias_file_path = "{$_SERVER['HOME']}/.drush/terra.{$app_name}.aliases.drushrc.php";
7474
if ($environment_factory->writeDrushAlias()) {
7575
$output->writeln("<info>Drush alias file created at {$drush_alias_file_path}</info>");
7676
$output->writeln("Wrote drush alias file to <comment>$drush_alias_file_path</comment>");
@@ -79,6 +79,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
7979
$output->writeln('<error>Unable to save drush alias.</error>');
8080
}
8181

82+
// Write Drupal Console site targets.
83+
$console_target_file_path = "{$_SERVER['HOME']}/.console/sites/terra.{$app_name}.yml";
84+
if ($environment_factory->writeConsoleSiteTargets()) {
85+
$output->writeln("<info>Drupal Console site file created at {$console_target_file_path}</info>");
86+
$output->writeln("Wrote Drupal Console site file to <comment>$console_target_file_path</comment>");
87+
$output->writeln("Use <info>drupal {$environment_factory->getDrushAlias()}</info> to access the site.");
88+
} else {
89+
$output->writeln('<error>Unable to save Drupal Console site target.</error>');
90+
}
91+
8292
// Run the enable hooks
8393
$output->writeln('');
8494
$output->writeln('Running <comment>ENABLE</comment> app hook...');

src/terra/Factory/EnvironmentFactory.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,24 @@ public function getDrushPort()
583583
}
584584
}
585585

586+
/**
587+
* Get's the exposed port of the Drupal Console container.
588+
*
589+
* @return bool|mixed
590+
*/
591+
public function getDrupalConsolePort()
592+
{
593+
$process = new Process('docker-compose port console 22', $this->getDockerComposePath());
594+
$process->run();
595+
if (!$process->isSuccessful()) {
596+
return false;
597+
} else {
598+
$output_array = explode(':', trim($process->getOutput()));
599+
return array_pop($output_array);
600+
}
601+
}
602+
603+
586604
/**
587605
* Get the system URL of an environment.
588606
*
@@ -647,6 +665,39 @@ public function writeDrushAlias()
647665
}
648666
}
649667

668+
/**
669+
* Writes a local Drupal Console site file.
670+
*/
671+
public function writeConsoleSiteTargets()
672+
{
673+
$console_target_file_path = "{$_SERVER['HOME']}/.console/sites/terra.{$this->app->name}.yml";
674+
675+
$console_target_file = array();
676+
$console_target_file[] = '';
677+
678+
foreach ($this->app->environments as $environment_name => $environment) {
679+
$factory = new self($environment, $this->app);
680+
$path = "/source/" . $environment['document_root'];
681+
$console_target_file[] = '# DO NOT EDIT. This is generated by Terra. Any changes will be overridden when the environment is re-enabled.';
682+
$console_target_file[] = "{$environment_name}:";
683+
$console_target_file[] = " host: {$factory->getHost()}";
684+
$console_target_file[] = " root: $path";
685+
$console_target_file[] = " user: root";
686+
$console_target_file[] = " port: {$factory->getDrupalConsolePort()}";
687+
$console_target_file[] = '';
688+
}
689+
690+
$fs = new FileSystem();
691+
692+
try {
693+
$fs->dumpFile($console_target_file_path, implode("\n", $console_target_file));
694+
695+
return true;
696+
} catch (IOException $e) {
697+
return false;
698+
}
699+
}
700+
650701
/**
651702
* Get the name of the drush alias.
652703
*/

0 commit comments

Comments
 (0)