Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Commands/core/RsyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ protected function injectAliasPathParameterOptions($input, $parameterName)
$evaluatedPath = HostPath::create($manager, $aliasName);
$this->pathEvaluator->evaluate($evaluatedPath);

$aliasRecord = $evaluatedPath->getAliasRecord();

// Inject the source and target alias records into the alias config context.
$evaluatedPath->getAliasRecord()->injectIntoConfig($aliasConfigContext, $parameterName);
$aliasRecord->injectIntoConfig($aliasConfigContext, $parameterName);

// If the path is remote, then we will also inject the global
// options into the alias config context so that we pick up
// things like ssh-options.
if ($aliasRecord->isRemote()) {
$aliasConfigContext->combine($aliasRecord->export());
}

return $evaluatedPath;
}
Expand Down
12 changes: 7 additions & 5 deletions src/SiteAlias/AliasRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,11 @@ protected function remap($data)
public function injectIntoConfig($config, $parameterName = '')
{
$aliasData = $this->export();
$aliasOptions = $aliasData;
unset($aliasOptions['alias-parameters']);
$parameterSpecificData = $this->getParameterSpecificOptions($aliasData, $parameterName);
if (!empty($parameterSpecificData)) {
$aliasOptions = ArrayUtil::mergeRecursiveDistinct($aliasOptions, $parameterSpecificData);
// Combine the data from the parameter-specific
$config->combine($parameterSpecificData);
}
// Combine the data from the parameter-specific
$config->combine($aliasOptions);
return $this;
}

Expand All @@ -298,9 +295,14 @@ protected function getParameterSpecificOptions($aliasData, $parameterName)
public function legacyRecord()
{
$result = $this->exportConfig()->get('options', []);

// Backend invoke needs a couple of critical items in specific locations.
if ($this->has('paths.drush-script')) {
$result['path-aliases']['%drush-script'] = $this->get('paths.drush-script');
}
if ($this->has('ssh.options')) {
$result['ssh-options'] = $this->get('ssh.options');
}
return $result;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/resources/alias-fixtures/example.alias.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ live:
host: service-provider.com
root: /path/on/service-provider
uri: https://example.com
ssh:
options: '-o PasswordAuthentication=example'
paths:
drush-script: '/example/path/to/drush'
5 changes: 5 additions & 0 deletions tests/rsyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public function testSimulated() {
$expected = "Calling system(rsync -e 'ssh ' -akz --include=\"dev-source\" --exclude=\"stage-target\" /path/to/dev/files /path/to/stage/files);";
$this->assertOutputEquals($expected);

// Test simulated rsync on local machine with a remote target
$this->drush('rsync', ['@example.dev:files', '@example.live:files'], $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1');
$expected = "Calling system(rsync -e 'ssh -o PasswordAuthentication=example' -akz --include=\"dev-source\" /path/to/dev/files [email protected]:/path/on/service-provider/files);";
$this->assertOutputEquals($expected);

// Test simulated backend invoke.
// Note that command-specific options are not processed for remote
// targets. The aliases are not interpreted at all until they recach
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testSimulatedSqlSync() {
// injection will be done.
$this->drush('sql:sync', ['@synctest.remote', '@synctest.local'], $options, 'user@server/path/to/drupal#sitename', NULL, self::EXIT_SUCCESS, '2>&1');
$output = $this->getSimplifiedOutput();
$this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=whatever user@server '/path/to/drush --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=/path/to/drupal --uri=sitename --no-ansi sql:sync '\''@synctest.remote'\'' '\''@synctest.local'\''", $output);
$this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=no user@server 'drush --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=/path/to/drupal --uri=sitename --no-ansi sql:sync '\''@synctest.remote'\'' '\''@synctest.local'\''", $output);
}

/**
Expand Down