Exemplo n.º 1
0
 protected function _url($args, $callback)
 {
     foreach ($args as $obj_id) {
         $object = $this->fetcher->get_check($obj_id);
         \Terminus::line($callback($object->{$this->obj_id_key}));
     }
 }
Exemplo n.º 2
0
 private function prompt($question, $default)
 {
     try {
         $response = \cli\prompt($question, $default);
     } catch (\Exception $e) {
         \Terminus::line();
         return false;
     }
     return $response;
 }
Exemplo n.º 3
0
 function show_usage()
 {
     $methods = $this->get_subcommands();
     $i = 0;
     foreach ($methods as $name => $subcommand) {
         $prefix = 0 == $i++ ? 'usage: ' : '   or: ';
         \Terminus::line($subcommand->get_usage($prefix));
     }
     \Terminus::line();
     \Terminus::line("See 'terminus help {$this->name} <command>' for more information on a specific command.");
 }
Exemplo n.º 4
0
 private function _checkSession()
 {
     if (!property_exists($this, "session") || !property_exists($this->session, "user_uuid")) {
         return false;
     }
     $results = $this->terminus_request("user", $this->session->user_uuid, "profile", "GET");
     if ($results['info']['http_code'] >= 400) {
         Terminus::line("Expired Session, please re-authenticate.");
         $this->cache->remove('session');
         Terminus::launch_self("auth", array("login"));
         $this->whoami();
         return true;
     } else {
         return $results['info']['http_code'] <= 199 || $results['info']['http_code'] >= 300 ? false : true;
     }
 }
Exemplo n.º 5
0
 /**
  * Print various data about the CLI environment.
  *
  * ## OPTIONS
  *
  * [--format=<format>]
  * : Accepted values: json
  */
 function info($_, $assoc_args)
 {
     $php_bin = defined('PHP_BINARY') ? PHP_BINARY : getenv('TERMINUS_PHP_USED');
     $runner = Terminus::get_runner();
     if (isset($assoc_args['format']) && 'json' === $assoc_args['format']) {
         $info = array('php_binary_path' => $php_bin, 'global_config_path' => $runner->global_config_path, 'project_config_path' => $runner->project_config_path, 'wp_cli_dir_path' => TERMINUS_ROOT, 'wp_cli_version' => TERMINUS_VERSION);
         Terminus::line(json_encode($info));
     } else {
         Terminus::line("PHP binary:\t" . $php_bin);
         Terminus::line("PHP version:\t" . PHP_VERSION);
         Terminus::line("php.ini used:\t" . get_cfg_var('cfg_file_path'));
         Terminus::line("Terminus root dir:\t" . TERMINUS_ROOT);
         Terminus::line("Terminus global config:\t" . $runner->global_config_path);
         Terminus::line("Terminus project config:\t" . $runner->project_config_path);
         Terminus::line("Terminus version:\t" . TERMINUS_VERSION);
     }
 }
Exemplo n.º 6
0
 function feedback($string)
 {
     if (isset($this->upgrader->strings[$string])) {
         $string = $this->upgrader->strings[$string];
     }
     if (strpos($string, '%') !== false) {
         $args = func_get_args();
         $args = array_splice($args, 1);
         if (!empty($args)) {
             $string = vsprintf($string, $args);
         }
     }
     if (empty($string)) {
         return;
     }
     $string = str_replace('&#8230;', '...', strip_tags($string));
     \Terminus::line($string);
 }
Exemplo n.º 7
0
 /**
  * Waits on this workflow to finish
  *
  * @return [Workflow] $this
  */
 public function wait()
 {
     while (!$this->isFinished()) {
         $this->fetch();
         sleep(3);
         // TODO: output this to stdout so that it doesn't get mixed with any actual output.
         // We can't use the logger here because that might be redirected to a log-file and each line is timestamped.
         \Terminus::out(".");
     }
     // TODO: output this to stdout so that it doesn't get mixed with any actual output.
     \Terminus::line();
     if ($this->isSuccessful()) {
         return $this;
     } else {
         $final_task = $this->get('final_task');
         if ($final_task != null && !empty($final_task->messages)) {
             foreach ($final_task->messages as $data => $message) {
                 throw new TerminusException($message->message);
             }
         }
     }
 }
Exemplo n.º 8
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)
 {
     $site_name = $assoc_args['site'];
     if (isset($assoc_args['env'])) {
         $environment = $assoc_args['env'];
     } else {
         $environment = 'dev';
     }
     $site = SiteFactory::instance($site_name);
     if (!$site) {
         Terminus::error("Command could not be completed.");
         exit;
     }
     # see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
     $server = array('user' => "{$environment}.{$site->getId()}", 'host' => "appserver.{$environment}.{$site->getId()}.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} ";
         }
     }
     Terminus::line("Running wp %s %s on %s-%s", array($command, $flags, $site->getName(), $environment));
     $this->send_command($server, 'wp', $args, $assoc_args);
 }
