-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPostSymlinkHandler.php
52 lines (45 loc) · 1.98 KB
/
PostSymlinkHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace DigipolisGent\Robo\Helpers\EventHandler\DefaultHandler;
use DigipolisGent\CommandBuilder\CommandBuilder;
use DigipolisGent\Robo\Helpers\EventHandler\AbstractTaskEventHandler;
use DigipolisGent\Robo\Helpers\Util\RemoteConfig;
use DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile;
use Symfony\Component\EventDispatcher\GenericEvent;
class PostSymlinkHandler extends AbstractTaskEventHandler
{
use \DigipolisGent\Robo\Task\Deploy\Tasks;
/**
* {@inheritDoc}
*/
public function handle(GenericEvent $event)
{
/** @var RemoteConfig $remoteConfig */
$remoteConfig = $event->getArgument('remoteConfig');
$remoteSettings = $remoteConfig->getRemoteSettings();
$auth = new KeyFile($remoteConfig->getUser(), $remoteConfig->getPrivateKeyFile());
$timeouts = $event->getArgument('timeouts');
$collection = $this->collectionBuilder();
if (isset($remoteSettings['postsymlink_filechecks']) && $remoteSettings['postsymlink_filechecks']) {
$projectRoot = $remoteSettings['rootdir'];
$collection->taskSsh($remoteConfig->getHost(), $auth)
->remoteDirectory($projectRoot, true)
->timeout($timeouts['post_symlink']);
foreach ($remoteSettings['postsymlink_filechecks'] as $file) {
// If this command fails, the collection will fail, which will
// trigger a rollback.
$builder = CommandBuilder::create('ls')
->addArgument($file)
->pipeOutputTo('grep')
->addArgument($file)
->onFailure(
CommandBuilder::create('echo')
->addArgument('[ERROR] ' . $file . ' was not found.')
->onFinished('exit')
->addArgument('1')
);
$collection->exec((string) $builder);
}
}
return $collection;
}
}