1 | <?php |
||
8 | class RemoteActionRunner |
||
9 | { |
||
10 | /** |
||
11 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
12 | */ |
||
13 | protected $output; |
||
14 | |||
15 | /** |
||
16 | * @var Net_SFTP |
||
17 | */ |
||
18 | protected $ssh; |
||
19 | |||
20 | public function __construct(OutputInterface $output, Net_SFTP $ssh) |
||
25 | |||
26 | public function exec($command, $cwd = null) |
||
44 | |||
45 | public function symlink($target, $linkName) |
||
46 | { |
||
47 | return $this->exec('ln -s ' . $target . ' ' . $linkName); |
||
48 | } |
||
49 | |||
50 | public function rmfile($file) |
||
54 | |||
55 | public function rmdir($file) |
||
59 | |||
60 | protected function getComposerCommand($dir) |
||
61 | { |
||
62 | //is composer installed on the system ? |
||
63 | $composerCommand = str_replace("\n", '', $this->ssh->exec('which composer')); |
||
64 | if ($composerCommand != '') { |
||
65 | return $composerCommand; |
||
66 | } |
||
67 | |||
68 | //is composer installed locally ? |
||
69 | if (file_exists("$dir/composer.phar")) { |
||
70 | return "$dir/composer.phar"; |
||
71 | } |
||
72 | |||
73 | //if not install it locally |
||
74 | $response = $this->exec('curl -s https://getcomposer.org/installer | php -- --install-dir="' . $dir . '"'); |
||
75 | |||
76 | $this->output->write('<fg=green>' . $response . '</fg=green>'); |
||
77 | |||
78 | return "$dir/composer.phar"; |
||
79 | } |
||
80 | |||
81 | public function composer($dir) |
||
82 | { |
||
83 | $composerCommand = $this->getComposerCommand($dir); |
||
84 | |||
85 | $command = "$composerCommand install --prefer-dist --optimize-autoloader --no-dev --no-interaction -d $dir"; |
||
86 | |||
87 | return $this->exec($command . ((VERBOSE) ? ' -v' : '')); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Tests if a directory exists |
||
92 | * |
||
93 | * @param string $dir |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function isDir($dir) |
||
108 | |||
109 | public function getSymlinkDestination($folder) |
||
117 | |||
118 | public function setupServer($destinationDir) |
||
119 | { |
||
120 | if (!$this->isDir($destinationDir)) { |
||
128 | } |
||
129 |