forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsCommand.php
160 lines (139 loc) · 5.43 KB
/
SettingsCommand.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace Acquia\Blt\Robo\Commands\Setup;
use Acquia\Blt\Robo\BltTasks;
use Acquia\Blt\Robo\Common\RandomString;
use Robo\Contract\VerbosityThresholdInterface;
/**
* Defines commands in the "setup:settings" namespace.
*/
class SettingsCommand extends BltTasks {
protected $defaultBehatLocalConfigFile;
protected $projectBehatLocalConfigFile;
/**
* This hook will fire for all commands in this command file.
*
* @hook init
*/
public function initialize() {
$this->defaultBehatLocalConfigFile = $this->getConfigValue('repo.root') . '/tests/behat/example.local.yml';
$this->projectBehatLocalConfigFile = $this->getConfigValue('repo.root') . '/tests/behat/local.yml';
}
/**
* Generates default settings files for Drupal and drush.
*
* @command setup:settings
*/
public function generateSiteConfigFiles() {
$this->taskFilesystemStack()
->copy($this->getConfigValue('blt.config-files.example-local'), $this->getConfigValue('blt.config-files.local'))
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
$multisites = $this->getConfigValue('multisites');
foreach ($multisites as $multisite) {
// Generate settings.php.
$multisite_dir = $this->getConfigValue('docroot') . "/sites/$multisite";
$project_default_settings_file = "$multisite_dir/default.settings.php";
$project_settings_file = "$multisite_dir/settings.php";
// Generate local.settings.php.
$blt_local_settings_file = $this->getConfigValue('blt.root') . '/settings/default.local.settings.php';
$default_local_settings_file = "$multisite_dir/settings/default.local.settings.php";
$project_local_settings_file = "$multisite_dir/settings/local.settings.php";
// Generate local.drushrc.php.
$blt_local_drush_file = $this->getConfigValue('blt.root') . '/settings/default.local.drushrc.php';
$default_local_drush_file = "$multisite_dir/default.local.drushrc.php";
$project_local_drush_file = "$multisite_dir/local.drushrc.php";
$this->taskFilesystemStack()
->chmod($multisite_dir, 0777)
// @todo Might need to check that this file exists before chmoding it.
->chmod($project_settings_file, 0777)
->copy($project_default_settings_file, $project_settings_file)
->copy($blt_local_settings_file, $default_local_settings_file)
->copy($default_local_settings_file, $project_local_settings_file)
->copy($blt_local_drush_file, $default_local_drush_file)
->copy($default_local_drush_file, $project_local_drush_file)
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
$this->getConfig()->expandFileProperties($project_local_drush_file);
$this->taskWriteToFile($project_settings_file)
->appendUnlessMatches('#vendor/acquia/blt/settings/blt.settings.php#', 'require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";')
->append(TRUE)
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
$this->taskFilesystemStack()
->chmod($project_settings_file, 0644)
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
}
}
/**
* Generates tests/behat/local.yml file for executing Behat tests locally.
*
* @command setup:behat
*/
public function behat() {
$this->say("Generating Behat configuration files...");
$this->taskFilesystemStack()
->copy($this->defaultBehatLocalConfigFile, $this->projectBehatLocalConfigFile)
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
$this->getConfig()->expandFileProperties($this->projectBehatLocalConfigFile);
}
/**
* Installs BLT git hooks to local .git/hooks directory.
*
* @command setup:git-hooks
*/
public function gitHooks() {
foreach (['pre-commit', 'commit-msg'] as $hook) {
$this->installGitHook($hook);
}
}
/**
* Installs a given git hook.
*
* This symlinks the hook into the project's .git/hooks directory.
*
* @param string $hook
* The git hook to install. E.g., 'pre-commit'.
*/
protected function installGitHook($hook) {
if ($this->getConfigValue('git.hooks.' . $hook)) {
$this->say("Installing $hook git hook...");
$source = $this->getConfigValue('git.hooks.' . $hook) . "/$hook";
$dest = $this->getConfigValue('repo.root') . "/.git/hooks/$hook";
$this->taskFilesystemStack()
->mkdir($this->getConfigValue('repo.root') . '/.git/hooks')
->remove($dest)
->symlink($source, $dest)
->stopOnFail()
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->run();
}
else {
$this->say("Skipping installation of $hook git hook");
}
}
/**
* Writes a hash salt to ${repo.root}/salt.txt if one does not exist.
*
* @command setup:hash-salt
*
* @return int
* A CLI exit code.
*/
public function hashSalt() {
$hash_salt_file = $this->getConfigValue('repo.root') . '/salt.txt';
if (!file_exists($hash_salt_file)) {
$this->say("Writing hash salt to $hash_salt_file");
$result = $this->taskWriteToFile($hash_salt_file)
->line(RandomString::string(55))
->run();
return $result->wasSuccessful();
}
return TRUE;
}
}