Skip to content

Commit e56ea8c

Browse files
committed
Case 27689; tidying up handling of directory paths
1 parent a575410 commit e56ea8c

14 files changed

+87
-75
lines changed

chain/chain-site-configure.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ 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: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,20 @@ abstract class AbstractCommand extends Command {
7070
protected $profile = NULL;
7171

7272
/**
73-
* The Drupal core directory.
73+
* The root directory.
7474
*
7575
* @var string
7676
*/
77-
protected $drupal_directory = NULL;
77+
protected $root = NULL;
78+
79+
/**
80+
* The web root directory.
81+
*
82+
* This is the web directory within the root.
83+
*
84+
* @var string
85+
*/
86+
protected $web_root = NULL;
7887

7988
/**
8089
* Stores the site url.
@@ -180,8 +189,11 @@ protected function validateSiteParams(InputInterface $input, OutputInterface $ou
180189
// Validate profile.
181190
$this->validateProfile($input);
182191

183-
// Validate destination.
184-
$this->validateDestination($input);
192+
// Validate root.
193+
$this->validateRoot($input);
194+
195+
// Validate web root.
196+
$this->validateWebRoot();
185197

186198
// Validate url.
187199
$this->validateUrl($input);
@@ -253,51 +265,50 @@ protected function validateProfile(InputInterface $input) {
253265
}
254266

255267
/**
256-
* Helper to validate destination parameter.
268+
* Validate and set the web root directory.
269+
*/
270+
protected function validateWebRoot() {
271+
$this->web_root = $this->root . trim($this->config['web_directory'], '/') . '/';
272+
}
273+
274+
/**
275+
* Validate and set the root directory.
257276
*
258277
* @param InputInterface $input
259-
*
260-
* @throws CommandException
261-
*
262-
* @return string Destination
278+
* @return string
263279
*/
264-
protected function validateDestination(InputInterface $input) {
280+
protected function validateRoot(InputInterface $input) {
265281
if ($input->hasOption('destination-directory') &&
266282
!is_null($input->getOption('destination-directory'))
267283
) {
268284
// Use config from parameter.
269-
$this->drupal_directory = $input->getOption('destination-directory');
285+
$this->root = $input->getOption('destination-directory');
270286
}
271-
elseif (isset($this->config['repo']['directory'])) {
287+
elseif (isset($this->config['root'])) {
272288
// Use config from sites.yml.
273-
$this->drupal_directory = $this->config['repo']['directory'];
289+
$this->root = $this->config['root'];
274290
}
275291
else {
276-
$this->drupal_directory = '/tmp/' . $this->siteName;
292+
$this->root = '/tmp/' . $this->siteName;
277293
}
278294

279295
// Allow destination to be overriden by environment variable. i.e.
280296
// export site_destination_directory="/directory/"
281297
if (!getenv('site_destination_directory')) {
282-
putenv("site_destination_directory=$this->drupal_directory");
298+
putenv("site_destination_directory=$this->root");
283299
}
284300
else {
285-
$this->drupal_directory = getenv('site_destination_directory');
301+
$this->root = getenv('site_destination_directory');
286302
}
287303

288-
$this->drupal_directory = rtrim($this->drupal_directory, '/') . '/' . trim($this->config['core_directory'], '/') . '/';
289-
290-
return $this->drupal_directory;
304+
$this->root = rtrim($this->root, '/') . '/';
291305
}
292306

293307
/**
294-
* Helper to validate destination parameter.
308+
* Helper to validate URL.
295309
*
296310
* @param InputInterface $input
297-
*
298-
* @throws CommandException
299-
*
300-
* @return string Destination
311+
* @return string
301312
*/
302313
protected function validateUrl(InputInterface $input) {
303314
$scheme = isset($this->config['scheme']) && !empty($this->config['scheme']) ? $this->config['scheme'] : 'http';
@@ -322,7 +333,7 @@ protected function validateUrl(InputInterface $input) {
322333
* @return string Path
323334
*/
324335
public function settingsPhpDirectory() {
325-
$webSitesPath = $this->drupal_directory . '/sites/';
336+
$webSitesPath = $this->web_root . 'sites/';
326337
$settingsPath = $webSitesPath . 'default';
327338

328339
$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->drupal_directory . $this->template;
101-
$this->filename = $this->drupal_directory . $this->filename;
100+
$this->template = $this->root . $this->template;
101+
$this->filename = $this->root . $this->filename;
102102

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

src/Command/Site/Checkout/AbstractRefCommand.php

Lines changed: 12 additions & 15 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->repo['directory']
76+
$this->root
7777
));
7878

7979
switch ($this->repo['type']) {
8080
case 'git':
8181
// Check if repo exists and has any changes.
82-
if ($this->fileExists($this->repo['directory']) &&
83-
$this->fileExists($this->repo['directory'] . '.' . $this->repo['type'])
82+
if ($this->fileExists($this->root) &&
83+
$this->fileExists($this->root . '.' . $this->repo['type'])
8484
) {
8585
if ($input->hasOption('force') &&
8686
!$input->getOption('force')
@@ -111,13 +111,10 @@ 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.
116114
*/
117115
protected function validateRepo() {
118116
if (isset($this->config['repo'])) {
119117
$this->repo = $this->config['repo'];
120-
$this->repo['directory'] = rtrim($this->repo['directory'], '/') . '/';
121118
}
122119
else {
123120
throw new CommandException('Repo not found in sites.yml');
@@ -136,7 +133,7 @@ protected function validateRepo() {
136133
protected function gitDiff() {
137134
$command = sprintf(
138135
'cd %s && git diff-files --name-status -r --ignore-submodules',
139-
$this->shellPath($this->repo['directory'])
136+
$this->shellPath($this->root)
140137
);
141138

142139
$shellProcess = $this->getShellProcess();
@@ -146,7 +143,7 @@ protected function gitDiff() {
146143
$message = sprintf('You have uncommitted changes on %s' . PHP_EOL .
147144
'Please commit or revert your changes before checking out the site.' . PHP_EOL .
148145
'If you want to wipe your local changes use --force.',
149-
$this->repo['directory']
146+
$this->root
150147
);
151148
throw new CommandException($message);
152149
}
@@ -168,14 +165,14 @@ protected function gitDiff() {
168165
protected function gitClone() {
169166
$command = sprintf('git clone %s %s',
170167
$this->repo['url'],
171-
$this->shellPath($this->repo['directory'])
168+
$this->shellPath($this->root)
172169
);
173170
$this->io->commentBlock($command);
174171

175172
$shellProcess = $this->getShellProcess();
176173

177174
if ($shellProcess->exec($command, TRUE)) {
178-
$this->io->success(sprintf('Repo cloned on %s', $this->repo['directory']));
175+
$this->io->success(sprintf('Repo cloned on %s', $this->root));
179176
}
180177
else {
181178
throw new CommandException($shellProcess->getOutput());
@@ -196,10 +193,10 @@ protected function gitClone() {
196193
*/
197194
protected function gitCheckout() {
198195
$commands = [
199-
sprintf('cd %s', $this->shellPath($this->repo['directory'])),
196+
sprintf('cd %s', $this->shellPath($this->root)),
200197
'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),
198+
sprintf('chmod 777 %ssites/default', $this->web_root),
199+
sprintf('chmod 777 %ssites/default/settings.php', $this->web_root),
203200
sprintf('git checkout %s --force', $this->ref),
204201
];
205202
$command = implode(' && ', $commands);
@@ -223,10 +220,10 @@ protected function gitCheckout() {
223220
* @return mixed
224221
*/
225222
protected function getCurrentRef() {
226-
if ($this->fileExists($this->repo['directory'])) {
223+
if ($this->fileExists($this->root)) {
227224
// Get branch from site directory.
228225
$command = sprintf('cd %s && git branch',
229-
$this->shellPath($this->repo['directory'])
226+
$this->shellPath($this->root)
230227
);
231228

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

src/Command/Site/ComposeCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ 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(rtrim($this->config['repo']['directory'], '/') . '/composer.json')) {
47+
if (!$this->fileExists($this->root . 'composer.json')) {
4848
$message = sprintf('The file composer.json is missing on %s',
49-
$this->config['repo']['directory']
49+
$this->root
5050
);
5151
throw new CommandException($message);
5252
}
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
6767
protected function runCommand($command) {
6868
$command = sprintf(
6969
'cd %s && composer %s',
70-
$this->shellPath(rtrim($this->config['repo']['directory'], '/')),
70+
$this->shellPath($this->root),
7171
$command
7272
);
7373
$this->io->commentBlock($command);
@@ -76,7 +76,7 @@ protected function runCommand($command) {
7676

7777
//@todo Show a progress bar.
7878
if ($shellProcess->exec($command, TRUE)) {
79-
$this->io->success(sprintf('Composer installed on %s', rtrim($this->config['repo']['directory'], '/')));
79+
$this->io->success(sprintf('Composer installed on %s', $this->root));
8080
}
8181
else {
8282
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->drupal_directory = $this->settingsPhpDirectory();
119+
$this->web_root = $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->drupal_directory),
160+
$this->shellPath($this->web_root),
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->drupal_directory,
174+
$this->web_root,
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->drupal_directory,
190+
$this->web_root,
191191
$this->config['host']
192192
));
193193
}

src/Command/Site/DrushAliasCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DrushAliasCommand extends AbstractCommand {
3535
*
3636
* @var
3737
*/
38-
protected $dir = 'web/sites/all/drush/site-aliases/';
38+
protected $dir = 'sites/all/drush/site-aliases/';
3939

4040
/**
4141
* {@inheritdoc}
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
6565
parent::execute($input, $output);
6666

6767
// Remove existing file.
68-
$file = $this->drupal_directory . $this->dir . $this->filename;
68+
$file = $this->web_root . $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->drupal_directory}web',
82+
'root' => '{$this->web_root}',
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->drupal_directory
48+
$this->web_root
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->drupal_directory)
54+
$this->shellPath($this->web_root)
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->drupal_directory
48+
$this->web_root
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->drupal_directory)
54+
$this->shellPath($this->web_root)
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->drupal_directory = $this->settingsPhpDirectory();
61+
$this->web_root = $this->settingsPhpDirectory();
6262

6363
// Validation.
64-
if (!$this->fileExists($this->drupal_directory . 'settings.php')) {
64+
if (!$this->fileExists($this->web_root . 'settings.php')) {
6565
$message = sprintf('Could not find %s',
66-
$this->drupal_directory . 'settings.php'
66+
$this->web_root . '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->drupal_directory . $this->filename;
88+
$file = $this->web_root . $this->filename;
8989
if ($this->fileExists($file)) {
9090
$this->fileUnlink($file);
9191
}

0 commit comments

Comments
 (0)