Repository URL to install this package:
|
Version:
2.2.4 ▾
|
<?php
namespace MeltConsole\App\Commands;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ChoiceQuestion;
/**
* Class to pull files.
*/
class PullFilesCommand extends MeltCommand {
/**
* Question helper.
*
* @var \Symfony\Component\Console\Helper\QuestionHelper
*/
private $question;
/**
* {@inheritdoc}
*/
protected function configure() {
// Initial config for command.
$this
->setName('melt:pull-files')
->setAliases(['melt:pullf'])
->setDescription('Pull files from remote environment.')
->setHelp('Syncs local files with remote environment...')
->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'Environment e.g dev, qa, stage');
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output) {
// TODO: Change the autogenerated stub.
parent::interact($input, $output);
$this->question = $this->getHelper('question');
if (!$input->getOption('env')) {
// Ask the user some stuff.
$envs = $this->getEnvironmentsFromServer();
$question = new ChoiceQuestion('Choose environment to pull from: ', $envs);
if (empty($envs)) {
throw new \Exception('There are currently no environments.');
}
$env = $this->question->ask($input, $output, $question);
// Set options based on users answer.
$input->setOption('env', $env);
}
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$env = $input->getOption('env');
if (!$this->validateEnvironmentExistsOnServer($env)) {
throw new \Exception('Environment doesn\'t exist.');
}
$drushAlias = "@melt.{$env}";
$output->writeln('Pulling files in progress...');
$this->runLocalCommands([
"drush rsync {$drushAlias}:docroot/sites/default/files/ @self:sites/default/files",
"drush cr",
]);
$output->writeln('<info>Done!</info>');
}
}