Skip to content

Commit cd90dfe

Browse files
Merge branch 'site_build_command'
# Conflicts: # chain/chain-site-build.yml # src/Command/SiteBaseCommand.php # src/Command/SiteCheckoutCommand.php
2 parents 465afec + b363558 commit cd90dfe

File tree

5 files changed

+169
-4
lines changed

5 files changed

+169
-4
lines changed

chain/chain-site-build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Usage: drupal site:build --placeholder="name:subscriptions"
22
command:
3+
<<<<<<< HEAD
34
name: site:build
45
description: 'Builds a site.'
6+
=======
7+
name: chain_site:build
8+
description: 'Performs multiple commands to build a site'
9+
>>>>>>> site_build_command
510
commands:
611
# Checkout site
712
- command: site:checkout

console.config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ application:
22
autowire:
33
commands:
44
forced:
5+
"site:build":
6+
class: \DennisDigital\Drupal\Console\Command\SiteBuildCommand
57
'site:checkout':
68
class: \DennisDigital\Drupal\Console\Command\SiteCheckoutCommand
79
'site:compose':

src/Command/SiteBaseCommand.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class SiteBaseCommand extends Command {
8787
*/
8888
protected $container;
8989

90+
/**
91+
* @var ConfigurationManager
92+
*/
93+
protected $configurationManager;
94+
9095
/**
9196
* Constructor.
9297
*/
@@ -139,6 +144,12 @@ protected function configure() {
139144
protected function interact(InputInterface $input, OutputInterface $output) {
140145
$this->io = new DrupalStyle($input, $output);
141146

147+
<<<<<<< HEAD
148+
=======
149+
$this->configurationManager = $this->container
150+
->get('console.configuration_manager');
151+
152+
>>>>>>> site_build_command
142153
$sitesDirectory = $this->configurationManager->getSitesDirectory();
143154
$options = $this->siteList($sitesDirectory);
144155

@@ -154,7 +165,6 @@ protected function interact(InputInterface $input, OutputInterface $output) {
154165
}
155166

156167
$this->validateSiteParams($input, $output);
157-
158168
}
159169

160170
/**
@@ -197,7 +207,11 @@ protected function validateSiteParams(InputInterface $input, OutputInterface $ou
197207
*/
198208
protected function _siteConfig(InputInterface $input) {
199209
$siteName = $input->getArgument('name');
210+
<<<<<<< HEAD
200211

212+
=======
213+
//var_dump($this->config);
214+
>>>>>>> site_build_command
201215
// $environment = $input->getOption('env')
202216
$environment = $this->configurationManager->getConfiguration()
203217
->get('application.environment');
@@ -446,10 +460,17 @@ protected function shellPath($file_name) {
446460
* It will only return sites that have 'repo' configured
447461
*
448462
* @param string $sitesDirectory
463+
<<<<<<< HEAD
449464
*
450465
* @return array
451466
*/
452467
private function siteList($sitesDirectory) {
468+
=======
469+
* @return array
470+
*/
471+
private function siteList($sitesDirectory)
472+
{
473+
>>>>>>> site_build_command
453474
$finder = new Finder();
454475
$finder->in($sitesDirectory);
455476
$finder->name("*.yml");
@@ -473,5 +494,8 @@ private function siteList($sitesDirectory) {
473494

474495
return $tableRows;
475496
}
497+
<<<<<<< HEAD
476498

499+
=======
500+
>>>>>>> site_build_command
477501
}

src/Command/SiteBuildCommand.php

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
}

src/Command/SiteCheckoutCommand.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ protected function interact(InputInterface $input, OutputInterface $output) {
105105
protected function execute(InputInterface $input, OutputInterface $output) {
106106
parent::execute($input, $output);
107107

108-
// Validate repo.
109-
$this->_validateRepo();
110-
111108
// Validate branch.
112109
$this->_validateBranch($input);
113110

@@ -302,6 +299,11 @@ protected function gitCheckout($branch, $destination) {
302299
/**
303300
* Pulls a list of branches from remote.
304301
*
302+
<<<<<<< HEAD
303+
=======
304+
* @param $repo
305+
*
306+
>>>>>>> site_build_command
305307
* @return mixed
306308
* @throws SiteCommandException
307309
*/

0 commit comments

Comments
 (0)