Exemplo n.º 9
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)
 {
     $site_name = $assoc_args['site'];
     if (isset($assoc_args['env'])) {
         $environment = $assoc_args['env'];
     } else {
         $environment = 'dev';
     }
     $site = SiteFactory::instance($site_name);
     if (!$site) {
         Terminus::error("Command could not be completed.");
         exit;
     }
     $server = array('user' => "{$environment}.{$site->getId()}", 'host' => "appserver.{$environment}.{$site->getId()}.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} ";
         }
     }
     Terminus::line("Running drush %s %s on %s-%s", array($command, $flags, $site->getName(), $environment));
     $this->send_command($server, 'drush', $args, $assoc_args);
 }
Exemplo n.º 10
0
 /**
  * Interacts with redis
  *
  * ## OPTIONS
  *
  * <clear>
  * : clear - Clear redis cache on remote server
  *
  * [--site=<site>]
  * : site name
  *
  * [--env=<env>]
  * : environment
  *
  * ## Examples
  *
  *    terminus site redis clear --site=mikes-wp-test --env=live
  *
  */
 public function redis($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = SiteFactory::instance(Input::sitename($assoc_args));
     $env = @$assoc_args['env'];
     switch ($action) {
         case 'clear':
             $bindings = $site->bindings('cacheserver');
             if (empty($bindings)) {
                 \Terminus::error("Redis cache not enabled");
             }
             $commands = array();
             foreach ($bindings as $binding) {
                 if (@$env and $env != $binding->environment) {
                     continue;
                 }
                 // @$todo ... should probably do this with symfony Process lib
                 $args = array($binding->environment, $site->getId(), $binding->environment, $site->getId(), $binding->host, $binding->port, $binding->password);
                 array_filter($args, function ($a) {
                     return escapeshellarg($a);
                 });
                 $commands[$binding->environment] = vsprintf('ssh -p 2222 %s.%s@appserver.%s.%s.drush.in "redis-cli -h %s -p %s -a %s flushall"', $args);
             }
             foreach ($commands as $env => $command) {
                 Terminus::line("Clearing redis on %s ", array($env));
                 exec($command, $stdout, $return);
                 echo Logger::greenLine($stdout[0]);
             }
             break;
     }
 }
Exemplo n.º 11
0
 public function render()
 {
     foreach ($this->opts as $opt) {
         \Terminus::line($opt);
     }
 }
Exemplo n.º 12
0
Arquivo: site.php Projeto: newtoid/cli
 /**
  * Show or apply upstream updates
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to check
  *
  * [--update]
  * : Apply upstream updates
  *
  * [--env=<name>]
  * : Environment (dev or multidev) to apply updates to; Default: dev
  *
  * [--updatedb]
  * : (Drupal only) run update.php after deploy
  *
  * @alias upstream-updates
  **/
 public function upstream_updates($args, $assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $upstream = $site->getUpstreamUpdates();
     $data = array();
     if (isset($upstream->remote_url) && isset($upstream->behind)) {
         $data[$upstream->remote_url] = 'Up-to-date';
         if ($upstream->behind > 0) {
             $data[$upstream->remote_url] = 'Updates Available';
         }
         $this->constructTableForResponse($data, array('Upstream', 'Status'));
         if (!isset($upstream) || empty($upstream->update_log)) {
             Terminus::success('No updates to show');
         }
         $upstreams = (array) $upstream->update_log;
         if (!empty($upstreams)) {
             $data = array();
             foreach ($upstreams as $commit) {
                 $data[] = array('hash' => $commit->hash, 'datetime' => $commit->datetime, 'message' => $commit->message, 'author' => $commit->author);
             }
             $this->outputter->outputRecordList($data);
         }
     } else {
         Terminus::line('There was a problem checking your upstream status. Please try again.');
     }
     if (isset($assoc_args['update']) && !empty($upstream->update_log)) {
         $env = 'dev';
         if (isset($assoc_args['env'])) {
             $env = $assoc_args['env'];
         }
         if (in_array($env, array('test', 'live'))) {
             Terminus::error(sprintf('Upstream updates cannot be applied to the %s environment', $env));
         }
         $updatedb = isset($assoc_args['updatedb']) && $assoc_args['updatedb'];
         Terminus::confirm(sprintf('Are you sure you want to apply the upstream updates to %s-dev', $site->get('name'), $env));
         $workflow = $site->applyUpstreamUpdates($env, $updatedb);
         $workflow->wait();
         $this->workflowOutput($workflow);
     }
 }
