-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Because of consolidation/annotated-command#273, which technically speaking contains a BC break, it was made clear for us that we're not using Robo or the consolidation packages as they were intended. In an effort to keep this package as extendible as possible, and keeping the same philosophy as before, we switched to an event-based system. Basically every step in a command fires an event. The event listener returns a `HandlerWithPriority`, which it turn returns a `TaskInterface` to be executed for this step in the command. We made our own implementation of event priorities, since the default implementation used in Robo doesn't support them (consolidation/annotated-command#244). I tried to document everything as well as possible in the README, but it might (probably will) need some lovin'. This package contains default event handlers with some sensible (to us) defaults. You can prevent these handlers from being executed by writig your own handler with a higher priority (lower number) which does its thing and then calls `$event->stopPropagation()`.
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace DigipolisGent\Robo\Helpers\EventHandler; | ||
|
||
use DigipolisGent\Robo\Helpers\Util\TimeHelper; | ||
use Robo\Contract\ConfigAwareInterface; | ||
|
||
abstract class AbstractBackupHandler | ||
extends AbstractTaskEventHandler | ||
implements ConfigAwareInterface | ||
{ | ||
|
||
use \Consolidation\Config\ConfigAwareTrait; | ||
|
||
/** | ||
* Generate a backup filename based on the given time. | ||
* | ||
* @param string $extension | ||
* The extension to append to the filename. Must include leading dot. | ||
* @param int|null $timestamp | ||
* The timestamp to generate the backup name from. Defaults to the request | ||
* time. | ||
* | ||
* @return string | ||
* The generated filename. | ||
*/ | ||
public function backupFileName($extension, $timestamp = null) | ||
{ | ||
if (is_null($timestamp)) { | ||
$timestamp = TimeHelper::getInstance()->getTime(); | ||
} | ||
return $timestamp . '_' . date('Y_m_d_H_i_s', $timestamp) . $extension; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace DigipolisGent\Robo\Helpers\EventHandler; | ||
|
||
use DigipolisGent\Robo\Helpers\EventHandler\EventHandlerWithPriority; | ||
use DigipolisGent\Robo\Helpers\Util\AddToContainerInterface; | ||
use Robo\Tasks; | ||
|
||
abstract class AbstractTaskEventHandler | ||
extends Tasks | ||
implements EventHandlerWithPriority, AddToContainerInterface | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return static::DEFAULT_PRIORITY; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace DigipolisGent\Robo\Helpers\EventHandler\DefaultHandler; | ||
|
||
use DigipolisGent\Robo\Helpers\EventHandler\AbstractBackupHandler; | ||
use DigipolisGent\Robo\Helpers\Util\RemoteConfig; | ||
use DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
|
||
class BackupRemoteHandler extends AbstractBackupHandler | ||
{ | ||
|
||
use \DigipolisGent\Robo\Helpers\Traits\RemoteDatabaseBackupTrait; | ||
use \DigipolisGent\Robo\Helpers\Traits\RemoteFilesBackupTrait; | ||
use \DigipolisGent\Robo\Task\Deploy\Tasks; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle(GenericEvent $event) | ||
{ | ||
/** @var RemoteConfig $remoteConfig */ | ||
$remoteConfig = $event->getArgument('remoteConfig'); | ||
$remoteSettings = $remoteConfig->getRemoteSettings(); | ||
$options = $event->getArgument('options'); | ||
$fileBackupConfig = $event->getArgument('fileBackupConfig'); | ||
$timeouts = $event->getArgument('timeouts'); | ||
|
||
if (!$options['files'] && !$options['data']) { | ||
$options['files'] = true; | ||
$options['data'] = true; | ||
} | ||
|
||
$backupDir = $remoteSettings['backupsdir'] . '/' . $remoteSettings['time']; | ||
$auth = new KeyFile($remoteConfig->getUser(), $remoteConfig->getPrivateKeyFile()); | ||
$collection = $this->collectionBuilder(); | ||
|
||
if ($options['files']) { | ||
$collection | ||
->taskRemoteFilesBackup($remoteConfig->getHost(), $auth, $backupDir, $remoteSettings['filesdir']) | ||
->backupFile($this->backupFileName('.tar.gz')) | ||
->excludeFromBackup($fileBackupConfig['exclude_from_backup']) | ||
->backupSubDirs($fileBackupConfig['file_backup_subdirs']) | ||
->timeout($timeouts['backup_files']); | ||
} | ||
|
||
if ($options['data']) { | ||
$collection | ||
->taskRemoteDatabaseBackup($remoteConfig->getHost(), $auth, $backupDir, $remoteConfig->getCurrentProjectRoot()) | ||
->backupFile($this->backupFileName('.sql')) | ||
->timeout($timeouts['backup_database']); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |