Ejemplo n.º 1
0
 /**
  * List an organizations sites
  *
  * ## OPTIONS
  *
  * [--org=<org>]
  * : Organization name or Id
  *
  * [--add=<site>]
  * : Site to add to organization
  *
  * [--remove=<site>]
  * : Site to remove from organization
  *
  * @subcommand sites
  *
  */
 public function sites($args, $assoc_args)
 {
     $orgs = array();
     $user = new User();
     foreach ($user->organizations() as $id => $org) {
         $orgs[$id] = $org->name;
     }
     if (!isset($assoc_args['org']) or empty($assoc_args['org'])) {
         $selected_org = Terminus::menu($orgs, false, "Choose an organization");
     } else {
         $selected_org = $assoc_args['org'];
     }
     $org = new Organization($selected_org);
     if (isset($assoc_args['add'])) {
         $add = SiteFactory::instance(Input::site($assoc_args, 'add'));
         Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name));
         $org->addSite($add);
         Terminus::success("Added site!");
         return true;
     }
     if (isset($assoc_args['remove'])) {
         $remove = SiteFactory::instance(Input::site($assoc_args, 'remove'));
         Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name));
         $org->removeSite($remove);
         Terminus::success("Removed site!");
         return true;
     }
     $sites = $org->getSites();
     $data = array();
     foreach ($sites as $site) {
         $data[] = array('name' => $site->site->name, 'service level' => isset($site->site->service_level) ? $site->site->service_level : '', 'framework' => isset($site->site->framework) ? $site->site->framework : '', 'created' => date('Y-m-d H:i:s', $site->site->created));
     }
     $this->handleDisplay($data);
 }
Ejemplo n.º 2
0
 /**
  * Show a list of your organizations on Pantheon
  *
  * @subcommand list
  *
  */
 public function all($args, $assoc_args)
 {
     $user = new User();
     $data = array();
     foreach ($user->organizations() as $org_id => $org) {
         $data[] = array('name' => $org->name, 'id' => $org_id);
     }
     $this->handleDisplay($data);
 }
Ejemplo n.º 3
0
 public static function orglist($site = null)
 {
     $orgs = array('-' => 'None');
     $user = new User();
     foreach ($user->organizations() as $id => $org) {
         $orgs[$id] = $org->name;
     }
     return $orgs;
 }
Ejemplo n.º 4
0
 /**
  * Create a new Site
  * @param $options (array)
  *   @param $options label(string)
  *   @param $options name(string)
  *   @option $options organization_id(string)
  *   @option product_id(string)
  *
  * @return Workflow
  *
  */
 static function create($options = array())
 {
     $data = array('label' => $options['label'], 'site_name' => $options['name']);
     if (isset($options['organization_id'])) {
         $data['organization_id'] = $options['organization_id'];
     }
     if (isset($options['product_id'])) {
         $data['deploy_product'] = array('product_id' => $options['product_id']);
     }
     $user = User::instance();
     $workflow = $user->workflows->create('create_site', array('params' => $data));
     return $workflow;
 }
Ejemplo n.º 5
0
 public function __construct($org)
 {
     // if the org id is passed in then we need to fetch it from the user object
     if (is_string($org)) {
         $user = User::instance();
         $orgs = $user->organizations();
         $org = $orgs->{$org};
     }
     // hydrate the object
     $properties = get_object_vars($org);
     foreach (get_object_vars($org) as $key => $value) {
         if (!property_exists($this, $key)) {
             $this->{$key} = $properties[$key];
         }
     }
     return $this;
 }
