function testEnvironmentFromEnvironmentVariable()
 {
     $_SERVER['TERMINUS_ENV'] = 'live';
     $env_id = Input::env();
     $this->assertInternalType('string', $env_id);
     $this->assertEquals('live', $env_id);
 }
Exemple #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);
     }
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #5
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);
     }
 }
Exemple #6
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);
     }
 }
Exemple #7
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);
     }
 }
Exemple #8
0
 /**
  * Displays an environment's regular backup schedule
  *
  * @params [array] $assoc_args Parameters and flags from the command line
  * @return [void]
  */
 private function showBackupSchedule($assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env(array('args' => $assoc_args, 'choices' => array('dev', 'live'))));
     $schedule = $env->backups->getBackupSchedule();
     if (is_null($schedule['daily_backup_hour'])) {
         $this->log()->info('Backups are not currently scheduled to be run.');
     } else {
         $this->output()->outputRecord($schedule);
     }
 }
Exemple #9
0
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Specify environment, default = dev
  */
 public function wipe($args, $assoc_args)
 {
     try {
         $env = @$assoc_args['env'] ?: 'dev';
         $site = SiteFactory::instance(Input::site($assoc_args));
         $site_id = $site->getId();
         $env = Input::env($assoc_args, 'env');
         Terminus::line("Wiping %s %s", array($site_id, $env));
         $resp = $site->environment($env)->wipe();
         if ($resp) {
             $this->waitOnWorkflow('sites', $site_id, $resp['data']->id);
             Terminus::success("Successfully wiped %s -- %s", array($site->getName(), $env));
         }
     } catch (Exception $e) {
         Terminus::error("%s", array($e->getMessage()));
     }
 }
Exemple #10
0
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Environment to be wiped
  */
 public function wipe($args, $assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     Terminus::confirm('Are you sure you want to wipe {site}-{env}?', array('site' => $site->get('name'), 'env' => $env->get('id')));
     $workflow = $env->wipe();
     $workflow->wait();
     $this->log()->info('Successfully wiped {site}-{env}', array('site' => $site->get('name'), 'env' => $env->get('id')));
 }
Exemple #11
0
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Environment to be wiped
  */
 public function wipe($args, $assoc_args)
 {
     $site = SiteFactory::instance(Input::sitename($assoc_args));
     $environment_id = Input::env($assoc_args, 'env');
     Terminus::confirm(sprintf("Are you sure you want to wipe %s - %s?", $site->getName(), $environment_id));
     $workflow = $site->environment($environment_id)->wipe();
     $workflow->wait();
     Terminus::success(sprintf("Successfully wiped %s - %s", $site->getName(), $environment_id));
 }
Exemple #12
0
 /**
  * Loads a single backup
  *
  * @params [array] $assoc_args Parameters and flags from the command line
  * @return [boolean] Always true, else the function has thrown an exception
  */
 private function loadBackup($assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env(array('args' => $assoc_args, 'site' => $site)));
     $assoc_args['to'] = '/tmp';
     $assoc_args['element'] = 'database';
     if (isset($assoc_args['database'])) {
         $database = $assoc_args['database'];
     } else {
         $database = escapeshellarg(Terminus::prompt('Name of database to import to'));
     }
     if (isset($assoc_args['username'])) {
         $username = $assoc_args['username'];
     } else {
         $username = escapeshellarg(Terminus::prompt('Username'));
     }
     if (isset($assoc_args['password'])) {
         $password = $assoc_args['password'];
     } else {
         $password = escapeshellarg(Terminus::prompt('Password'));
     }
     exec('mysql -e "show databases"', $stdout, $exit);
     if ($exit != 0) {
         $this->failure('MySQL does not appear to be installed on your server.');
     }
     $assoc_args['env'] = $env->get('id');
     $target = $this->backup(array('get'), $assoc_args);
     $target = '/tmp/' . Utils\getFilenameFromUrl($target);
     if (!file_exists($target)) {
         $this->failure('Cannot read database file {target}', compact('target'));
     }
     $this->log()->info('Unziping database');
     exec("gunzip {$target}", $stdout, $exit);
     // trim the gz of the target
     $target = Utils\sqlFromZip($target);
     $target = escapeshellarg($target);
     exec(sprintf('mysql %s -u %s -p"%s" < %s', $database, $username, $password, $target), $stdout, $exit);
     if ($exit != 0) {
         $this->failure('Could not import database');
     }
     $this->log()->info('{target} successfully imported to {db}', array('target' => $target, 'db' => $database));
     return true;
 }
Exemple #13
0
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Environment to be wiped
  */
 public function wipe($args, $assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     Terminus::confirm(sprintf('Are you sure you want to wipe %s - %s?', $site->get('name'), $env->get('id')));
     $workflow = $env->wipe();
     $workflow->wait();
     Terminus::success(sprintf('Successfully wiped %s - %s', $site->get('name'), $env->get('id')));
 }
Exemple #14
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(Input::siteName(array('args' => $assoc_args)));
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $env_id = 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;
 }