示例#1
0
文件: sites.php 项目: slivermon/cli
 /**
  * List Sites in Cache
  *
  * ## OPTIONS
  *
  * [--rebuild]
  * @subcommand cache
  */
 public function cache($args, $assoc_args)
 {
     $sites_cache = new Terminus\SitesCache();
     if (isset($assoc_args['rebuild'])) {
         $sites_cache->rebuild();
     }
     $sites = $sites_cache->all();
     $data = array();
     foreach ($sites as $name => $id) {
         $data[] = array('name' => $name, 'id' => $id);
     }
     $this->handleDisplay($data, $args);
 }
示例#2
0
文件: Site.php 项目: slivermon/cli
 public static function createFromName($sitename)
 {
     $sites_cache = new SitesCache();
     $site_id = $sites_cache->find($sitename);
     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');
     }
 }
示例#3
0
文件: site.php 项目: spleshka/cli
 /**
  * Retrieve information about the site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : name of the site to work with
  *
  * [--field=<field>]
  * : field to return
  *
  * ## EXAMPLES
  *
  */
 public function info($args, $assoc_args)
 {
     $sitename = Input::site($assoc_args);
     $site_id = SitesCache::find($sitename);
     $site = new Site($site_id);
     $site->fetch();
     # Fetch environment data for sftp/git connection info
     $site->environmentsCollection->fetch();
     if (isset($assoc_args['field'])) {
         $field = $assoc_args['field'];
         Terminus::line($site->info($field));
     } else {
         $this->handleDisplay($site->info(), $args);
     }
 }
示例#4
0
 /**
  * Searches the SitesCache for an ID given a name
  *
  */
 static function find($name, $options = array())
 {
     $instance = new SitesCache();
     return $instance->_find($name, $options);
 }
示例#5
0
 /**
  * Create a new site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Name of the site to create (machine-readable)
  *
  * [--name=<name>]
  * : (deprecated) use --site instead
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--product=<productid>]
  * : Specify the upstream product to use
  *
  * [--import=<url>]
  * : A url to import a valid archive
  *
  * [--org=<org>]
  * : UUID of organization into which to add this site
  *
  */
 public function create($args, $assoc_args)
 {
     $options = array();
     $options['label'] = Input::string($assoc_args, 'label', "Human readable label for the site");
     $suggested_name = Utils\sanitize_name($options['label']);
     if (array_key_exists('name', $assoc_args)) {
         // Deprecated but kept for backwards compatibility
         $options['name'] = $assoc_args['name'];
     } elseif (array_key_exists('site', $assoc_args)) {
         $options['name'] = $assoc_args['site'];
     } else {
         $options['name'] = Input::string($assoc_args, 'site', "Machine name of the site; used as part of the default URL (if left blank will be {$suggested_name})", $suggested_name);
     }
     if ($org_id = Input::orgid($assoc_args, 'org', false)) {
         $options['organization_id'] = $org_id;
     }
     if (!isset($assoc_args['import'])) {
         $product = Input::product($assoc_args, 'product');
         $options['product_id'] = $product['id'];
         Terminus::line(sprintf("Creating new %s installation ... ", $product['longname']));
     }
     $workflow = Site::create($options);
     $workflow->wait();
     Terminus::success("Pow! You created a new site!");
     // Add Site to SitesCache
     $site_id = $workflow->attributes->final_task->site_id;
     $site = new Site($site_id);
     $site->fetch();
     $cache_membership = array('id' => $site_id, 'name' => $options['name'], 'service_level' => $site->attributes->service_level, 'framework' => $site->attributes->framework);
     if ($org_id) {
         $org = new Organization($org_id);
         $cache_membership['membership'] = array('id' => $org_id, 'name' => $org->profile->name, 'type' => 'organization');
     } else {
         $user_id = Session::getValue('user_uuid');
         $cache_membership['membership'] = array('id' => $user_id, 'name' => 'Team', 'type' => 'team');
     }
     $sites_cache = new Terminus\SitesCache();
     $sites_cache->add($cache_membership);
     if (isset($assoc_args['import'])) {
         sleep(10);
         //To stop erroenous site-DNE errors
         Terminus::launch_self('site', array('import'), array('url' => $assoc_args['import'], 'site' => $options['name'], 'element' => 'all'));
     } else {
         Terminus::launch_self('site', array('info'), array('site' => $options['name']));
     }
     return true;
 }
示例#6
0
文件: Sites.php 项目: serundeputy/cli
 /**
  * Clears sites cache
  *
  * @return void
  */
 public function rebuildCache()
 {
     $this->sites_cache->rebuild();
 }
示例#7
0
 /**
  * Input helper that provides interactive site list
  *
  * @param [array]  $args  The args passed in from argv
  * @param [string] $key   Args key to search for
  * @param [string] $label Prompt for STDOUT
  * @return [string] Site name
  */
 public static function sitename($args = array(), $key = 'site', $label = 'Choose site')
 {
     // return early if sitename is provided in args
     if (isset($args[$key])) {
         return $args[$key];
     }
     if (isset($_SERVER['TERMINUS_SITE'])) {
         return $_SERVER['TERMINUS_SITE'];
     }
     $sitesCache = new SitesCache();
     $sitenames = array_map(function ($site_cache) {
         return $site_cache['name'];
     }, $sitesCache->all());
     $choices = array();
     foreach ($sitenames as $sitename) {
         $choices[$sitename] = $sitename;
     }
     $menu = self::menu($choices, $default = null, $label);
     return $menu;
 }
示例#8
0
文件: sites.php 项目: spleshka/cli
 /**
  * Create a new site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Name of the site to create (machine-readable)
  *
  * [--name=<name>]
  * : (deprecated) use --site instead
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--product=<productid>]
  * : Specify the upstream product to use
  *
  * [--import=<url>]
  * : A url to import a valid archive
  *
  * [--org=<org>]
  * : UUID of organization into which to add this site
  *
  */
 public function create($args, $assoc_args)
 {
     $options = array();
     $options['label'] = Input::string($assoc_args, 'label', "Human readable label for the site");
     $suggested_name = Utils\sanitize_name($options['label']);
     if (array_key_exists('name', $assoc_args)) {
         // Deprecated but kept for backwards compatibility
         $options['name'] = $assoc_args['name'];
     } elseif (array_key_exists('site', $assoc_args)) {
         $options['name'] = $assoc_args['site'];
     } else {
         $options['name'] = Input::string($assoc_args, 'site', "Machine name of the site; used as part of the default URL (if left blank will be {$suggested_name})", $suggested_name);
     }
     if ($org_id = Input::orgid($assoc_args, 'org', false)) {
         $options['organization_id'] = $org_id;
     }
     if (!isset($assoc_args['import'])) {
         $product = Input::product($assoc_args, 'product');
         $options['product_id'] = $product['id'];
         Terminus::line(sprintf("Creating new %s installation ... ", $product['longname']));
     }
     $workflow = Site::create($options);
     $workflow->wait();
     Terminus::success("Pow! You created a new site!");
     // Add Name->ID mapping to SitesCache
     $site_id = $workflow->status()->final_task->site_id;
     $sites_cache = new Terminus\SitesCache();
     $sites_cache->add(array($options['name'] => $site_id));
     if (isset($assoc_args['import'])) {
         sleep(10);
         //To stop erroenous site-DNE errors
         Terminus::launch_self('site', array('import'), array('url' => $assoc_args['import'], 'site' => $options['name'], 'element' => 'all'));
     } else {
         Terminus::launch_self('site', array('info'), array('site' => $options['name']));
     }
     return true;
 }