Ejemplo n.º 6
0
 public function __construct($org)
 {
     // if the org id is passed in then we need to fetch it from the user object
     if (is_string($org)) {
         $this->user = User::instance();
         $orgs = $this->user->organizations();
         $org = $orgs->{$org};
     }
     $this->id = $org->id;
     // hydrate the object
     $properties = get_object_vars($org);
     foreach (get_object_vars($org) as $key => $value) {
         if (!property_exists($this, $key)) {
             $this->{$key} = $properties[$key];
         }
     }
     $this->workflows = new Workflows(array('owner' => $this, 'owner_type' => 'organization'));
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Print and save drush aliases
  *
  * ## OPTIONS
  *
  * [--print]
  * : print aliases to screen
  *
  * [--location=<location>]
  * : specify the location of the alias file, default it ~/.drush/pantheon.drushrc.php
  *
  */
 public function aliases($args, $assoc_args)
 {
     $user = new User();
     $print = Input::optional('print', $assoc_args, false);
     $json = \Terminus::get_config('json');
     $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php');
     $message = "Pantheon aliases updated.";
     if (!file_exists($location)) {
         $message = "Pantheon aliases created.";
     }
     $content = $user->getAliases();
     $h = fopen($location, 'w+');
     fwrite($h, $content);
     fclose($h);
     chmod($location, 0777);
     Logger::coloredOutput("%2%K{$message}%n");
     if ($json) {
         include $location;
         print \Terminus\Utils\json_dump($aliases);
     } elseif ($print) {
         print $content;
     }
 }
Ejemplo n.º 8
0
 /**
  * Change the site payment instrument
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--instrument=<UUID>]
  * : Change the instrument by setting the ID
  *
  * ## EXAMPLES
  *
  *  terminus site instrument --site=sitename
  */
 public function instrument($args, $assoc_args)
 {
     $user = new User();
     $instruments = $user->instruments()->all();
     foreach ($instruments as $instrument) {
         $data[$instrument->get('id')] = $instrument->get('label');
     }
     //If site is not set, show all user's payment instruments
     if (!isset($assoc_args['site'])) {
         $this->handleDisplay($data, array(), array('UUID', 'Label'));
     } else {
         array_unshift($data, 'none');
         $site = SiteFactory::instance($assoc_args['site']);
         //If instrument is not present, show the site's current instrument
         if (!isset($assoc_args['instrument'])) {
             $instrument_uuid = $site->get('instrument');
             if ($instrument_uuid == null) {
                 \Terminus::line($site->get('name') . ' does not have an attached payment instrument.');
             } else {
                 \Terminus::line($site->get('name') . ' is being charged to ' . $data[$instrument_uuid] . ', UUID: ' . $instrument_uuid);
             }
         } else {
             //Both are present. Ensure sure UUID is valid.
             //This attempts to prevent users from selecting instruments which do not belong to them.
             $instrument_id = $assoc_args['instrument'];
             if (!isset($data[$instrument_id])) {
                 $location = array_search($instrument_id, $data);
                 if ($location !== false) {
                     $instrument_id = $location;
                 } else {
                     $uuids = array_keys($data);
                     $instrument_id = Input::menu($data, null, 'Select a payment instrument');
                 }
             }
             //Change the instrument once we have a valid instrument.
             if ($instrument_id == 0) {
                 $workflow = $site->removeInstrument();
             } else {
                 $workflow = $site->addInstrument($instrument_id);
             }
             $workflow->wait();
             \Terminus::line("Successfully updated payment instrument to {$instrument_id}.");
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Print and save drush aliases
  *
  * ## OPTIONS
  *
  * [--print]
  * : print aliases to screen
  *
  * [--location=<location>]
  * : Specify the the full path, including the filename, to the alias file you wish to create.
  *   Without this option a default of '~/.drush/pantheon.drushrc.php' will be used.
  *
  */
 public function aliases($args, $assoc_args)
 {
     $user = new User();
     $print = Input::optional('print', $assoc_args, false);
     $json = \Terminus::get_config('json');
     $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php');
     // Cannot provide just a directory
     if (is_dir($location)) {
         \Terminus::error("Please provide a full path with filename, e.g. %s/pantheon.aliases.drushrc.php", $location);
         exit(1);
     }
     $file_exists = file_exists($location);
     // Create the directory if it doesn't yet exist
     $dirname = dirname($location);
     if (!is_dir($dirname)) {
         mkdir($dirname, 0700, true);
     }
     $content = $user->getAliases();
     $h = fopen($location, 'w+');
     fwrite($h, $content);
     fclose($h);
     chmod($location, 0700);
     $message = $file_exists ? 'Pantheon aliases updated' : 'Pantheon aliases created';
     Logger::coloredOutput("%2%K{$message}%n");
     if ($json) {
         include $location;
         print \Terminus\Utils\json_dump($aliases);
     } elseif ($print) {
         print $content;
     }
 }
Ejemplo n.º 10
0
 /**
  * Returns an array listing organizaitions applicable to user
  *
  * @return [array] List of organizations
  */
 public static function orglist($options = array())
 {
     $orgs = array();
     $allow_none = isset($options['allow_none']) ? $options['allow_none'] : true;
     if ($allow_none) {
         $orgs = array('-' => 'None');
     }
     $user = new User();
     foreach ($user->organizations() as $id => $org) {
         $orgs[$id] = $org->name;
     }
     return $orgs;
 }