Skip to content

Commit

Permalink
Merge pull request #994 from pantheon-systems/addition/site_import-co…
Browse files Browse the repository at this point in the history
…ntent_env

Added env param to site import-content
  • Loading branch information
TeslaDethray committed Mar 16, 2016
2 parents c1121cf + 4a53541 commit eb85d00
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ All notable changes to this project starting with the 0.6.0 release will be docu
- New command `ssh-keys list` added. (#990)
- New command `ssh-keys add` added. (#990)
- New command `ssh-keys delete` added. (#990)
- New parameter `--env=<env>` has been added to `site import-content`. (#994)

### Changed
- WP-CLI function `import` has been removed from the command blacklist. [See the documentation for more information.](https://github.com/pantheon-systems/documentation/blob/master/source/docs/guides/create-a-wordpress-site-from-the-commandline-with-terminus-and-wp-cli.md) (#979)
- When running `terminus auth login` and more than one machine token is present, Terminus will now tell you how to use them instead of giving the same error message received when no tokens are present. (#987)
- `SiteCommand#import` has been renamed to `SiteCommand#importContent`. (#994)
- `Site#importDatabase` has been moved to `Environment#importDatabase`. (#994)
- `Site#importFiles` has been moved to `Environment#importFiles`. (#994)

### Fixed
- Fixed unidentified index email warning which appeared when logging in via saved machine token by email. (#983)
- Prevented long loop of configurator loadings. (#988)
- Fixed auth status check before running `CommandWithSSH` descendant commands (`drush`, `wp`). (#986)
- Ensured that API and server errors exit with non-zero status. (#996)
- Fixed error in `site import-content` documentation regarding what is importable. (#994)

## [0.10.6] - 2016-03-07
### Changed
Expand Down
47 changes: 31 additions & 16 deletions php/Terminus/Commands/SiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,48 +918,63 @@ public function hostnames($args, $assoc_args) {
* ## OPTIONS
*
* [--site=<site>]
* : Site to use
* : Site to import content to
*
* [--env=<env>]
* : Name of the environment to import to
*
* [--url=<url>]
* : URL of archive to import
*
* [--element=<element>]
* : Site element to import (i.e. code or database)
* : Site element to import. Options are files or db.
*
* @subcommand import-content
*/
public function import($args, $assoc_args) {
$site = $this->sites->get($this->input()->siteName(array('args' => $assoc_args)));
$url = $this->input()->string(
array(
public function importContent($args, $assoc_args) {
$site = $this->sites->get(
$this->input()->siteName(['args' => $assoc_args,])
);
if (isset($assoc_args['env'])) {
$env_name = $assoc_args['env'];
} else {
$env_name = $this->input()->env(
[
'args' => $assoc_args,
'choices' => array_diff($site->environments->ids(), ['test', 'live',]),
]
);
}
$env = $site->environments->get($env_name);
$url = $this->input()->string(
[
'args' => $assoc_args,
'key' => 'url',
'message' => 'URL of archive to import'
)
'message' => 'URL of archive to import',
]
);
if (!$url) {
$this->log()->error('Please enter a URL.');
}

if (!isset($assoc_args['element'])) {
$element_options = array('database', 'files');
$element_key = $this->input()->menu(
array(
'choices' => $element_options,
$element_key = $this->input()->menu(
[
'choices' => ['db', 'files',],
'message' => 'Which element are you importing?',
)
]
);
$element = $element_options[$element_key];
$element = $element_options[$element_key];
} else {
$element = $assoc_args['element'];
}

switch ($element) {
case 'database':
$workflow = $site->importDatabase($url);
$workflow = $env->importDatabase($url);
break;
case 'files':
$workflow = $site->importFiles($url);
$workflow = $env->importFiles($url);
break;
}
$workflow->wait();
Expand Down
1 change: 0 additions & 1 deletion php/Terminus/Commands/SitesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,3 @@ private function sanitizeName($string) {
}

}

28 changes: 28 additions & 0 deletions php/Terminus/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,34 @@ public function hasDeployableCode() {
return (boolean)$number_of_commits;
}

/**
* Imports a database archive
*
* @param string $url URL to import data from
* @return Workflow
*/
public function importDatabase($url) {
$workflow = $this->site->workflows->create(
'import_database',
['environment' => $this->get('id'), 'params' => compact('url'),]
);
return $workflow;
}

/**
* Imports a file archive
*
* @param string $url URL to import data from
* @return Workflow
*/
public function importFiles($url) {
$workflow = $this->site->workflows->create(
'import_files',
['environment' => $this->get('id'), 'params' => compact('url'),]
);
return $workflow;
}

/**
* Load site info
*
Expand Down
28 changes: 0 additions & 28 deletions php/Terminus/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,34 +464,6 @@ public function import($url) {
return $workflow;
}

/**
* Imports a database archive
*
* @param string $url URL to import data from
* @return Workflow
*/
public function importDatabase($url) {
$workflow = $this->workflows->create(
'import_database',
['environment' => 'dev', 'params' => ['url' => $url,],]
);
return $workflow;
}

/**
* Imports a file archive
*
* @param string $url URL to import data from
* @return Workflow
*/
public function importFiles($url) {
$workflow = $this->workflows->create(
'import_files',
['environment' => 'dev', 'params' => ['url' => $url,],]
);
return $workflow;
}

/**
* Load site info
*
Expand Down
2 changes: 1 addition & 1 deletion tests/features/sites_import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Create a site and import its content
Created new site "[[test_site_name]]"
"""
Then I should get "."
Then I should get:
And I should get:
"""
Importing database/files to "dev"
"""
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures/sites_import_new
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,30 @@
ETag: 'W/"eHUC5tE6/XuFH3Y9bYf6Lw=="'
Vary: Accept-Encoding
body: '{"environment_id": "dev", "params": {"url": "https://s3.amazonaws.com/pantheon-infrastructure/testing/canary.tgz", "files": 1, "code": 1, "updatedb": 1, "database": 1}, "role": "owner", "site_id": "69917fa8-7ca8-413c-a246-8c2f0bbaf673", "started_at": 1442967008.090953, "task_ids": ["72ac63a8-6187-11e5-9286-bc764e1108cd", "72aed82c-6187-11e5-9286-bc764e1108cd", "72b0360e-6187-11e5-9286-bc764e1108cd", "72b14c38-6187-11e5-9286-bc764e1108cd", "72b401ee-6187-11e5-9286-bc764e1108cd", "72b52696-6187-11e5-9286-bc764e1108cd", "72b71f46-6187-11e5-9286-bc764e1108cd", "72bdea88-6187-11e5-9286-bc764e1108cd", "72c365c6-6187-11e5-9286-bc764e1108cd", "72c4ec70-6187-11e5-9286-bc764e1108cd", "72c602e0-6187-11e5-9286-bc764e1108cd", "72c8dac4-6187-11e5-9286-bc764e1108cd", "72daa628-6187-11e5-9286-bc764e1108cd", "72dc5482-6187-11e5-9286-bc764e1108cd", "72dd69e4-6187-11e5-9286-bc764e1108cd"], "trace_id": "729f2620-6187-11e5-8e85-0d70049e9359", "type": "do_import", "user_id": "cbc3d67f-f2b9-44a0-8dd6-8d63265af96e", "id": "72a532cc-6187-11e5-9286-bc764e1108cd", "key": "69917fa8-7ca8-413c-a246-8c2f0bbaf673", "waiting_for_task_id": "72ac63a8-6187-11e5-9286-bc764e1108cd", "keep_forever": false, "phase": "started", "queued_time": null, "run_time": null, "created_at": 1442967007.657646, "reason": "", "environment": "dev", "final_task_id": null, "result": "succeeded", "total_time": null, "active_description": "Importing database/files to \"dev\"", "description": "Import code, files and database to \"dev\"", "step": 1, "number_of_tasks": 15, "trace_log_url": "https://logs.getpantheon.com:443//#/dashboard/file/Trace_Id.json?trace_id=729f2620-6187-11e5-8e85-0d70049e9359&from_iso_date=2015-09-23T00:05:07.657646Z&to_iso_date=now", "user": {"created_at": 1428707345, "password": "SCRUBBED", "user_id": "cbc3d67f-f2b9-44a0-8dd6-8d63265af96e", "email": "[email protected]", "agency_id": null}, "user_email": "[email protected]", "waiting_for_task": {"allow_concurrent": true, "environment": "dev", "fn_name": "queue_jenkins_task", "params": {"host": "23.253.58.250", "task_type": "deploy_dbserver_binding", "job_id": "72ac63a8-6187-11e5-9286-bc764e1108cd", "binding_id": "e5de6f80bcae4612a87350cfa6622075"}, "queued_at": 1442967008.091329, "responses": [{"code": 302, "body": "Successfully queued deploy_dbserver_binding", "error_details": "", "internal_reason": ""}], "site_id": "69917fa8-7ca8-413c-a246-8c2f0bbaf673", "trace_id": "729f2620-6187-11e5-8e85-0d70049e9359", "user_id": "pantheon", "workflow_id": "72a532cc-6187-11e5-9286-bc764e1108cd", "id": "72ac63a8-6187-11e5-9286-bc764e1108cd", "key": "1442966400", "created_at": 1442967007.704772, "queued_time": null, "run_time": null, "phase": "queued", "result": null, "total_time": null, "reason": "", "error_details": "", "internal_reason": "", "trace_log_url": "https://logs.getpantheon.com:443//#/dashboard/file/Trace_Id.json?trace_id=729f2620-6187-11e5-8e85-0d70049e9359&from_iso_date=2015-09-23T00:05:07.704772Z&to_iso_date=now", "type": "deploy_dbserver_binding", "build_url": null, "messages": {"2015-09-23T00:10:09.377106": {"message": "Successfully queued deploy_dbserver_binding", "level": "INFO"}}}}'
-
request:
method: GET
url: 'https://dashboard.pantheon.io/api/sites/69917fa8-7ca8-413c-a246-8c2f0bbaf673/environments'
headers:
Host: dashboard.pantheon.io
Accept: null
User-Agent: 'Terminus/0.8.0 (php_version=5.5.27&script=boot-fs.php)'
Cookie: 'X-Pantheon-Session=cbc3d67f-f2b9-44a0-8dd6-8d63265af96e:60b72cfe-6188-11e5-b16d-bc764e102660:C6hSsDhfvxqd5KtDIabZC'
response:
status:
http_version: '1.1'
code: '200'
message: OK
headers:
Server: nginx
Date: 'Wed, 23 Sep 2015 00:16:50 GMT'
Content-Type: 'application/json; charset=utf-8'
Transfer-Encoding: chunked
Connection: keep-alive
X-Pantheon-Trace-Id: 62f63fa0-6188-11e5-ba41-dd54dc52c0b7
X-Frame-Options: deny
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: 'Origin, Content-Type, Accept'
ETag: 'W/"299-f9e7391c"'
Vary: Accept-Encoding
body: '{"test": {"environment_created": 1442966995, "dns_zone": "pantheon.io", "randseed": "SJM6R4VU4BQIR7GYE3NDXM84CHCIETP3", "lock": {"username": null, "password": null, "locked": false}, "styx_cluster": "styx-03.pantheon.io"}, "dev": {"environment_created": 1442966994, "dns_zone": "pantheon.io", "randseed": "UIOTC4NXTM04GRF205H0321YBYCFAR4I", "lock": {"username": null, "password": null, "locked": false}, "styx_cluster": "styx-01.pantheon.io"}, "live": {"environment_created": 1442966995, "dns_zone": "pantheon.io", "randseed": "23CI7JA2V82BQ0RIXV9HAUETPZPOHD1M", "lock": {"username": null, "password": null, "locked": false}, "styx_cluster": "styx-03.pantheon.io"}}'

0 comments on commit eb85d00

Please sign in to comment.