Exemplo n.º 13
0
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * --site=<site>
  * : Id of the site you want to delete
  *
  * [--all]
  * : Just kidding ... we won't let you do that.
  *
  * [--force]
  * : to skip the confirmations
  *
  */
 function delete($args, $assoc_args)
 {
     $site_to_delete = SiteFactory::instance(@$assoc_args['site']);
     if (!$site_to_delete) {
         foreach (SiteFactory::instance() as $id => $site) {
             $site->id = $id;
             $sites[] = $site;
             $menu[] = $site->information->name;
         }
         $index = Terminus::menu($menu, null, "Select a site to delete");
         $site_to_delete = $sites[$index];
     }
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     Terminus::success("Deleted %s!", $site_to_delete->information->name);
 }
Exemplo n.º 14
0
 protected function _debug($vars)
 {
     Terminus::line(print_r($this, true));
     Terminus::line(print_r($vars, true));
 }
Exemplo n.º 15
0
 /**
  * Prompt the user for input
  *
  * @param string $message
  */
 static function promptSecret($message = '', $params = array(), $default = null)
 {
     exec("stty -echo");
     $response = Terminus::prompt($message, $params);
     exec("stty echo");
     Terminus::line();
     return $response;
 }
Exemplo n.º 16
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()));
     }
 }
Exemplo n.º 17
0
 /**
  * Update alls dev sites with an available upstream update.
  *
  * ## OPTIONS
  *
  * [--report]
  * : If set output will contain list of sites and whether they are up-to-date
  *
  * [--upstream=<upstream>]
  * : Specify a specific upstream to check for updating.
  *
  * [--no-updatedb]
  * : Use flag to skip running update.php after the update has applied
  *
  * [--xoption=<theirs|ours>]
  * : Corresponds to git's -X option, set to 'theirs' by default -- https://www.kernel.org/pub/software/scm/git/docs/git-merge.html
  *
  * @subcommand mass-update
  */
 public function mass_update($args, $assoc_args)
 {
     $sites = SiteFactory::instance();
     $env = 'dev';
     $upstream = Input::optional('upstream', $assoc_args, false);
     $data = array();
     $report = Input::optional('report', $assoc_args, false);
     $confirm = Input::optional('confirm', $assoc_args, false);
     // Start status messages.
     if ($upstream) {
         Terminus::line('Looking for sites using ' . $upstream . '.');
     }
     foreach ($sites as $site) {
         $updates = $site->getUpstreamUpdates();
         if (!isset($updates->behind)) {
             // No updates, go back to start.
             continue;
         }
         // Check for upstream argument and site upstream URL match.
         $siteUpstream = $site->info('upstream');
         if ($upstream and isset($siteUpstream->url)) {
             if ($siteUpstream->url != $upstream) {
                 // Uptream doesn't match, go back to start.
                 continue;
             }
         }
         if ($updates->behind > 0) {
             $data[$site->getName()] = array('site' => $site->getName(), 'status' => "Needs update");
             $noupdatedb = Input::optional($assoc_args, 'updatedb', false);
             $update = $noupdatedb ? false : true;
             $xoption = Input::optional($assoc_args, 'xoption', 'theirs');
             if (!$report) {
                 $confirmed = Input::yesno("Apply upstream updatefs to %s ( run update.php:%s, xoption:%s ) ", array($site->getName(), var_export($update, 1), var_export($xoption, 1)));
                 if (!$confirmed) {
                     continue;
                 }
                 // Suer says No, go back to start.
                 // Backup the DB so the client can restore if something goes wrong.
                 Terminus::line('Backing up ' . $site->getName() . '.');
                 $backup = $site->environment('dev')->createBackup(array('element' => 'all'));
                 // Only continue if the backup was successful.
                 if ($backup) {
                     Terminus::success("Backup of " . $site->getName() . " created.");
                     Terminus::line('Updating ' . $site->getName() . '.');
                     // Apply the update, failure here would trigger a guzzle exception so no need to validate success.
                     $response = $site->applyUpstreamUpdates($env, $update, $xoption);
                     $data[$site->getName()]['status'] = 'Updated';
                     Terminus::success($site->getName() . ' is updated.');
                 } else {
                     $data[$site->getName()]['status'] = 'Backup failed';
                     Terminus::error('There was a problem backing up ' . $site->getName() . '. Update aborted.');
                 }
             }
         } else {
             if (isset($assoc_args['report'])) {
                 $data[$site->getName()] = array('site' => $site->getName(), 'status' => "Up to date");
             }
         }
     }
     if (!empty($data)) {
         sort($data);
         $this->handleDisplay($data);
     } else {
         Terminus::line('No sites in need up updating.');
     }
 }
Exemplo n.º 18
0
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * [--site=<site>]
  * : ID of the site you want to delete
  *
  * [--force]
  * : to skip the confirmations
  */
 function delete($args, $assoc_args)
 {
     $sitename = Input::sitename($assoc_args);
     $site_id = $this->sitesCache->findID($sitename);
     $site_to_delete = new Site($site_id);
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     $this->sitesCache->remove($sitename);
     Terminus::success("Deleted %s!", $sitename);
 }