-
Notifications
You must be signed in to change notification settings - Fork 396
/
BuildCommand.php
113 lines (101 loc) · 3.08 KB
/
BuildCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Acquia\Blt\Robo\Commands\Setup;
use Acquia\Blt\Robo\BltTasks;
use Acquia\Blt\Robo\Exceptions\BltException;
use Robo\Contract\VerbosityThresholdInterface;
use Symfony\Component\Finder\Finder;
/**
* Defines commands in the "source:build" namespace.
*/
class BuildCommand extends BltTasks {
/**
* Installs Drupal and sets correct file/directory permissions.
*
* @command drupal:install
*
* @aliases di setup:drupal:install
*
* @interactGenerateSettingsFiles
*
* @validateDrushConfig
* @validateMySqlAvailable
* @validateDocrootIsPresent
* @executeInVm
*
* @todo Add a @validateSettingsFilesArePresent
*/
public function drupalInstall() {
$commands = ['internal:drupal:install'];
$strategy = $this->getConfigValue('cm.strategy');
if (in_array($strategy, ['config-split', 'features'])) {
$commands[] = 'drupal:config:import';
}
$this->invokeCommands($commands);
$this->setSitePermissions();
}
/**
* Set correct permissions for directories (755) and files (644) in
* docroot/sites/[site] (excluding docroot/sites/[site]/files).
*/
protected function setSitePermissions() {
$taskFilesystemStack = $this->taskFilesystemStack();
$multisite_dir = $this->getConfigValue('docroot') . '/sites/' . $this->getConfigValue('site');
$finder = new Finder();
$dirs = $finder
->in($multisite_dir)
->directories()
->depth('< 1')
->exclude('files');
foreach ($dirs->getIterator() as $dir) {
$taskFilesystemStack->chmod($dir->getRealPath(), 0755);
}
$files = $finder
->in($multisite_dir)
->files()
->depth('< 1')
->exclude('files');
foreach ($files->getIterator() as $file) {
$taskFilesystemStack->chmod($file->getRealPath(), 0644);
}
$taskFilesystemStack->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE);
$result = $taskFilesystemStack->run();
if (!$result->wasSuccessful()) {
throw new BltException("Unable to set permissions for site directories and files.");
}
}
/**
* Generates all required files for a full build.
*
* @command source:build
*
* @aliases sb setup:build
*
* @interactConfigIdentical
*/
public function build() {
$this->invokeCommands([
'tests:behat:init:config',
// source:build:composer must run prior to blt:init:settings to ensure
// that scaffold files are present.
'source:build:composer',
'blt:init:git-hooks',
'blt:init:settings',
'source:build:frontend',
]);
$this->invokeHook("post-setup-build");
}
/**
* Installs Composer dependencies.
*
* @command source:build:composer
* @aliases sbc setup:composer:install
*/
public function composerInstall() {
$result = $this->taskExec("export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --ansi --no-interaction")
->dir($this->getConfigValue('repo.root'))
->interactive($this->input()->isInteractive())
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
return $result;
}
}