From 7bdd7da22dbfb23841173736821f724570ccc078 Mon Sep 17 00:00:00 2001 From: Mike Van Winkle Date: Mon, 8 Dec 2014 20:27:34 +0000 Subject: [PATCH] Fixes Issue #32 --- php/Terminus/Site.php | 2 +- php/commands/site.php | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/php/Terminus/Site.php b/php/Terminus/Site.php index 200bcb0f2..2b72c0d7a 100755 --- a/php/Terminus/Site.php +++ b/php/Terminus/Site.php @@ -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); diff --git a/php/commands/site.php b/php/commands/site.php index d449e0cc4..c55abeeb5 100755 --- a/php/commands/site.php +++ b/php/commands/site.php @@ -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, @@ -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; @@ -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"); @@ -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)); } @@ -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; @@ -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); @@ -1027,6 +1028,9 @@ public function upstream_info($args, $assoc_args) { * [--apply-to=] * : A flag to apply to a specified environment * + * [--update] + * : Do update on dev env + * * @subcommand upstream-updates */ public function upstream_updates($args, $assoc_args) { @@ -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(); @@ -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"); + } } }