Inheritance: extends Symfony\Component\Console\Helper\Helper, implements Platformsh\Cli\Console\OutputAwareInterface
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $projectRoot = $this->getProjectRoot();
     if (!$projectRoot) {
         throw new RootNotFoundException();
     }
     $projectConfig = LocalProject::getProjectConfig($projectRoot);
     $current_group = isset($projectConfig['alias-group']) ? $projectConfig['alias-group'] : $projectConfig['id'];
     if ($input->getOption('pipe')) {
         $output->writeln($current_group);
         return 0;
     }
     $project = $this->getCurrentProject();
     $new_group = ltrim($input->getOption('group'), '@');
     $homeDir = $this->getHomeDir();
     $drushHelper = new DrushHelper($output);
     $drushHelper->ensureInstalled();
     $drushHelper->setHomeDir($homeDir);
     $aliases = $drushHelper->getAliases($current_group);
     if ($new_group && $new_group != $current_group || !$aliases || $input->getOption('recreate')) {
         $new_group = $new_group ?: $current_group;
         $this->stdErr->writeln("Creating Drush aliases in the group <info>@{$new_group}</info>");
         $questionHelper = $this->getHelper('question');
         if ($new_group != $current_group) {
             $existing = $drushHelper->getAliases($new_group);
             if ($existing && $new_group != $current_group) {
                 $question = "The Drush alias group <info>@{$new_group}</info> already exists. Overwrite?";
                 if (!$questionHelper->confirm($question, $input, $output, false)) {
                     return 1;
                 }
             }
             LocalProject::writeCurrentProjectConfig('alias-group', $new_group, $projectRoot);
         }
         $environments = $this->getEnvironments($project, true, false);
         $drushHelper->createAliases($project, $projectRoot, $environments, $current_group);
         if ($new_group != $current_group) {
             $drushDir = $homeDir . '/.drush';
             $oldFile = $drushDir . '/' . $current_group . '.aliases.drushrc.php';
             if (file_exists($oldFile)) {
                 if ($questionHelper->confirm("Delete old Drush alias group <info>@{$current_group}</info>?", $input, $this->stdErr)) {
                     unlink($oldFile);
                 }
             }
         }
         // Clear the Drush cache now that the aliases have been updated.
         $drushHelper->clearCache();
         // Read the new aliases.
         $aliases = $drushHelper->getAliases($new_group);
     }
     if ($aliases) {
         $this->stdErr->writeln("Drush aliases for <info>{$project->title}</info> ({$project->id}):");
         foreach (explode("\n", $aliases) as $alias) {
             $output->writeln('    @' . $alias);
         }
     }
     return 0;
 }
 public function testCreateAliasesMultiDrupal()
 {
     // Set up file structure.
     $testDir = $this->createTempSubDir();
     $fsHelper = new FilesystemHelper();
     $fsHelper->copyAll(__DIR__ . '/../data/repositories/multi-drupal', $testDir . '/project/repository');
     $projectRoot = $testDir . '/project';
     $homeDir = "{$testDir}/home";
     mkdir($homeDir);
     // Check that aliases are created.
     $this->drushHelper->setHomeDir($homeDir);
     $this->drushHelper->createAliases($this->project, $projectRoot, $this->environments);
     $this->assertFileExists("{$homeDir}/.drush/test.aliases.drushrc.php");
     // Check that aliases exist for the 'master' and local environments.
     $aliases = [];
     include_once "{$homeDir}/.drush/test.aliases.drushrc.php";
     $this->assertArrayHasKey('master--drupal1', $aliases);
     $this->assertArrayHasKey('_local--drupal1', $aliases);
     $this->assertArrayHasKey('master--drupal2', $aliases);
     $this->assertArrayHasKey('_local--drupal2', $aliases);
 }
 public function testCreateAliases()
 {
     // Set up a dummy project with a remote environment.
     $project = new Project(array('id' => 'test', 'title' => 'Test project title'));
     $environments = array();
     $environments[] = new Environment(array('id' => 'master', '_links' => array('public-url' => array('href' => 'http://example.com'), 'ssh' => array('href' => 'ssh://user@example.com'))));
     // Set up file structure.
     $testDir = tempnam($this->root, '');
     unlink($testDir);
     mkdir($testDir);
     $projectRoot = "{$testDir}/project";
     $homeDir = "{$testDir}/home";
     mkdir($projectRoot);
     mkdir($homeDir);
     // Check that aliases are created.
     $this->drushHelper->setHomeDir($homeDir);
     $this->drushHelper->createAliases($project, $projectRoot, $environments);
     $this->assertFileExists("{$homeDir}/.drush/test.aliases.drushrc.php");
     // Check that aliases exist for the 'master' and local environments.
     $aliases = array();
     include_once "{$homeDir}/.drush/test.aliases.drushrc.php";
     $this->assertArrayHasKey('master', $aliases);
     $this->assertArrayHasKey('_local', $aliases);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $project = $this->getCurrentProject();
     if (!$project) {
         throw new \Exception('This can only be run from inside a project directory');
     }
     $projectRoot = $this->getProjectRoot();
     $projectConfig = LocalProject::getProjectConfig($projectRoot);
     $current_group = isset($projectConfig['alias-group']) ? $projectConfig['alias-group'] : $project['id'];
     if ($input->getOption('pipe') || !$this->isTerminal($output)) {
         $output->writeln($current_group);
         return 0;
     }
     $new_group = ltrim($input->getOption('group'), '@');
     $homeDir = $this->getHelper('fs')->getHomeDirectory();
     $drushHelper = new DrushHelper($output);
     $drushHelper->ensureInstalled();
     $drushHelper->setHomeDir($homeDir);
     if ($new_group && $new_group != $current_group) {
         $questionHelper = $this->getHelper('question');
         $existing = $drushHelper->getAliases($new_group);
         if ($existing) {
             if (!$questionHelper->confirm("The alias group <info>@{$new_group}</info> already exists. Overwrite?", $input, $output, false)) {
                 return 1;
             }
         }
         $project['alias-group'] = $new_group;
         LocalProject::writeCurrentProjectConfig('alias-group', $new_group, $projectRoot);
         $output->write("Creating Drush aliases in the group <info>@{$new_group}</info>...");
         $environments = $this->getEnvironments($project, true, false);
         $drushHelper->createAliases($project, $projectRoot, $environments);
         $output->writeln(" done");
         $drushDir = $homeDir . '/.drush';
         $oldFile = $drushDir . '/' . $current_group . '.aliases.drushrc.php';
         if (file_exists($oldFile)) {
             if ($questionHelper->confirm("Delete old alias group <info>@{$current_group}</info>?", $input, $output)) {
                 unlink($oldFile);
             }
         }
         // Clear the Drush cache now that the aliases have been updated.
         $drushHelper->clearCache();
         $current_group = $new_group;
     } elseif ($input->getOption('recreate')) {
         $output->write("Recreating Drush aliases...");
         $environments = $this->getEnvironments($project, true, false);
         $drushHelper->createAliases($project, $projectRoot, $environments);
         $drushHelper->clearCache();
         $output->writeln(' done');
     }
     // Don't run expensive drush calls if they are not needed.
     if ($input->getOption('quiet')) {
         return 0;
     }
     $aliases = $drushHelper->getAliases($current_group);
     if ($aliases) {
         $output->writeln("Aliases for <info>{$project['name']}</info> ({$project['id']}):");
         foreach (explode("\n", $aliases) as $alias) {
             $output->writeln('    @' . $alias);
         }
     }
     return 0;
 }
