Skip to content

Commit a575410

Browse files
committed
Case 27689; starting branch to remove hard-coded web directories
1 parent 0c30d0d commit a575410

14 files changed

+79
-80
lines changed

chain/chain-site-configure.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ commands:
1515
- command: site:settings:memcache
1616
arguments:
1717
name: '%{{name}}'
18-
# Create the drush alias
19-
- command: site:drush:alias
20-
arguments:
21-
name: '%{{name}}'

src/Command/Site/AbstractCommand.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ abstract class AbstractCommand extends Command {
7070
protected $profile = NULL;
7171

7272
/**
73-
* Stores the destination directory.
73+
* The Drupal core directory.
7474
*
7575
* @var string
7676
*/
77-
protected $destination = NULL;
77+
protected $drupal_directory = NULL;
7878

7979
/**
8080
* Stores the site url.
@@ -266,31 +266,28 @@ protected function validateDestination(InputInterface $input) {
266266
!is_null($input->getOption('destination-directory'))
267267
) {
268268
// Use config from parameter.
269-
$this->destination = $input->getOption('destination-directory');
269+
$this->drupal_directory = $input->getOption('destination-directory');
270270
}
271-
elseif (isset($this->config['root'])) {
271+
elseif (isset($this->config['repo']['directory'])) {
272272
// Use config from sites.yml.
273-
$this->destination = $this->config['root'];
273+
$this->drupal_directory = $this->config['repo']['directory'];
274274
}
275275
else {
276-
$this->destination = '/tmp/' . $this->siteName;
276+
$this->drupal_directory = '/tmp/' . $this->siteName;
277277
}
278278

279279
// Allow destination to be overriden by environment variable. i.e.
280280
// export site_destination_directory="/directory/"
281281
if (!getenv('site_destination_directory')) {
282-
putenv("site_destination_directory=$this->destination");
282+
putenv("site_destination_directory=$this->drupal_directory");
283283
}
284284
else {
285-
$this->destination = getenv('site_destination_directory');
285+
$this->drupal_directory = getenv('site_destination_directory');
286286
}
287287

288-
// Make sure we have a slash at the end.
289-
if (substr($this->destination, -1) != '/') {
290-
$this->destination .= '/';
291-
}
288+
$this->drupal_directory = rtrim($this->drupal_directory, '/') . '/' . trim($this->config['core_directory'], '/') . '/';
292289

293-
return $this->destination;
290+
return $this->drupal_directory;
294291
}
295292

296293
/**
@@ -325,7 +322,7 @@ protected function validateUrl(InputInterface $input) {
325322
* @return string Path
326323
*/
327324
public function settingsPhpDirectory() {
328-
$webSitesPath = $this->destination . 'web/sites/';
325+
$webSitesPath = $this->drupal_directory . '/sites/';
329326
$settingsPath = $webSitesPath . 'default';
330327

331328
$command = sprintf(

src/Command/Site/AbstractConfigCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
9797
* @throws \DennisDigital\Drupal\Console\Exception\CommandException
9898
*/
9999
protected function generateConfigFile() {
100-
$this->template = $this->destination . $this->template;
101-
$this->filename = $this->destination . $this->filename;
100+
$this->template = $this->drupal_directory . $this->template;
101+
$this->filename = $this->drupal_directory . $this->filename;
102102

103103
// Validation.
104104
if (!$this->fileExists($this->template)) {

src/Command/Site/Checkout/AbstractRefCommand.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ protected function execute(InputInterface $input, OutputInterface $output) {
7373
$this->io->comment(sprintf('Checking out %s (%s) on %s',
7474
$this->siteName,
7575
$this->ref,
76-
$this->destination
76+
$this->repo['directory']
7777
));
7878

7979
switch ($this->repo['type']) {
8080
case 'git':
8181
// Check if repo exists and has any changes.
82-
if ($this->fileExists($this->destination) &&
83-
$this->fileExists($this->destination . '.' . $this->repo['type'])
82+
if ($this->fileExists($this->repo['directory']) &&
83+
$this->fileExists($this->repo['directory'] . '.' . $this->repo['type'])
8484
) {
8585
if ($input->hasOption('force') &&
8686
!$input->getOption('force')
@@ -111,10 +111,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
111111
* @throws CommandException
112112
*
113113
* @return string Repo url
114+
*
115+
* @todo validate for all command that use repo config.
114116
*/
115117
protected function validateRepo() {
116118
if (isset($this->config['repo'])) {
117119
$this->repo = $this->config['repo'];
120+
$this->repo['directory'] = rtrim($this->repo['directory'], '/') . '/';
118121
}
119122
else {
120123
throw new CommandException('Repo not found in sites.yml');
@@ -133,7 +136,7 @@ protected function validateRepo() {
133136
protected function gitDiff() {
134137
$command = sprintf(
135138
'cd %s && git diff-files --name-status -r --ignore-submodules',
136-
$this->shellPath($this->destination)
139+
$this->shellPath($this->repo['directory'])
137140
);
138141

139142
$shellProcess = $this->getShellProcess();
@@ -143,7 +146,7 @@ protected function gitDiff() {
143146
$message = sprintf('You have uncommitted changes on %s' . PHP_EOL .
144147
'Please commit or revert your changes before checking out the site.' . PHP_EOL .
145148
'If you want to wipe your local changes use --force.',
146-
$this->destination
149+
$this->repo['directory']
147150
);
148151
throw new CommandException($message);
149152
}
@@ -165,14 +168,14 @@ protected function gitDiff() {
165168
protected function gitClone() {
166169
$command = sprintf('git clone %s %s',
167170
$this->repo['url'],
168-
$this->shellPath($this->destination)
171+
$this->shellPath($this->repo['directory'])
169172
);
170173
$this->io->commentBlock($command);
171174

172175
$shellProcess = $this->getShellProcess();
173176

174177
if ($shellProcess->exec($command, TRUE)) {
175-
$this->io->success(sprintf('Repo cloned on %s', $this->destination));
178+
$this->io->success(sprintf('Repo cloned on %s', $this->repo['directory']));
176179
}
177180
else {
178181
throw new CommandException($shellProcess->getOutput());
@@ -192,15 +195,14 @@ protected function gitClone() {
192195
* @throws CommandException
193196
*/
194197
protected function gitCheckout() {
195-
$command = sprintf(
196-
'cd %s && ' .
197-
'git fetch --all && ' .
198-
'chmod 777 web/sites/default && ' .
199-
'chmod 777 web/sites/default/settings.php && ' .
200-
'git checkout %s --force',
201-
$this->shellPath($this->destination),
202-
$this->ref
203-
);
198+
$commands = [
199+
sprintf('cd %s', $this->shellPath($this->repo['directory'])),
200+
'git fetch --all',
201+
sprintf('chmod 777 %s/sites/default', $this->drupal_directory),
202+
sprintf('chmod 777 %s/sites/default/settings.php', $this->drupal_directory),
203+
sprintf('git checkout %s --force', $this->ref),
204+
];
205+
$command = implode(' && ', $commands);
204206

205207
$shellProcess = $this->getShellProcess();
206208

@@ -221,10 +223,10 @@ protected function gitCheckout() {
221223
* @return mixed
222224
*/
223225
protected function getCurrentRef() {
224-
if ($this->fileExists($this->destination)) {
226+
if ($this->fileExists($this->repo['directory'])) {
225227
// Get branch from site directory.
226228
$command = sprintf('cd %s && git branch',
227-
$this->shellPath($this->destination)
229+
$this->shellPath($this->repo['directory'])
228230
);
229231

230232
$shellProcess = $this->getShellProcess()->printOutput(FALSE);

src/Command/Site/ComposeCommand.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,30 @@ protected function interact(InputInterface $input, OutputInterface $output) {
4444
protected function execute(InputInterface $input, OutputInterface $output) {
4545
parent::execute($input, $output);
4646

47-
if (!$this->fileExists($this->destination . 'composer.json')) {
47+
if (!$this->fileExists(rtrim($this->config['repo']['directory'], '/') . '/composer.json')) {
4848
$message = sprintf('The file composer.json is missing on %s',
49-
$this->destination
49+
$this->config['repo']['directory']
5050
);
5151
throw new CommandException($message);
5252
}
5353

5454
// Run composer install.
55-
$this->runCommand('install', $this->destination);
55+
$this->runCommand('install');
5656
}
5757

5858
/**
5959
* Helper to run composer commands.
6060
*
6161
* @param $command The command to run.
62-
* @param $destination The destination folder.
6362
*
6463
* @return bool TRUE If successful.
6564
*
6665
* @throws CommandException
6766
*/
68-
protected function runCommand($command, $destination) {
67+
protected function runCommand($command) {
6968
$command = sprintf(
7069
'cd %s && composer %s',
71-
$this->shellPath($destination),
70+
$this->shellPath(rtrim($this->config['repo']['directory'], '/')),
7271
$command
7372
);
7473
$this->io->commentBlock($command);
@@ -77,7 +76,7 @@ protected function runCommand($command, $destination) {
7776

7877
//@todo Show a progress bar.
7978
if ($shellProcess->exec($command, TRUE)) {
80-
$this->io->success(sprintf('Composer installed on %s', $this->destination));
79+
$this->io->success(sprintf('Composer installed on %s', rtrim($this->config['repo']['directory'], '/')));
8180
}
8281
else {
8382
throw new CommandException($shellProcess->getOutput());

src/Command/Site/DbImportCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
116116
$this->filename = $this->unzip($this->filename);
117117
}
118118

119-
$this->destination = $this->settingsPhpDirectory();
119+
$this->drupal_directory = $this->settingsPhpDirectory();
120120

121121
// Override default values for these options (if empty).
122122
$override = array(
@@ -157,7 +157,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
157157
'chmod 777 settings.php && ' .
158158
'drush si -y %s %s && ' .
159159
'drush cset "system.site" uuid "$(drush cget system.site uuid --source=sync --format=list)" -y',
160-
$this->shellPath($this->destination),
160+
$this->shellPath($this->drupal_directory),
161161
$this->profile,
162162
$options
163163
);
@@ -171,7 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
171171
'cd %s; ' .
172172
'drush sql-create %s -y; ' .
173173
'drush sql-cli < %s; ',
174-
$this->destination,
174+
$this->drupal_directory,
175175
$input->getOption('db-name'),
176176
$this->filename
177177
);
@@ -187,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
187187
$this->io->writeln($shellProcess->getOutput());
188188
$this->io->success(sprintf(
189189
"Site installed on %s\nURL %s",
190-
$this->destination,
190+
$this->drupal_directory,
191191
$this->config['host']
192192
));
193193
}

src/Command/Site/DrushAliasCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
6565
parent::execute($input, $output);
6666

6767
// Remove existing file.
68-
$file = $this->destination . $this->dir . $this->filename;
68+
$file = $this->drupal_directory . $this->dir . $this->filename;
6969
if ($this->fileExists($file)) {
7070
$this->fileUnlink($file);
7171
}
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
7979
* the generic Drush alias.
8080
*/
8181
\$aliases["site"] = array (
82-
'root' => '{$this->destination}web',
82+
'root' => '{$this->drupal_directory}web',
8383
'uri' => '{$this->url}',
8484
'user' => 1,
8585
);

src/Command/Site/GruntCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4545
parent::execute($input, $output);
4646

4747
$this->io->comment(sprintf('Running Grunt on %s',
48-
$this->destination
48+
$this->drupal_directory
4949
));
5050

5151
$command = sprintf(
52-
'cd %sweb && ' .
52+
'cd %s && ' .
5353
'find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name Gruntfile.js -execdir sh -c "grunt" \;',
54-
$this->shellPath($this->destination)
54+
$this->shellPath($this->drupal_directory)
5555
);
5656

5757
// Run.

src/Command/Site/NPMCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4545
parent::execute($input, $output);
4646

4747
$this->io->comment(sprintf('Running NPM on %s',
48-
$this->destination
48+
$this->drupal_directory
4949
));
5050

5151
$command = sprintf(
52-
'cd %sweb && ' .
52+
'cd %s && ' .
5353
'find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name package.json -execdir sh -c "npm install" \;',
54-
$this->shellPath($this->destination)
54+
$this->shellPath($this->drupal_directory)
5555
);
5656

5757
// Run.

src/Command/Site/Settings/DbCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ protected function interact(InputInterface $input, OutputInterface $output) {
5858
protected function execute(InputInterface $input, OutputInterface $output) {
5959
parent::execute($input, $output);
6060

61-
$this->destination = $this->settingsPhpDirectory();
61+
$this->drupal_directory = $this->settingsPhpDirectory();
6262

6363
// Validation.
64-
if (!$this->fileExists($this->destination . 'settings.php')) {
64+
if (!$this->fileExists($this->drupal_directory . 'settings.php')) {
6565
$message = sprintf('Could not find %s',
66-
$this->destination . 'settings.php'
66+
$this->drupal_directory . 'settings.php'
6767
);
6868
throw new CommandException($message);
6969
}
@@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
8585
}
8686

8787
// Remove existing file.
88-
$file = $this->destination . $this->filename;
88+
$file = $this->drupal_directory . $this->filename;
8989
if ($this->fileExists($file)) {
9090
$this->fileUnlink($file);
9191
}

0 commit comments

Comments
 (0)