Skip to content

Commit b5d713d

Browse files
committed
Refactor clone to use workflows. resolves #173
1 parent f2369e4 commit b5d713d

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

php/Terminus/Site.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,10 @@ public function bindings($type=null) {
6262
* Return all environments for a site
6363
*/
6464
public function environments() {
65-
$cache = \Terminus::get_cache();
66-
if (empty($this->environments)) {
67-
if (!$environments = $cache->get_data("environments:{$this->id}")) {
68-
$results = \Terminus_Command::request("sites", $this->getId(), "environments", "GET");
69-
$environments = $results['data'];
70-
$cache->put_data("environments:{$this->id}",$environments);
71-
}
72-
$this->environments = $environments;
73-
}
74-
65+
$results = \Terminus_Command::request("sites", $this->getId(), "environments", "GET");
66+
$environments = $results['data'];
67+
$this->environments = $environments;
68+
7569
// instantiate local objects
7670
foreach ( $this->environments as $name => $env) {
7771
$this->environments->$name = EnvironmentFactory::load($this, $name, array(
@@ -92,8 +86,12 @@ public function environment($environment) {
9286
} else {
9387
// load the environments
9488
$this->environments();
89+
if (array_key_exists($environment,$this->environments)) {
90+
return $this->environments->$environment;
91+
} else {
92+
throw new \Terminus\Iterators\Exception("No such environment $environment.");
93+
}
9594
}
96-
return $this->environments->$environment;
9795
}
9896

9997
/**

php/commands/site.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use \Terminus\Helpers\Input;
1414
use \Terminus\Deploy;
1515
use \Terminus\SiteWorkflow;
16+
use \Terminus\EnvironmentWorkflow;
1617

1718
class Site_Command extends Terminus_Command {
1819

@@ -563,20 +564,25 @@ public function clone_env($args, $assoc_args) {
563564

564565
$confirm = sprintf("Are you sure?\n\tClone from %s to %s\n\tInclude: %s\n", strtoupper($from_env), strtoupper($to_env), $append);
565566
\Terminus::confirm($confirm);
566-
567-
if ( !$this->envExists($site_id, $to_env) ) {
568-
\Terminus::error("The %s environment has not been created yet. run `terminus site create-env [--site=<env>]`", $to_env);
569-
}
567+
$to_env = $site->environment($to_env);
568+
$from_env = $site->environment($from_env);
570569

571570
if ($db) {
572-
print "Cloning database ... ";
573-
$this->cloneObject( $to_env, $from_env, $site_id, 'database');
571+
print "Cloning database ... ";
572+
$workflow = new EnvironmentWorkflow('clone_database','sites', $to_env);
573+
$workflow->setParams(array('from_environment' => $from_env->name));
574+
$workflow->setMethod('POST');
575+
$workflow->start()->wait();;
574576
}
575577

576578
if ($files) {
577579
print "Cloning files ... ";
578-
$this->cloneObject( $to_env, $from_env, $site_id, 'files');
580+
$workflow = new EnvironmentWorkflow('clone_files','sites', $to_env);
581+
$workflow->setParams(array('from_environment' => $from_env->name));
582+
$workflow->setMethod('POST');
583+
$workflow->start()->wait();
579584
}
585+
580586
\Terminus::success("Clone complete!");
581587
return true;
582588
}
@@ -741,12 +747,6 @@ function environments($args, $assoc_args) {
741747
return $data;
742748
}
743749

744-
private function envExists($site_id, $env) {
745-
$response = \Terminus_Command::request('sites', $site_id, 'code-tips', 'GET');
746-
$envs = (array) $response['data'];
747-
return array_key_exists($env, $envs);
748-
}
749-
750750
/**
751751
* Hostname operations
752752
*

php/terminus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
// Can be used by plugins/themes to check if Terminus is running or not
33
define( 'Terminus', true );
4-
define( 'TERMINUS_VERSION', '0.5.4');
4+
define( 'TERMINUS_VERSION', '0.5.5');
55
$source = 'unknown';
66
if ('cli' === PHP_SAPI && isset($argv)) {
77
$source = explode('/',$argv[0]);

0 commit comments

Comments
 (0)