Skip to content

Commit

Permalink
Merge pull request #170 from pantheon-systems/wipe
Browse files Browse the repository at this point in the history
Add Environment Wipe Command
  • Loading branch information
Josh Koenig committed Sep 6, 2014
2 parents 881add3 + ee6e2fe commit 792ee9e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ Updates can be performed in the directory:
drush psite-create $SITE_NAME --label="$SITE_DESC" --product=21e1fada-199c-492b-97bd-0b36b53a9da0
# Update your aliases.
drush paliases
# Determine the site_uuid of the newly created site.
SITE_UUID=$(drush psite-uuid $SITE_NAME)
# Determine the site_uuid of the newly created site and save as variable SITE_UUID.
SITE_UUID=`drush psite-uuid $SITE_NAME | cut -f2 -d' '`
# Change the connection mode of the dev environment to SFTP.
drush psite-cmode $SITE_UUID dev sftp
# Use a public URL as the source for drush_make to download a few modules.
Expand Down
58 changes: 58 additions & 0 deletions terminus.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,19 @@ function terminus_drush_command() {
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);

$items['pantheon-site-environment-content-wipe'] = array(
'description' => 'Wipe the content from a particular environment.',
'arguments' => array(
'site' => 'UUID of the site.',
'environment' => 'The target environment (e.g. "live") to which code will be deployed.',
),
'examples' => array(
'drush psite-ewipe SITE_UUID dev' => 'Wipe the database and files from the dev environment.',
),
'aliases' => array('psite-ewipe'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);

/**
* Utility Functions.
*/
Expand Down Expand Up @@ -1175,6 +1188,51 @@ function drush_terminus_pantheon_site_deploy($site_uuid = '', $env_target = '')
terminus_api_environment_deploy_code($site_uuid, $env_target, $updatedb, $clearcache);
}

/**
* Validate Pantheon site environment content wipe.
*/
function drush_terminus_pantheon_site_environment_content_wipe_validate($site_uuid = FALSE, $environment = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_EWIPE_NO_SESSION', dt('You must authenticate before using this command.'));
}

if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_EWIPE_INVALID_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);

if (!terminus_validate_environment($environment)) {
if (!$environment = terminus_session_select_data('environment', $site_uuid)) {
return drush_set_error('DRUSH_PSITE_EWIPE_INVALID_ENV', dt('You must specify a valid environment name.'));
}
}

drush_set_option('environment', $environment);
$result = terminus_api_site_info($site_uuid, $environment);

if (!$result) {
return drush_set_error('DRUSH_PSITE_EWIPE_INFO_REQFAIL', dt('Unable to get wipe information.'));
}
}

/**
* Wipe a site environment.
*/
function drush_terminus_pantheon_site_environment_content_wipe($site_uuid = FALSE, $environment = FALSE, $username = FALSE, $password = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$environment = drush_get_option('environment');

$result = terminus_api_environment_content_wipe($site_uuid, $environment);
if (!$result) {
return drush_set_error('DRUSH_PSITE_WIPE_REQFAIL', dt('Unable to wipe.'));
}
drush_log(dt('@site_name @environment is now wiped.', array(
'@site_name' => terminus_pantheon_site_name($site_uuid),
'@environment' => $environment,
)), 'ok');
}

/**
* Validate Pantheon site content clone.
*/
Expand Down

0 comments on commit 792ee9e

Please sign in to comment.