/**
  * Requests API data and returns aliases
  *
  * @return string
  */
 private function getAliases()
 {
     $request = new Request();
     $user = new User();
     $path = 'drush_aliases';
     $method = 'GET';
     $response = $request->request('users', Session::getValue('user_id'), $path, $method);
     eval(str_replace('<?php', '', $response['data']->drush_aliases));
     $formatted_aliases = substr($response['data']->drush_aliases, 0, -1);
     $sites_object = new Sites();
     $sites = $sites_object->all();
     foreach ($sites as $site) {
         $environments = $site->environments->all();
         foreach ($environments as $environment) {
             $key = $site->get('name') . '.' . $environment->get('id');
             if (isset($aliases[$key])) {
                 break;
             }
             try {
                 $formatted_aliases .= PHP_EOL . "  \$aliases['{$key}'] = ";
                 $formatted_aliases .= $this->constructAlias($environment);
             } catch (TerminusException $e) {
                 continue;
             }
         }
     }
     $formatted_aliases .= PHP_EOL;
     return $formatted_aliases;
 }
Beispiel #2
0
 /**
  * Invoke `wp` commands on a Pantheon development site
  *
  * <commands>...
  * : The WP-CLI commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional WP-CLI flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 function __invoke($args, $assoc_args)
 {
     $command = implode($args, ' ');
     $this->checkCommand($command);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     $environment = Input::env(array('args' => $assoc_args, 'site' => $site));
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     /**
      * See https://github.com/pantheon-systems/titan-mt/blob/master/..
      *  ..dashboardng/app/workshops/site/models/environment.coffee
      */
     $server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
     // Sanitize assoc args so we don't try to pass our own flags.
     unset($assoc_args['site']);
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     // Create user-friendly output
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}=" . escapeshellarg($v) . ' ';
         } else {
             $flags .= "--{$k} ";
         }
     }
     $this->log()->info('Running wp {cmd} {flags} on {site}-{env}', array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand($server, 'wp', $args, $assoc_args);
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Beispiel #3
0
 /**
  * Invoke `wp` commands on a Pantheon development site
  *
  * <commands>...
  * : The WP-CLI commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional WP-CLI flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 function __invoke($args, $assoc_args)
 {
     $environment = Input::env($assoc_args);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     if (!$site) {
         throw new TerminusException("Command could not be completed. Unknown site specified.");
     }
     # see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
     $server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
     if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
         $server['user'] = "******";
         $server['host'] = TERMINUS_HOST;
     }
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     unset($assoc_args['site']);
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $command = implode($args, ' ');
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}=" . escapeshellarg($v) . ' ';
         } else {
             $flags .= "--{$k} ";
         }
     }
     $this->log()->info("Running wp {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $this->send_command($server, 'wp', $args, $assoc_args);
 }
Beispiel #4
0
 /**
  * Invoke `drush` commands on a Pantheon development site
  *
  * <commands>...
  * : The Drush commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional Drush flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 function __invoke($args, $assoc_args)
 {
     $environment = Input::env($assoc_args);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     if (!$site) {
         throw new TerminusException("Command could not be completed. Unknown site specified.");
     }
     $server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
     if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
         $server['user'] = "******";
         $server['host'] = TERMINUS_HOST;
     }
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     unset($assoc_args['site']);
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $command = implode($args, ' ');
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}={$v} ";
         } else {
             $flags .= "--{$k} ";
         }
     }
     $this->log()->info("Running drush {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $this->send_command($server, 'drush', $args, $assoc_args);
 }
Beispiel #5
0
 /**
  * @vcr site_deploy
  */
 public function testGetParentEnvironment()
 {
     logInWithBehatCredentials();
     $site = $this->sites->get('behat-tests');
     $test_env = $site->environments->get('test');
     $dev_env = $test_env->getParentEnvironment();
     $this->assertEquals($dev_env->get('id'), 'dev');
     setDummyCredentials();
 }
Beispiel #6
0
 /**
  * Invoke `drush` commands on a Pantheon development site
  *
  * <commands>...
  * : The WP-CLI command you intend to run, with its arguments
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 public function __invoke($args, $assoc_args)
 {
     $command = array_pop($args);
     $this->checkCommand($command);
     $sites = new Sites();
     $assoc_args['site'] = Input::sitename($assoc_args);
     $site = $sites->get($assoc_args['site']);
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $assoc_args['env'] = $environment = Input::env(array('args' => $assoc_args, 'site' => $site));
     $server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
     if (in_array(Terminus::getConfig('format'), array('bash', 'json', 'silent'))) {
         $assoc_args['pipe'] = 1;
     }
     $this->log()->info("Running drush {cmd} on {site}-{env}", array('cmd' => $command, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand(array('server' => $server, 'remote_exec' => 'drush', 'command' => $command));
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Beispiel #7
0
 /**
  * Invoke `wp` commands on a Pantheon development site
  *
  * <commands>...
  * : The WP-CLI command you intend to run with its arguments, in quotes
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 public function __invoke($args, $assoc_args)
 {
     $command = array_pop($args);
     $this->checkCommand($command);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     $environment = Input::env(array('args' => $assoc_args, 'site' => $site));
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     /**
      * See https://github.com/pantheon-systems/titan-mt/blob/master/..
      *  ..dashboardng/app/workshops/site/models/environment.coffee
      */
     $server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
     $this->log()->info('Running wp {cmd} on {site}-{env}', array('cmd' => $command, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand(array('server' => $server, 'remote_exec' => 'wp', 'command' => $command));
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Beispiel #8
0
 /**
  * Invoke `drush` commands on a Pantheon development site
  *
  * <commands>...
  * : The Drush commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional Drush flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 public function __invoke($args, $assoc_args)
 {
     $command = implode($args, ' ');
     $this->checkCommand($command);
     $sites = new Sites();
     $assoc_args['site'] = Input::sitename($assoc_args);
     $site = $sites->get($assoc_args['site']);
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $assoc_args['env'] = $environment = Input::env($assoc_args);
     $server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     if (isset($assoc_args['site'])) {
         unset($assoc_args['site']);
     }
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}={$v} ";
         } else {
             $flags .= "--{$k} ";
         }
     }
     if (in_array(Terminus::getConfig('format'), array('bash', 'json', 'silent'))) {
         $assoc_args['pipe'] = 1;
     }
     $this->log()->info("Running drush {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand($server, 'drush', $args, $assoc_args);
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Beispiel #9
0
 /**
  * Parent function to SSH-based command invocations
  *
  * @param string[] $args       Command(s) given in the command line
  * @param string[] $assoc_args Arguments and flags passed into the former
  * @return array Elements as follow:
  *         Site   site    Site being invoked
  *         string env_id  Name of the environment being invoked
  *         string command Command to run remotely
  *         string server  Server connection info
  */
 protected function getElements($args, $assoc_args)
 {
     $this->ensureQuotation($args, $assoc_args);
     $command = array_pop($args);
     $this->checkCommand($command);
     $sites = new Sites();
     $site = $sites->get($this->input()->siteName(array('args' => $assoc_args)));
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $env_id = $this->input()->env(array('args' => $assoc_args, 'site' => $site));
     if (!in_array($env_id, ['test', 'live'])) {
         $this->checkConnectionMode($site->environments->get($env_id));
     }
     $elements = array('site' => $site, 'env_id' => $env_id, 'command' => $command, 'server' => $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $env_id)));
     return $elements;
 }
 /**
  * Requests API data and returns aliases
  *
  * @param array $arg_options Elements as follow:
  *    boolean org_only  Set to true for only organizational aliases
  *    boolean team_only Set to true for only team aliases
  * @return string
  */
 private function getAliases(array $arg_options = [])
 {
     $default_options = ['org_only' => false, 'team_only' => false];
     $options = array_merge($default_options, $arg_options);
     $user = Session::getUser();
     $alias_string = $user->getAliases();
     if ($options['team_only']) {
         return $alias_string;
     }
     eval(str_replace('<?php', '', $alias_string));
     $team_aliases = substr($alias_string, 0, -1);
     $sites_object = new Sites();
     $sites = $sites_object->fetch()->all();
     $org_aliases = '';
     foreach ($sites as $site) {
         $environments = $site->environments->all();
         foreach ($environments as $environment) {
             $key = $site->get('name') . '.' . $environment->get('id');
             if (isset($aliases[$key])) {
                 break;
             }
             try {
                 $org_aliases .= PHP_EOL . "  \$aliases['{$key}'] = ";
                 $org_aliases .= $this->constructAlias($environment);
             } catch (TerminusException $e) {
                 continue;
             }
         }
     }
     if ($options['org_only']) {
         $org_aliases .= PHP_EOL;
         return $org_aliases;
     }
     $all_aliases = $alias_string . $org_aliases . PHP_EOL;
     return $all_aliases;
 }
<?php

require 'vendor/autoload.php';
use Terminus\Models\Collections\Sites;
$sites = new Sites();
$all_sites = $sites->all();
$domains = [];
foreach ($all_sites as $site) {
    $environments = $site->environments->all();
    foreach ($environments as $environment) {
        $hostnames = $environment->hostnames->ids();
        $domains = array_merge($hostnames, $domains);
    }
}
print_r($domains);