Skip to content

Commit 41f1bdc

Browse files
committed
Merge pull request #616 from pantheon-systems/fix_set-connection-mode_error
Invalid connection mode from API no longer inhibits connection type setting
2 parents f7f6674 + d8dda41 commit 41f1bdc

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu
1414
- `site create-env` no longer fails to clone from an environment. (#602)
1515
- `site backups list` filtering by element fixed. (#602)
1616
- Four SSH-based commands now return with unavailable errors: `wp import`, `wp db`, `drush sql-connect`, and `drush sql-sync`. (#607)
17+
- Failure of the API to return a connection mode no longer inhibits its setting. (#616)
1718
- When trying to access an invalid collection member, Terminus now exits instead of having a fatal error. (#615)
1819

1920
### Changed

php/Terminus/Models/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ public function info($key = null) {
814814
if (isset($info[$key])) {
815815
return $info[$key];
816816
} else {
817-
throw new TerminusException('There is no such field.', array(), -1);
817+
throw new TerminusException('There is no such field.', array(), 1);
818818
}
819819
} else {
820820
return $info;

php/commands/site.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Terminus\Utils;
44
use Terminus\Helpers\Input;
5+
use Terminus\Exceptions\TerminusException;
56
use Terminus\Models\User;
67
use Terminus\Models\Collections\Sites;
78

@@ -161,15 +162,22 @@ public function set_connection_mode($args, $assoc_args) {
161162
if (in_array($env->get('id'), array('test', 'live'))) {
162163
$this->failure('Connection mode cannot be set in Test or Live environments');
163164
}
164-
if ($mode == $env->info('connection_mode')) {
165-
$this->failure(
166-
'The connection mode on {site} for {env} is already set to {mode}.',
167-
array(
168-
'site' => $site->get('name'),
169-
'env' => $env->get('id'),
170-
'mode' => $mode
171-
),
172-
-1
165+
try {
166+
$current_mode = $env->info('connection_mode');
167+
if ($current_mode == $env->info('connection_mode')) {
168+
$this->failure(
169+
'The connection mode on {site} for {env} is already set to {mode}.',
170+
array(
171+
'site' => $site->get('name'),
172+
'env' => $env->get('id'),
173+
'mode' => $mode
174+
),
175+
-1
176+
);
177+
}
178+
} catch (TerminusException $e) {
179+
$this->log()->info(
180+
'Current connection info not available. Proceeding with mode change.'
173181
);
174182
}
175183
$workflow = $env->changeConnectionMode($mode);

tests/features/site_connection-mode.feature renamed to tests/features/site_set-connection-mode.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Site set connection mode
22

33
Scenario: Setting connection mode to git
4-
@vcr site_connection-mode_git
4+
@vcr site_set-connection-mode_git
55
Given I am authenticated
66
And a site named "[[test_site_name]]"
77
When I run "terminus site set-connection-mode --site=[[test_site_name]] --env=dev --mode=git"
@@ -12,7 +12,7 @@ Feature: Site set connection mode
1212
"""
1313

1414
Scenario: Setting connection mode to sftp
15-
@vcr site_connection-mode_sftp
15+
@vcr site_set-connection-mode_sftp
1616
Given I am authenticated
1717
And a site named "[[test_site_name]]"
1818
When I run "terminus site set-connection-mode --site=[[test_site_name]] --env=dev --mode=sftp"
@@ -23,7 +23,7 @@ Feature: Site set connection mode
2323
"""
2424

2525
Scenario: Failing to set connection mode to invalid mode
26-
@vcr site_connection-mode_git
26+
@vcr site_set-connection-mode_git
2727
Given I am authenticated
2828
And a site named "[[test_site_name]]"
2929
When I run "terminus site set-connection-mode --site=[[test_site_name]] --env=dev --mode=invalid"
@@ -34,11 +34,11 @@ Feature: Site set connection mode
3434
"""
3535

3636
Scenario: Failing to set the connection mode to the current mode
37-
@vcr site_connection-mode_git
37+
@vcr site_set-connection-mode_git
3838
Given I am authenticated
3939
And a site named "[[test_site_name]]"
4040
When I run "terminus site set-connection-mode --site=[[test_site_name]] --env=dev --mode=sftp"
4141
Then I should get:
4242
"""
43-
The connection mode on [[test_site_name]] for dev is already set to sftp.
43+
The connection mode is already set to sftp.
4444
"""
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)