Skip to content

Commit

Permalink
Merge branch 'feature/AddPostCloneCommandOption' into 'master'
Browse files Browse the repository at this point in the history
[FEATURE] Add postClone option to the clone command

The postClone option can either be an array or a string. The given commands are executed with the shell after the clone is finished.
The the local FLOW_CONTEXT is added to the command so `./flow ...` can be used without specifying the context.

See merge request !6
  • Loading branch information
grebaldi committed Mar 1, 2016
2 parents 3e542e5 + 6ec99b1 commit 02f87a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Classes/Sitegeist/MagicWand/Command/AbstractCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ protected function executeLocalShellCommand($command, $arguments = [], $options
* @param array $arguments
* @param array $options
*/
protected function executeLocalFlowCommand($command, $arguments = [], $options = [])
protected function executeLocalShellCommandWithFlowContext($command, $arguments = [], $options = [])
{
$flowCommand = 'FLOW_CONTEXT=' . $this->bootstrap->getContext() . ' ./flow ' . $command;
$flowCommand = sprintf('FLOW_CONTEXT=%s %s', $this->bootstrap->getContext(), $command);
return $this->executeLocalShellCommand($flowCommand, $arguments, $options);
}

/**
* @param string $commands
* @param array $arguments
* @param array $options
*/
protected function executeLocalFlowCommand($command, $arguments = [], $options = [])
{
$flowCommand = sprintf('./flow %s', $command);
return $this->executeLocalShellCommandWithFlowContext($flowCommand, $arguments, $options);
}

/**
* @param $line
*/
Expand Down
18 changes: 18 additions & 0 deletions Classes/Sitegeist/MagicWand/Command/CloneCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
$this->clonePresets[$presetName]['port'],
$this->clonePresets[$presetName]['path'],
$this->clonePresets[$presetName]['context'],
(isset($this->clonePresets[$presetName]['postClone']) ? $this->clonePresets[$presetName]['postClone'] : NULL),
$yes,
$keepDb
);
Expand All @@ -84,6 +85,7 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
* @param string $port ssh port
* @param string $path path on the remote server
* @param string $context flow_context on the remote server
* @param mixded $postClone command or array of commands to be executed after cloning
* @param boolean $yes confirm execution without further input
* @param boolean $keepDb skip dropping of database during sync
*/
Expand All @@ -93,6 +95,7 @@ public function remoteHostCommand(
$port,
$path,
$context = 'Production',
$postClone = NULL,
$yes = false,
$keepDb = false
) {
Expand Down Expand Up @@ -240,6 +243,21 @@ public function remoteHostCommand(
$this->outputHeadLine('Publish Resources');
$this->executeLocalFlowCommand('resource:publish');

##############
# Post Clone #
##############

if ($postClone) {
$this->outputHeadLine('Execute post_clone commands');
if (is_array($postClone)) {
foreach($postClone as $postCloneCommand) {
$this->executeLocalShellCommandWithFlowContext($postCloneCommand);
}
} else {
$this->executeLocalShellCommandWithFlowContext($postClone);
}
}

#################
# Final Message #
#################
Expand Down

0 comments on commit 02f87a7

Please sign in to comment.