From ef052a013205a5e789b9ad45fb200d549af3f91d Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Thu, 26 Oct 2017 15:28:49 -0700 Subject: [PATCH] Fixes #3046: Use correct target alias record when importing the sql database in sql:sync. (#3106) --- src/Commands/sql/SqlSyncCommands.php | 2 +- tests/sqlSyncTest.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Commands/sql/SqlSyncCommands.php b/src/Commands/sql/SqlSyncCommands.php index 40d7cc9b46..d8233d6eaf 100644 --- a/src/Commands/sql/SqlSyncCommands.php +++ b/src/Commands/sql/SqlSyncCommands.php @@ -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.'); } diff --git a/tests/sqlSyncTest.php b/tests/sqlSyncTest.php index 9de285b36f..1948af9bb5 100644 --- a/tests/sqlSyncTest.php +++ b/tests/sqlSyncTest.php @@ -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 www-admin@server.isp.simulated '/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 www-admin@server.isp.simulated '/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);