Skip to content

Commit

Permalink
Fixes #3046: Use correct target alias record when importing the sql d…
Browse files Browse the repository at this point in the history
…atabase in sql:sync. (#3106)
  • Loading branch information
greg-1-anderson authored Oct 26, 2017
1 parent db093f0 commit ef052a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Commands/sql/SqlSyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function sqlsync($source, $target, $options = ['no-dump' => false, 'no-sy
'file' => $target_dump_path,
'file-delete' => true,
);
$return = drush_invoke_process($target, 'sql-query', array(), $query_options, $backend_options);
$return = drush_invoke_process($targetRecord, 'sql-query', array(), $query_options, $backend_options);
if ($return['error_status']) {
throw new Exception('Failed to rsync the database dump from source to target.');
}
Expand Down
19 changes: 13 additions & 6 deletions tests/sqlSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ public function testSimulatedSqlSync() {
'alias-path' => __DIR__ . '/resources/alias-fixtures',
];

// Test simulated simple rsync with two local sites
// Test simulated simple rsync remote-to-local
$this->drush('sql:sync', ['@synctest.remote', '@synctest.local'], $options, '@synctest.local', NULL, self::EXIT_SUCCESS, '2>&1');
$output = $this->getSimplifiedOutput();
$this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=whatever [email protected] '/path/to/drush --backend=2 --strict=0 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=remote sql-dump --no-ansi --gzip --result-file", $output);
$this->assertContains("Simulating backend invoke: __SUT__/vendor/drush/drush/drush --backend=2 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=local core-rsync '@synctest.remote:/simulated/path/to/dump.tgz' '@synctest.local:__SANDBOX__/drush-tmp/dump.tgz' -- --remove-source-files", $output);
$this->assertContains("Simulating backend invoke: __SUT__/vendor/drush/drush/drush --backend=2 --strict=0 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=local sql-query --no-ansi --file=__SANDBOX__/drush-tmp/dump.tgz --file-delete", $output);

// 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
// the remote side, at which point they will be evaluated & any needed
// injection will be done.
// Test simulated simple rsync local-to-remote
$this->drush('sql:sync', ['@synctest.local', '@synctest.remote'], $options, '@synctest.local', NULL, self::EXIT_SUCCESS, '2>&1');
$output = $this->getSimplifiedOutput();
$this->assertContains("Simulating backend invoke: __SUT__/vendor/drush/drush/drush --backend=2 --strict=0 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=local sql-dump --no-ansi --gzip --result-file", $output);
$this->assertContains("Simulating backend invoke: __SUT__/vendor/drush/drush/drush --backend=2 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=local core-rsync '@synctest.local:/simulated/path/to/dump.tgz' '@synctest.remote:/tmp/dump.tgz' -- --remove-source-files", $output);
$this->assertContains("Simulating backend invoke: ssh -o PasswordAuthentication=whatever [email protected] '/path/to/drush --backend=2 --strict=0 --alias-path=__DIR__/resources/alias-fixtures:__SANDBOX__/etc/drush --root=__SUT__/web --uri=remote sql-query --no-ansi --file=/tmp/dump.tgz --file-delete", $output);


// Test simulated backend invoke with a remote runner.
// Note that the target aliases are not interpreted at all until they recach
// the remote side. Injection for alias parameters is currently only done when
// they are used with drush_invoke_process.
$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=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

0 comments on commit ef052a0

Please sign in to comment.