/**
  * Retrieves the model of the given ID
  *
  * @param [string] $id ID or name of desired organization
  * @return [UserOrganizationMembership] $model
  */
 public function get($id)
 {
     $orgs = $this->getMembers();
     $orglist = \Terminus\Helpers\Input::orglist();
     $model = null;
     if (isset($orgs[$id])) {
         $model = $this->models[$id];
     } elseif (($location = array_search($id, $orglist)) !== false) {
         $model = $this->models[$location];
     }
     return $model;
 }
Beispiel #2
0
 public static function orgid($args, $key, $default = null)
 {
     $orglist = Input::orglist();
     $flip = array_flip($orglist);
     if (isset($args[$key]) and array_key_exists($args[$key], $flip)) {
         // if we have a valid name provided and we need the id
         return $flip[$args[$key]];
     } elseif (isset($args[$key]) and array_key_exists($args[$key], $orglist)) {
         return $args[$key];
     }
     $orglist = Input::orglist();
     $org = \Terminus::menu($orglist, false, "Choose organization");
     if ('-' === $org) {
         return $default;
     }
     return $org;
 }
Beispiel #3
0
 /**
  * @vcr input_helper_org_helpers
  */
 function testOrgHelpers()
 {
     $orglist = Input::orglist();
     $this->assertInternalType('array', $orglist);
     $this->assertArrayHasKey('-', $orglist);
     $this->assertArrayHasKey('d59379eb-0c23-429c-a7bc-ff51e0a960c2', $orglist);
     // test normal usage
     $args = array('org' => 'Terminus Testing');
     $org = Input::orgname($args, 'org');
     $this->assertEquals('Terminus Testing', $org);
     // test case where an orgid is sent and a name should be returned
     $args = array('org' => 'd59379eb-0c23-429c-a7bc-ff51e0a960c2');
     $org = Input::orgname($args, 'org');
     $this->assertEquals('Terminus Testing', $org);
     // test case where an orgid is sent and a name should be returned
     $args = array('org' => 'd59379eb-0c23-429c-a7bc-ff51e0a960c2');
     $org = Input::orgid($args, 'org');
     $this->assertEquals('d59379eb-0c23-429c-a7bc-ff51e0a960c2', $org);
     $args = array('org' => 'Terminus Testing');
     $org = Input::orgid($args, 'org');
     $this->assertEquals('d59379eb-0c23-429c-a7bc-ff51e0a960c2', $org);
 }
Beispiel #4
0
 /**
  * Input helper that provides interactive menu to select org name
  *
  * @param [array]  $args The args passed in from argv
  * @param [string] $key  Args key to search for
  * @return [string] Site name
  */
 public static function orgname($args, $key)
 {
     $orglist = Input::orglist();
     if (isset($args[$key])) {
         //If org id is sent, fetch the name
         if (array_key_exists($args[$key], $orglist)) {
             return $orglist[$args[$key]];
         }
         return $args[$key];
     }
     $org = \Terminus::menu($orglist, false, "Choose organization");
     return $orglist[$org];
 }
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));
 }