Skip to content

Commit

Permalink
Merge pull request #299 from pantheon-systems/sitescache_rev
Browse files Browse the repository at this point in the history
Move SitesCache invocation out of Site model
  • Loading branch information
bensheldon committed Jul 29, 2015
2 parents 645b972 + b33f7e9 commit 844a2b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
18 changes: 6 additions & 12 deletions php/Terminus/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Terminus\Request;
use Terminus\Deploy;
use \Terminus\SiteWorkflow;
use Terminus\SitesCache;
use \Terminus_Command;
use Terminus\Environments;

Expand Down Expand Up @@ -51,18 +50,13 @@ public function __construct($attributes) {
return $this;
}

public static function createFromName($sitename) {
$sites_cache = new SitesCache();
$site_id = $sites_cache->find($sitename);
public function fetch() {
$response = Terminus_Command::simple_request(sprintf('sites/%s?site_state=true', $this->id));
$this->attributes = $response['data'];
# backwards compatibility
$this->information = $this->attributes;

if ($site_id) {
$response = Terminus_Command::simple_request('sites/' . $site_id . '?site_state=true');
$site_data = $response['data'];
$site = new Site($site_data);
return $site;
} else {
throw new \Exception('We cannot access a site with this name');
}
return $this;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions php/Terminus/SitesCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ class SitesCache {
protected $cache;
protected $cachekey = 'sites';

/**
* Searches the SitesCache for an ID given a name
*
*/
static function find($name, $options = array()) {
$instance = new SitesCache();
return $instance->_find($name, $options);
}

public function __construct() {
$this->cache = Terminus::get_cache();
}

// Returns the UUID of the site
public function find($name, $options = array()) {
private function _find($name, $options = array()) {
if (!isset($options['rebuild'])) {
$options['rebuild'] = true;
}
Expand Down
7 changes: 6 additions & 1 deletion php/commands/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use \Terminus\Helpers\Input;
use \Terminus\Deploy;
use \Terminus\SiteWorkflow;
use Terminus\SitesCache;


class Site_Command extends Terminus_Command {

Expand Down Expand Up @@ -288,7 +290,10 @@ public function dashboard($args, $assoc_args) {
*/
public function info($args, $assoc_args) {
$sitename = Input::site($assoc_args);
$site = Site::createFromName($sitename);
$site_id = SitesCache::find($sitename);
$site = new Site($site_id);

$site->fetch();

# Fetch environment data for sftp/git connection info
$site->environmentsCollection->fetch();
Expand Down

0 comments on commit 844a2b9

Please sign in to comment.