Example #5
0
 /**
  * Build in 'profile' mode: the application contains a site profile.
  *
  * @param string $profileName
  *
  * @throws \Exception
  */
 protected function buildInProfileMode($profileName)
 {
     $drushHelper = new DrushHelper($this->output);
     $drushHelper->ensureInstalled();
     // Find the contrib make file.
     if (file_exists($this->appRoot . '/project.make')) {
         $projectMake = $this->appRoot . '/project.make';
     } elseif (file_exists($this->appRoot . '/drupal-org.make')) {
         $projectMake = $this->appRoot . '/drupal-org.make';
     } else {
         throw new \Exception("Couldn't find a project.make or drupal-org.make in the directory.");
     }
     // Find the core make file.
     if (file_exists($this->appRoot . '/project-core.make')) {
         $projectCoreMake = $this->appRoot . '/project-core.make';
     } elseif (file_exists($this->appRoot . '/drupal-org-core.make')) {
         $projectCoreMake = $this->appRoot . '/drupal-org-core.make';
     } else {
         throw new \Exception("Couldn't find a project-core.make or drupal-org-core.make in the directory.");
     }
     $args = array_merge(array('make', $projectCoreMake, $this->buildDir), $this->drushFlags);
     $drushHelper->execute($args, null, true, false);
     $profileDir = $this->buildDir . '/profiles/' . $profileName;
     mkdir($profileDir, 0755, true);
     $this->output->writeln("Building the profile: <info>{$profileName}</info>");
     $args = array_merge(array('make', '--no-core', '--contrib-destination=.', $projectMake), $this->drushFlags);
     $drushHelper->execute($args, $profileDir, true, false);
     $this->output->writeln("Symlinking existing app files to the profile");
     $this->ignoredFiles[] = basename($projectMake);
     $this->ignoredFiles[] = basename($projectCoreMake);
     $this->ignoredFiles[] = 'settings.local.php';
     $this->specialDestinations['settings*.php'] = '{webroot}/sites/default';
     $this->specialDestinations['sites.php'] = '{webroot}/sites';
     $this->processSettingsPhp();
     // Symlink recursively; skip existing files (built by Drush make) for
     // example 'modules/contrib', but include files from the app such as
     // 'modules/custom'.
     $this->fsHelper->symlinkAll($this->appRoot, $profileDir, true, true, array_merge($this->ignoredFiles, array_keys($this->specialDestinations)));
 }