Beispiel #1
0
 /**
  * Create a new site
  *
  * ## OPTIONS
  *
  * [--product=<productid>]
  * : Specify the product to create
  *
  * [--name=<name>]
  * : (deprecated) use --site instead
  *
  * [--site=<site>]
  * : Name of the site to create (machine-readable)
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--org=<org>]
  * : UUID of organization to add this site to; or "None"
  *
  * [--import=<url>]
  * : A url to import a valid archive from
  */
 public function create($args, $assoc_args)
 {
     $sites = SiteFactory::instance();
     // setup data
     $data = array();
     $data['label'] = Input::string($assoc_args, 'label', "Human readable label for the site");
     $slug = Utils\sanitize_name($data['label']);
     // this ugly logic is temporarily if to handle the deprecated --name flag and preserve backward compatibility. it can be removed in the next major release.
     if (array_key_exists('name', $assoc_args)) {
         $data['site_name'] = $assoc_args['name'];
     } elseif (array_key_exists('site', $assoc_args)) {
         $data['site_name'] = $assoc_args['site'];
     } else {
         $data['site_name'] = Input::string($assoc_args, 'site', "Machine name of the site; used as part of the default URL [ if left blank will be {$slug}]", $slug);
     }
     if ($orgid = Input::orgid($assoc_args, 'org', false)) {
         $data['organization_id'] = $orgid;
     }
     if (!isset($assoc_args['import'])) {
         $product = Input::product($assoc_args, 'product');
         $data['deploy_product'] = array('product_id' => $product['id']);
         Terminus::line(sprintf("Creating new %s installation ... ", $product['longname']));
     }
     $params = array('body' => json_encode($data), 'headers' => array('Content-type' => 'application/json'));
     // run the workflow
     $workflow = Workflow::createWorkflow('create_site', 'users', new User());
     $workflow->setMethod('POST');
     $workflow->setParams($data);
     $workflow->start();
     $workflow->refresh();
     $details = $workflow->status();
     $site_id = $details->final_task->site_id;
     if ($details->result !== 'failed' and $details->result !== 'aborted') {
         Terminus\Loggers\Regular::coloredOutput('%G' . vsprintf('New "site" %s now building with "UUID" %s', array($data['site_name'], $site_id)));
     }
     $workflow->wait();
     Terminus::success("Pow! You created a new site!");
     $this->cache->flush(null, 'session');
     if (isset($assoc_args['import'])) {
         Terminus::launch_self('site', array('import'), array('url' => $assoc_args['import'], 'site' => $data['site_name'], 'element' => 'all', 'nocache' => True));
     }
     return true;
 }
Beispiel #2
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;
 }
Beispiel #3
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
  *
  * [--upstream=<upstreamid>]
  * : Specify the upstream upstream to use
  *
  * [--import=<url>]
  * : A url to import a valid archive
  *
  * [--org=<id>]
  * : 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'];
     } elseif (isset($_SERVER['TERMINUS_SITE'])) {
         $options['name'] = $_SERVER['TERMINUS_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 (isset($assoc_args['org'])) {
         $options['organization_id'] = Input::orgid($assoc_args, 'org', false);
     }
     if (!isset($assoc_args['import'])) {
         $upstream = Input::upstream($assoc_args, 'upstream');
         $options['upstream_id'] = $upstream->get('id');
         Terminus::line(sprintf("Creating new %s installation ... ", $upstream->get('longname')));
     }
     $workflow = $this->sites->addSite($options);
     $workflow->wait();
     $this->workflowOutput($workflow);
     // Add Site to SitesCache
     $final_task = $workflow->get('final_task');
     $this->sites->addSiteToCache($final_task->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;
 }
Beispiel #4
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 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;
 }
Beispiel #5
0
 /**
  * Import a new site
  * @package 2.0
  *
  * ## OPTIONS
  *
  * [--url=<url>]
  * : Url of archive to import
  *
  * [--name=<name>]
  * : Name of the site to create (machine-readable)
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--org=<org>]
  * : UUID of organization to add this site to
  *
  * @subcommand create-from-import
  */
 public function import($args, $assoc_args)
 {
     $url = Input::string($assoc_args, 'url', "Url of archive to import");
     $label = Input::string($assoc_args, 'label', "Human readable label for the site");
     $slug = Utils\sanitize_name($label);
     $name = Input::string($assoc_args, 'name', "Machine name of the site; used as part of the default URL [ if left blank will be {$slug}]");
     $name = $name ? $name : $slug;
     $organization = Terminus::menu(Input::orglist(), false, "Choose organization");
     if (!$url) {
         Terminus::error("Please enter a url.");
     }
     Terminus::launch_self('sites', array('create'), array('label' => $label, 'name' => $name, 'org' => $organization));
     Terminus::launch_self('site', array('import'), array('url' => $url, 'site' => $name, 'nocache' => True));
 }
Beispiel #6
0
 /**
  * A helper function for getting/prompting for the site create options.
  *
  * @param array $assoc_args
  * @return array
  */
 private static function getSiteCreateOptions($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'];
     } elseif (isset($_SERVER['TERMINUS_SITE'])) {
         $options['name'] = $_SERVER['TERMINUS_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 (isset($assoc_args['org'])) {
         $options['organization_id'] = Input::orgid($assoc_args, 'org', false);
     }
     return $options;
 }