Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / drush / drush / src / Commands / core / SshCommands.php
1 <?php
2 namespace Drush\Commands\core;
3
4 use Drush\Commands\DrushCommands;
5 use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
6 use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
7
8 class SshCommands extends DrushCommands implements SiteAliasManagerAwareInterface
9 {
10     use SiteAliasManagerAwareTrait;
11
12     /**
13      * Connect to a Drupal site's server via SSH.
14      *
15      * @command site:ssh
16      * @option cd Directory to change to if Drupal root is not desired (the default).
17      * @optionset_proc_build
18      * @handle-remote-commands
19      * @usage drush @mysite ssh
20      *   Open an interactive shell on @mysite's server.
21      * @usage drush @prod ssh ls /tmp
22      *   Run "ls /tmp" on @prod site. If @prod is a site list, then ls will be executed on each site.
23      * @usage drush @prod ssh git pull
24      *   Run "git pull" on the Drupal root directory on the @prod site.
25      * @aliases ssh,site-ssh
26      * @topics docs:aliases
27      */
28     public function ssh(array $args, $options = ['cd' => true])
29     {
30         // n.b. we do not escape the first (0th) arg to allow `drush ssh 'ls /path'`
31         // to work in addition to the preferred form of `drush ssh ls /path`.
32         // Supporting the legacy form means that we cannot give the full path to an
33         // executable if it contains spaces.
34         for ($x = 1; $x < count($args); $x++) {
35             $args[$x] = drush_escapeshellarg($args[$x]);
36         }
37         $command = implode(' ', $args);
38
39         $alias = $this->siteAliasManager()->getSelf();
40         if ($alias->isNone()) {
41             throw new \Exception('A site alias is required. The way you call ssh command has changed to `drush @alias ssh`.');
42         }
43
44         // Local sites run their bash without SSH.
45         if (!$alias->isRemote()) {
46             $return = drush_invoke_process('@self', 'core-execute', [$command], ['escape' => false]);
47             return $return['object'];
48         }
49
50         // We have a remote site - build ssh command and run.
51         $interactive = false;
52         $cd = $options['cd'];
53         if (empty($command)) {
54             $command = 'bash -l';
55             $interactive = true;
56         }
57
58         $cmd = drush_shell_proc_build($alias, $command, $cd, $interactive);
59         $status = drush_shell_proc_open($cmd);
60         if ($status != 0) {
61             throw new \Exception(dt('An error @code occurred while running the command `@command`', ['@command' => $cmd, '@code' => $status]));
62         }
63     }
64 }