|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Contains \DennisDigital\Drupal\Console\Command\SiteBuildCommand. |
| 6 | + * |
| 7 | + * Builds the site by calling various commands. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace DennisDigital\Drupal\Console\Command; |
| 11 | + |
| 12 | +use Symfony\Component\Console\Input\InputOption; |
| 13 | +use Symfony\Component\Console\Input\InputInterface; |
| 14 | +use Symfony\Component\Console\Output\OutputInterface; |
| 15 | +use Symfony\Component\Process\Process; |
| 16 | +use Symfony\Component\Process\Exception\ProcessFailedException; |
| 17 | +use DennisDigital\Drupal\Console\Exception\SiteCommandException; |
| 18 | + |
| 19 | +/** |
| 20 | + * Class SiteBuildCommand |
| 21 | + * |
| 22 | + * @package DennisDigital\Drupal\Console\Command |
| 23 | + */ |
| 24 | +class SiteBuildCommand extends SiteBaseCommand { |
| 25 | + |
| 26 | + /** |
| 27 | + * Stores branch information. |
| 28 | + * |
| 29 | + * @var array Branch. |
| 30 | + */ |
| 31 | + protected $branch; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var ShellProcess |
| 35 | + */ |
| 36 | + private $process; |
| 37 | + |
| 38 | + /** |
| 39 | + * {@inheritdoc} |
| 40 | + */ |
| 41 | + protected function configure() { |
| 42 | + parent::configure(); |
| 43 | + |
| 44 | + $this->setName('site:build') |
| 45 | + ->setDescription('Build a site'); |
| 46 | + |
| 47 | + // Custom options. |
| 48 | + $this->addOption( |
| 49 | + 'branch', |
| 50 | + '-B', |
| 51 | + InputOption::VALUE_OPTIONAL, |
| 52 | + 'Specify which branch to build if different than the global branch found in sites.yml' |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * {@inheritdoc} |
| 58 | + */ |
| 59 | + protected function interact(InputInterface $input, OutputInterface $output) { |
| 60 | + parent::interact($input, $output); |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * {@inheritdoc} |
| 66 | + */ |
| 67 | + protected function execute(InputInterface $input, OutputInterface $output) { |
| 68 | + parent::execute($input, $output); |
| 69 | + |
| 70 | + $commands = [ |
| 71 | + 'drupal site:checkout %s', |
| 72 | + 'drupal site:compose %s', |
| 73 | + 'drupal site:npm %s', |
| 74 | + 'drupal site:grunt %s', |
| 75 | + 'drupal site:settings:db %s', |
| 76 | + 'drupal site:phpunit:setup %s', |
| 77 | + 'drupal site:behat:setup %s', |
| 78 | + 'drupal site:settings:memcache %s', |
| 79 | + 'drupal site:db:import %s', |
| 80 | + ]; |
| 81 | + |
| 82 | + foreach ($commands as $item) { |
| 83 | + $command = sprintf( |
| 84 | + $item, |
| 85 | + $this->siteName |
| 86 | + ); |
| 87 | + $this->process($command); |
| 88 | + //print (shell_exec($command)); |
| 89 | + } |
| 90 | + |
| 91 | + $commands = [ |
| 92 | + 'cd %s/web; drush updb -y;', |
| 93 | + 'cd %s/web; drush cr;', |
| 94 | + ]; |
| 95 | + |
| 96 | + foreach ($commands as $item) { |
| 97 | + $command = sprintf( |
| 98 | + $item, |
| 99 | + $this->destination |
| 100 | + ); |
| 101 | + $this->process($command); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + protected function process($command) { |
| 106 | + $this->process = new Process($command); |
| 107 | + //$this->process->setWorkingDirectory($this->destination); |
| 108 | + $this->process->enableOutput(); |
| 109 | + $this->process->setTimeout(null); |
| 110 | + $this->process->setPty(true); |
| 111 | + $this->process->run( |
| 112 | + function ($type, $buffer) { |
| 113 | + $this->io->write($buffer); |
| 114 | + } |
| 115 | + ); |
| 116 | + |
| 117 | + if (!$this->process->isSuccessful()) { |
| 118 | + throw new SiteCommandException($this->process->getOutput()); |
| 119 | + } |
| 120 | + |
| 121 | +// $shellProcess = $this->getShellProcess(); |
| 122 | +// $shellProcess->process->enableOutput(); |
| 123 | +// |
| 124 | +// if ($shellProcess->exec($command, TRUE)) { |
| 125 | +// $this->io->writeln($shellProcess->getOutput()); |
| 126 | +// } |
| 127 | +// else { |
| 128 | +// throw new SiteCommandException($shellProcess->getOutput()); |
| 129 | +// } |
| 130 | + } |
| 131 | + |
| 132 | +} |
0 commit comments