Skip to content

Commit

Permalink
Fixes Issue #32
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevanwinkle committed Dec 8, 2014
1 parent 9e96e5c commit 7bdd7da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion php/Terminus/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getUpstreamUpdates() {
* @param $optionx boolean (optional) -- auto resolve merge conflicts
* @todo This currently doesn't work and is block upstream
*/
public function applyUpstreamUpdates($env, $updatedb = false, $xoption = false) {
public function applyUpstreamUpdates($env, $updatedb = true, $xoption = 'theirs') {
$data = array('updatedb' => $updatedb, 'xoption' => $xoption );
$options = array( 'body' => json_encode($data) , 'headers'=>array('Content-type'=>'application/json') );
$response = \Terminus_Command::request('sites', $this->getId(), 'code-upstream-updates', 'POST', $options);
Expand Down
30 changes: 19 additions & 11 deletions php/commands/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ public function backup($args, $assoc_args) {
case 'create':
$type='backup';
$path = sprintf('environments/%s/backups/create', $env);
$site_id = $this->getSiteId( $assoc_args['site'] );

$data = array(
'entry_type' => $type,
Expand All @@ -374,7 +373,7 @@ public function backup($args, $assoc_args) {
'body' => json_encode($data) ,
'headers'=> array('Content-type'=>'application/json')
);
$response = \Terminus_Command::request( "sites", $site_id, $path, 'POST', $OPTIONS);
$response = \Terminus_Command::request( "sites", $site->getId(), $path, 'POST', $OPTIONS);

if( @$response['data']->id ) {
$workflow_id = $response['data']->id;
Expand Down Expand Up @@ -432,7 +431,8 @@ public function backup($args, $assoc_args) {
* @subcommand clone-env
*/
public function clone_env($args, $assoc_args) {
$site_id = $this->getSiteId($assoc_args['site']);
$site = SiteFactory::instance($assoc_args['site']);
$site_id = $site->getId();
$from_env = $this->getValidEnv($assoc_args['site'], @$assoc_args['from-env'], "Choose environment you want to clone from");
$to_env = $this->getValidEnv($assoc_args['site'], @$assoc_args['to-env'], "Choose environment you want to clone to");

Expand Down Expand Up @@ -503,7 +503,8 @@ private function cloneObject($to_env, $from_env, $site_id, $object_type) {
public function create_env($args, $assoc_args) {
Terminus::error("Feature currently unavailable. Please create environments in you pantheon dashboard at http://dashboard.getpantheon.com.");
$env = $this->getValidEnv($assoc_args['site'], @$assoc_args['env']);
$site_id = $this->getSiteId($assoc_args['site']);
$site = SiteFactory::instance($assoc_args['site']);
$site_id = $site->getId();
if ($this->envExists($site_id,$env)) {
\Terminus::error("The %s environment already exists", array($env));
}
Expand Down Expand Up @@ -537,7 +538,7 @@ public function create_env($args, $assoc_args) {
*/
public function deploy($args, $assoc_args) {
$env = $this->getValidEnv(@$assoc_args['site'], @$assoc_args['env'], "Select environment to deploy to");

$site = SiteFactory::instance($assoc_args['site']);
$cc = $update = 0;
if (array_key_exists('cc',$assoc_args)) {
$cc = 1;
Expand All @@ -550,7 +551,7 @@ public function deploy($args, $assoc_args) {
'update' => $update,
'cc' => $cc
);
$site_id = $this->getSiteId($assoc_args['site']);
$site_id = $site->getId();
$path = sprintf('environments/%s/code?%s', $env, http_build_query($params));
$response = \Terminus_Command::request('sites', $site_id, $path, 'POST');
$result = $this->waitOnWorkflow('sites', $site_id, $response['data']->id);
Expand Down Expand Up @@ -1027,6 +1028,9 @@ public function upstream_info($args, $assoc_args) {
* [--apply-to=<env>]
* : A flag to apply to a specified environment
*
* [--update]
* : Do update on dev env
*
* @subcommand upstream-updates
*/
public function upstream_updates($args, $assoc_args) {
Expand All @@ -1044,7 +1048,7 @@ public function upstream_updates($args, $assoc_args) {
}

$this->_constructTableForResponse($data, array('Environment','Status') );
if (empty($upstream->update_log)) Terminus::success("No updates to show");
if (!isset($upstream) OR empty(@$upstream->update_log)) Terminus::success("No updates to show");
$upstreams = (array) $upstream->update_log;
if (!empty($upstreams)) {
$data = array();
Expand All @@ -1060,11 +1064,15 @@ public function upstream_updates($args, $assoc_args) {
}
}

if (isset($assoc_args['apply-to'])) {
$env = $this->getValidEnv($site->getName(),$assoc_args['apply-to']);
Terminus::confirm(sprintf("Are you sure you want to apply the upstream updates to %s:%s", $site->getName(), $env));
if (isset($assoc_args['update']) AND !empty(@$upstream->update_log)) {
$env = 'dev';
Terminus::confirm(sprintf("Are you sure you want to apply the upstream updates to %s-dev", $site->getName(), $env));
$response = $site->applyUpstreamUpdates($env);
$this->waitOnWorkflow('sites', $site->getId(), $response->id);
if (@$response->id) {
$this->waitOnWorkflow('sites', $site->getId(), $response->id);
} else {
Terminus::success("Updates applied");
}
}

}
Expand Down

0 comments on commit 7bdd7da

Please sign in to comment.