Skip to content

Commit 731ec13

Browse files
committed
Case 27689; Fix folder permissions
1 parent 53729f0 commit 731ec13

File tree

7 files changed

+57
-49
lines changed

7 files changed

+57
-49
lines changed

src/Command/Site/AbstractCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,28 @@ public function validateSiteRoot() {
429429
$settingsPath .= '/';
430430
}
431431

432+
// Fix folder permissions.
433+
$this->fixSiteFolderPermissions();
434+
432435
$this->siteRoot = $settingsPath;
433436
}
434437

438+
/**
439+
* Fixes the site folder permissions which is often changed by Drupal core.
440+
*/
441+
protected function fixSiteFolderPermissions() {
442+
if ($this->hasSiteRoot()) {
443+
$commands[] = sprintf('chmod 777 %s', $this->getSiteRoot());
444+
$commands[] = sprintf('chmod 777 %ssettings.php', $this->getSiteRoot());
445+
$command = implode(' && ', $commands);
446+
$this->io->commentBlock($command);
447+
$shellProcess = $this->getShellProcess();
448+
if (!$shellProcess->exec($command, TRUE)) {
449+
throw new CommandException($shellProcess->getOutput());
450+
}
451+
}
452+
}
453+
435454
/**
436455
* Get the shell process.
437456
*

src/Command/Site/Checkout/AbstractRefCommand.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,6 @@ protected function gitCheckout() {
195195

196196
$commands = [];
197197

198-
// Fix site folder permissions.
199-
if ($this->hasSiteRoot()) {
200-
$commands[] = sprintf('chmod 777 %s', $this->getSiteRoot());
201-
$commands[] = sprintf('chmod 777 %ssettings.php', $this->getSiteRoot());
202-
}
203-
204198
// Checkout commands.
205199
$commands[] = sprintf('cd %s', $this->shellPath($this->getRoot()));
206200
$commands[] = 'git fetch --all';

src/Command/Site/DbImportCommand.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,30 @@ protected function execute(InputInterface $input, OutputInterface $output) {
149149
// If a dump file wasn't found or not specified, do a fresh site install
150150
if (empty($this->filename) || !$this->fileExists($this->filename)) {
151151
//@todo Use drupal site:install instead of Drush.
152-
$command = sprintf(
153-
'cd %s && ' .
154-
'chmod 777 ../default && ' .
155-
'chmod 777 settings.php && ' .
156-
'drush si -y %s %s && ' .
157-
'drush cset "system.site" uuid "$(drush cget system.site uuid --source=sync --format=list)" -y',
158-
$this->shellPath($this->getSiteRoot()),
159-
$this->profile,
160-
$options
161-
);
162152
$this->io->comment('Installing site');
153+
// Site install.
154+
$commands[] = sprintf('cd %s', $this->shellPath($this->getSiteRoot()));
155+
// Install site.
156+
$commands[] = sprintf('drush si -y %s %s', $this->profile, $options);
157+
// Set site UUID from config.
158+
$commands[] = 'drush cset "system.site" uuid "$(drush cget system.site uuid --source=sync --format=list)" -y';
163159
}
164160
else {
161+
$this->io->comment('Importing dump');
162+
165163
if (is_null($input->getOption('db-name'))) {
166164
$input->setOption('db-name', $this->siteName);
167165
}
168-
$command = sprintf(
169-
'cd %s; ' .
170-
'drush sql-create %s -y; ' .
171-
'drush sql-cli < %s; ',
172-
$this->getSiteRoot(),
173-
$input->getOption('db-name'),
174-
$this->filename
175-
);
176-
$this->io->comment('Importing dump');
166+
167+
$commands[] = sprintf('cd %s', $this->shellPath($this->getSiteRoot()));
168+
// Create DB;
169+
$commands[] = sprintf('drush sql-create %s -y', $input->getOption('db-name'));
170+
// Import dump;
171+
$commands[] = sprintf('drush sql-cli < %s', $this->filename);
177172
}
178173

174+
$command = implode(' && ', $commands);
175+
179176
$this->io->commentBlock($command);
180177

181178
// Run.

src/Command/Site/GruntCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4848
$this->getWebRoot()
4949
));
5050

51-
$command = sprintf(
52-
'cd %s && ' .
53-
'find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name Gruntfile.js -execdir sh -c "grunt" \;',
51+
$commands = [];
52+
$commands[] = sprintf('cd %s', $this->shellPath($this->getWebRoot()));
53+
$commands[] = sprintf('find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name Gruntfile.js -execdir sh -c "grunt" \;',
5454
$this->shellPath($this->getWebRoot())
5555
);
56+
$command = implode(' && ', $commands);
5657

5758
// Run.
5859
$shellProcess = $this->getShellProcess();

src/Command/Site/NPMCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4848
$this->getWebRoot()
4949
));
5050

51-
$command = sprintf(
52-
'cd %s && ' .
53-
'find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name package.json -execdir sh -c "npm install" \;',
51+
$commands = [];
52+
$commands[] = sprintf('cd %s', $this->shellPath($this->getWebRoot()));
53+
$commands[] = sprintf('find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name package.json -execdir sh -c "npm install" \;',
5454
$this->shellPath($this->getWebRoot())
5555
);
56+
$command = implode(' && ', $commands);
5657

5758
// Run.
5859
$shellProcess = $this->getShellProcess();

src/Command/Site/TestCommand.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
8282
$this->getWebRoot()
8383
));
8484

85-
$command = sprintf(
86-
'cd %stests && ' .
87-
'./behat %s; ' .
88-
'cd %s; ./vendor/bin/phpunit;',
89-
$this->shellPath($this->getWebRoot()),
90-
$this->behatTags,
91-
$this->shellPath($this->getWebRoot())
92-
);
85+
$commands = [];
86+
$commands[] = sprintf('cd %s; ./vendor/bin/phpunit', $this->shellPath($this->getRoot()));
87+
$commands[] = sprintf('cd tests; ./behat %s', $this->behatTags);
88+
$command = implode(' ; ', $commands);
9389

9490
// Run.
9591
$shellProcess = $this->getShellProcess();

src/Command/Site/UpdateCommand.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4848
$this->getWebRoot()
4949
));
5050

51-
$commands = [
52-
sprintf('cd %s', $this->shellPath($this->getWebRoot())),
53-
'drush sset system.maintenance_mode 1',
54-
'drush cr',
55-
'drush updb -y',
56-
'drush cim -y',
57-
'drush cim -y',
58-
'drush sset system.maintenance_mode 0',
59-
'drush cr',
60-
];
51+
$commands = [];
52+
$commands[] = sprintf('cd %s', $this->shellPath($this->getWebRoot()));
53+
$commands[] = 'drush sset system.maintenance_mode 1';
54+
$commands[] = 'drush cr';
55+
$commands[] = 'drush updb -y';
56+
$commands[] = 'drush cim -y';
57+
$commands[] = 'drush cim -y';
58+
$commands[] = 'drush sset system.maintenance_mode 0';
59+
$commands[] = 'drush cr';
60+
6161
$command = implode(' && ', $commands);
6262

6363
// Run.

0 commit comments

Comments
 (0)