Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
meltmedia/meltconsole / src / App / Commands / PushFilesCommand.php
Size: Mime:
<?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 push files.
 */
class PushFilesCommand extends MeltCommand {

  /**
   * Question helper.
   *
   * @var \Symfony\Component\Console\Helper\QuestionHelper
   */
  private $question;

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    // Initial config for command.
    $this
      ->setName('melt:push-files')
      ->setAliases(['melt:pushf'])
      ->setDescription('Push files to 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 push to: ', $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.');
    }

    $srcDir = "{$this->projectName}.{$env}";
    $drushAlias = "@melt.{$env}";

    $output->writeln('Pushing files in progress...');

    $this->runLocalCommands([
      "drush rsync @self:sites/default/files {$drushAlias}:docroot/sites/default/files/",
      "drush cr",
    ]);

    $this->runServerCommands([
      "cd {$this->serverRoot}/{$srcDir}",
      'lando drush cr',
    ]);

    $output->writeln('<info>Done!</info>');
  }

}