Skip to content

Commit 62e990a

Browse files
committed
Case 27689; introduced new siteRoot property
1 parent e56ea8c commit 62e990a

File tree

12 files changed

+54
-41
lines changed

12 files changed

+54
-41
lines changed

src/Command/Site/AbstractCommand.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,16 @@ abstract class AbstractCommand extends Command {
8383
*
8484
* @var string
8585
*/
86-
protected $web_root = NULL;
86+
protected $webRoot = NULL;
87+
88+
/**
89+
* The site root directory.
90+
*
91+
* This is where we put settings.php
92+
*
93+
* @var string
94+
*/
95+
protected $siteRoot = NULL;
8796

8897
/**
8998
* Stores the site url.
@@ -195,6 +204,9 @@ protected function validateSiteParams(InputInterface $input, OutputInterface $ou
195204
// Validate web root.
196205
$this->validateWebRoot();
197206

207+
// Validate settings.php directory.
208+
$this->validateSiteRoot();
209+
198210
// Validate url.
199211
$this->validateUrl($input);
200212
}
@@ -268,7 +280,8 @@ protected function validateProfile(InputInterface $input) {
268280
* Validate and set the web root directory.
269281
*/
270282
protected function validateWebRoot() {
271-
$this->web_root = $this->root . trim($this->config['web_directory'], '/') . '/';
283+
$web_directory = empty($this->config['web_directory']) ? 'web' : $this->config['web_directory'];
284+
$this->webRoot = $this->root . trim($web_directory, '/') . '/';
272285
}
273286

274287
/**
@@ -326,16 +339,25 @@ protected function validateUrl(InputInterface $input) {
326339
}
327340

328341
/**
329-
* Helper to return the path to settings.php
342+
* Helper to set the site root.
343+
*
344+
* This is where we place settings.php
345+
*
330346
* It will try to match a folder with same name as site name
331347
* If not found, it will try to match a folder called "default".
332348
*
333349
* @return string Path
334350
*/
335-
public function settingsPhpDirectory() {
336-
$webSitesPath = $this->web_root . 'sites/';
351+
public function validateSiteRoot() {
352+
$webSitesPath = $this->webRoot . 'sites/';
337353
$settingsPath = $webSitesPath . 'default';
338354

355+
// It's possible that a command is run before the site is available. e.g. checkout
356+
// We will skip setting in this situation, but throw an Exception in the site root getter to prevent any unpredictable behaviour.
357+
if (!file_exists($settingsPath)) {
358+
return;
359+
}
360+
339361
$command = sprintf(
340362
'cd %s && find . -name settings.php',
341363
$this->shellPath($webSitesPath)
@@ -368,7 +390,7 @@ public function settingsPhpDirectory() {
368390
$settingsPath .= '/';
369391
}
370392

371-
return $settingsPath;
393+
$this->siteRoot = $settingsPath;
372394
}
373395

374396
/**

src/Command/Site/AbstractConfigCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ protected function configure() {
7979
*/
8080
protected function interact(InputInterface $input, OutputInterface $output) {
8181
parent::interact($input, $output);
82-
8382
}
8483

8584
/**

src/Command/Site/Checkout/AbstractRefCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ protected function gitCheckout() {
195195
$commands = [
196196
sprintf('cd %s', $this->shellPath($this->root)),
197197
'git fetch --all',
198-
sprintf('chmod 777 %ssites/default', $this->web_root),
199-
sprintf('chmod 777 %ssites/default/settings.php', $this->web_root),
198+
sprintf('chmod 777 %ssites/default', $this->webRoot),
199+
sprintf('chmod 777 %ssites/default/settings.php', $this->webRoot),
200200
sprintf('git checkout %s --force', $this->ref),
201201
];
202202
$command = implode(' && ', $commands);

src/Command/Site/DbImportCommand.php

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

119-
$this->web_root = $this->settingsPhpDirectory();
120-
121119
// Override default values for these options (if empty).
122120
$override = array(
123121
'account-name' => $this->config['account-name'],
@@ -157,7 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
157155
'chmod 777 settings.php && ' .
158156
'drush si -y %s %s && ' .
159157
'drush cset "system.site" uuid "$(drush cget system.site uuid --source=sync --format=list)" -y',
160-
$this->shellPath($this->web_root),
158+
$this->shellPath($this->siteRoot),
161159
$this->profile,
162160
$options
163161
);
@@ -171,7 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
171169
'cd %s; ' .
172170
'drush sql-create %s -y; ' .
173171
'drush sql-cli < %s; ',
174-
$this->web_root,
172+
$this->siteRoot,
175173
$input->getOption('db-name'),
176174
$this->filename
177175
);
@@ -187,7 +185,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
187185
$this->io->writeln($shellProcess->getOutput());
188186
$this->io->success(sprintf(
189187
"Site installed on %s\nURL %s",
190-
$this->web_root,
188+
$this->siteRoot,
191189
$this->config['host']
192190
));
193191
}

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->web_root . $this->dir . $this->filename;
68+
$file = $this->webRoot . $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->web_root}',
82+
'root' => '{$this->webRoot}',
8383
'uri' => '{$this->url}',
8484
'user' => 1,
8585
);

src/Command/Site/GruntCommand.php

Lines changed: 2 additions & 2 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->web_root
48+
$this->webRoot
4949
));
5050

5151
$command = sprintf(
5252
'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->web_root)
54+
$this->shellPath($this->webRoot)
5555
);
5656

5757
// Run.

src/Command/Site/NPMCommand.php

Lines changed: 2 additions & 2 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->web_root
48+
$this->webRoot
4949
));
5050

5151
$command = sprintf(
5252
'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->web_root)
54+
$this->shellPath($this->webRoot)
5555
);
5656

5757
// Run.

src/Command/Site/Settings/DbCommand.php

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

61-
$this->web_root = $this->settingsPhpDirectory();
62-
6361
// Validation.
64-
if (!$this->fileExists($this->web_root . 'settings.php')) {
62+
if (!$this->fileExists($this->siteRoot . 'settings.php')) {
6563
$message = sprintf('Could not find %s',
66-
$this->web_root . 'settings.php'
64+
$this->siteRoot . 'settings.php'
6765
);
6866
throw new CommandException($message);
6967
}
@@ -85,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
8583
}
8684

8785
// Remove existing file.
88-
$file = $this->web_root . $this->filename;
86+
$file = $this->siteRoot . $this->filename;
8987
if ($this->fileExists($file)) {
9088
$this->fileUnlink($file);
9189
}

src/Command/Site/Settings/LocalCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,23 @@ protected function interact(InputInterface $input, OutputInterface $output) {
5353
protected function execute(InputInterface $input, OutputInterface $output) {
5454
parent::execute($input, $output);
5555

56-
$this->web_root = $this->settingsPhpDirectory();
57-
5856
// Validation.
59-
if (!$this->fileExists($this->web_root . '../example.' . $this->filename)) {
57+
if (!$this->fileExists($this->siteRoot . '../example.' . $this->filename)) {
6058
$message = sprintf('The file example.settings.local.php is missing.',
61-
$this->web_root
59+
$this->siteRoot
6260
);
6361
throw new CommandException($message);
6462
}
6563

6664
// Remove existing file.
67-
$file = $this->web_root . $this->filename;
65+
$file = $this->siteRoot . $this->filename;
6866
if ($this->fileExists($file)) {
6967
$this->fileUnlink($file);
7068
}
7169

7270
// Copy example.
7371
$command = sprintf('cd %s && cp -n ../example.%s %s',
74-
$this->shellPath($this->web_root),
72+
$this->shellPath($this->siteRoot),
7573
$this->filename,
7674
$this->filename
7775
);

src/Command/Site/Settings/MemcacheCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ protected function interact(InputInterface $input, OutputInterface $output) {
6363
protected function execute(InputInterface $input, OutputInterface $output) {
6464
parent::execute($input, $output);
6565

66-
$this->web_root = $this->settingsPhpDirectory();
67-
6866
// Validation.
69-
if (!$this->fileExists($this->web_root . 'settings.php')) {
67+
if (!$this->fileExists($this->siteRoot . 'settings.php')) {
7068
$message = sprintf('The file settings.php is missing on %s',
71-
$this->web_root
69+
$this->siteRoot
7270
);
7371
throw new CommandException($message);
7472
}
@@ -78,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
7876
}
7977

8078
// Remove existing file.
81-
$file = $this->web_root . $this->filename;
79+
$file = $this->siteRoot . $this->filename;
8280
if ($this->fileExists($file)) {
8381
$this->fileUnlink($file);
8482
}

0 commit comments

Comments
 (0)