-
Notifications
You must be signed in to change notification settings - Fork 2
/
RestoreBackupDbLocalHandler.php
41 lines (36 loc) · 1.42 KB
/
RestoreBackupDbLocalHandler.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
<?php
namespace DigipolisGent\Robo\Helpers\EventHandler\DefaultHandler;
use DigipolisGent\CommandBuilder\CommandBuilder;
use DigipolisGent\Robo\Helpers\EventHandler\AbstractBackupHandler;
use DigipolisGent\Robo\Helpers\Util\RemoteConfig;
use Symfony\Component\EventDispatcher\GenericEvent;
class RestoreBackupDbLocalHandler extends AbstractBackupHandler
{
/**
* {@inheritDoc}
*/
public function handle(GenericEvent $event)
{
/** @var RemoteConfig $remoteConfig */
$remoteConfig = $event->getArgument('remoteConfig');
$remoteSettings = $remoteConfig->getRemoteSettings();
$dbBackupFile = $this->backupFileName('.sql.gz', $remoteSettings['time']);
$dbRestore = CommandBuilder::create('vendor/bin/robo digipolis:database-restore')->addOption('source', $dbBackupFile);
$cwd = getcwd();
return $this->taskExecStack()
->exec(
(string) CommandBuilder::create('cd')
->addArgument($this->getConfig()->get('digipolis.root.project'))
->onSuccess($dbRestore)
)
->exec(
(string) CommandBuilder::create('cd')
->addArgument($cwd)
->onSuccess(
CommandBuilder::create('rm')
->addFlag('rf')
->addArgument($dbBackupFile)
)
);
}
}