Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * API functions for installing modules and themes.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@18
|
8 use Drupal\Core\Extension\Dependency;
|
Chris@0
|
9 use Drupal\Component\Utility\Unicode;
|
Chris@18
|
10 use Drupal\Core\File\FileSystemInterface;
|
Chris@0
|
11 use Symfony\Component\HttpFoundation\RedirectResponse;
|
Chris@0
|
12 use Drupal\Component\Utility\Crypt;
|
Chris@0
|
13 use Drupal\Component\Utility\OpCodeCache;
|
Chris@0
|
14 use Drupal\Component\Utility\UrlHelper;
|
Chris@0
|
15 use Drupal\Core\Extension\ExtensionDiscovery;
|
Chris@17
|
16 use Drupal\Core\Extension\ModuleHandler;
|
Chris@0
|
17 use Drupal\Core\Site\Settings;
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * Requirement severity -- Informational message only.
|
Chris@0
|
21 */
|
Chris@0
|
22 const REQUIREMENT_INFO = -1;
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * Requirement severity -- Requirement successfully met.
|
Chris@0
|
26 */
|
Chris@0
|
27 const REQUIREMENT_OK = 0;
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Requirement severity -- Warning condition; proceed but flag warning.
|
Chris@0
|
31 */
|
Chris@0
|
32 const REQUIREMENT_WARNING = 1;
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Requirement severity -- Error condition; abort installation.
|
Chris@0
|
36 */
|
Chris@0
|
37 const REQUIREMENT_ERROR = 2;
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * File permission check -- File exists.
|
Chris@0
|
41 */
|
Chris@0
|
42 const FILE_EXIST = 1;
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * File permission check -- File is readable.
|
Chris@0
|
46 */
|
Chris@0
|
47 const FILE_READABLE = 2;
|
Chris@0
|
48
|
Chris@0
|
49 /**
|
Chris@0
|
50 * File permission check -- File is writable.
|
Chris@0
|
51 */
|
Chris@0
|
52 const FILE_WRITABLE = 4;
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * File permission check -- File is executable.
|
Chris@0
|
56 */
|
Chris@0
|
57 const FILE_EXECUTABLE = 8;
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * File permission check -- File does not exist.
|
Chris@0
|
61 */
|
Chris@0
|
62 const FILE_NOT_EXIST = 16;
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * File permission check -- File is not readable.
|
Chris@0
|
66 */
|
Chris@0
|
67 const FILE_NOT_READABLE = 32;
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * File permission check -- File is not writable.
|
Chris@0
|
71 */
|
Chris@0
|
72 const FILE_NOT_WRITABLE = 64;
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * File permission check -- File is not executable.
|
Chris@0
|
76 */
|
Chris@0
|
77 const FILE_NOT_EXECUTABLE = 128;
|
Chris@0
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * Loads .install files for installed modules to initialize the update system.
|
Chris@0
|
81 */
|
Chris@0
|
82 function drupal_load_updates() {
|
Chris@0
|
83 foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) {
|
Chris@0
|
84 if ($schema_version > -1) {
|
Chris@0
|
85 module_load_install($module);
|
Chris@0
|
86 }
|
Chris@0
|
87 }
|
Chris@0
|
88 }
|
Chris@0
|
89
|
Chris@0
|
90 /**
|
Chris@0
|
91 * Loads the installation profile, extracting its defined distribution name.
|
Chris@0
|
92 *
|
Chris@0
|
93 * @return
|
Chris@0
|
94 * The distribution name defined in the profile's .info.yml file. Defaults to
|
Chris@0
|
95 * "Drupal" if none is explicitly provided by the installation profile.
|
Chris@0
|
96 *
|
Chris@0
|
97 * @see install_profile_info()
|
Chris@0
|
98 */
|
Chris@0
|
99 function drupal_install_profile_distribution_name() {
|
Chris@0
|
100 // During installation, the profile information is stored in the global
|
Chris@0
|
101 // installation state (it might not be saved anywhere yet).
|
Chris@0
|
102 $info = [];
|
Chris@0
|
103 if (drupal_installation_attempted()) {
|
Chris@0
|
104 global $install_state;
|
Chris@0
|
105 if (isset($install_state['profile_info'])) {
|
Chris@0
|
106 $info = $install_state['profile_info'];
|
Chris@0
|
107 }
|
Chris@0
|
108 }
|
Chris@0
|
109 // At all other times, we load the profile via standard methods.
|
Chris@0
|
110 else {
|
Chris@0
|
111 $profile = drupal_get_profile();
|
Chris@0
|
112 $info = system_get_info('module', $profile);
|
Chris@0
|
113 }
|
Chris@0
|
114 return isset($info['distribution']['name']) ? $info['distribution']['name'] : 'Drupal';
|
Chris@0
|
115 }
|
Chris@0
|
116
|
Chris@0
|
117 /**
|
Chris@0
|
118 * Loads the installation profile, extracting its defined version.
|
Chris@0
|
119 *
|
Chris@0
|
120 * @return string
|
Chris@0
|
121 * Distribution version defined in the profile's .info.yml file.
|
Chris@0
|
122 * Defaults to \Drupal::VERSION if no version is explicitly provided by the
|
Chris@0
|
123 * installation profile.
|
Chris@0
|
124 *
|
Chris@0
|
125 * @see install_profile_info()
|
Chris@0
|
126 */
|
Chris@0
|
127 function drupal_install_profile_distribution_version() {
|
Chris@0
|
128 // During installation, the profile information is stored in the global
|
Chris@0
|
129 // installation state (it might not be saved anywhere yet).
|
Chris@0
|
130 if (drupal_installation_attempted()) {
|
Chris@0
|
131 global $install_state;
|
Chris@0
|
132 return isset($install_state['profile_info']['version']) ? $install_state['profile_info']['version'] : \Drupal::VERSION;
|
Chris@0
|
133 }
|
Chris@0
|
134 // At all other times, we load the profile via standard methods.
|
Chris@0
|
135 else {
|
Chris@0
|
136 $profile = drupal_get_profile();
|
Chris@0
|
137 $info = system_get_info('module', $profile);
|
Chris@0
|
138 return $info['version'];
|
Chris@0
|
139 }
|
Chris@0
|
140 }
|
Chris@0
|
141
|
Chris@0
|
142 /**
|
Chris@0
|
143 * Detects all supported databases that are compiled into PHP.
|
Chris@0
|
144 *
|
Chris@0
|
145 * @return
|
Chris@0
|
146 * An array of database types compiled into PHP.
|
Chris@0
|
147 */
|
Chris@0
|
148 function drupal_detect_database_types() {
|
Chris@0
|
149 $databases = drupal_get_database_types();
|
Chris@0
|
150
|
Chris@0
|
151 foreach ($databases as $driver => $installer) {
|
Chris@0
|
152 $databases[$driver] = $installer->name();
|
Chris@0
|
153 }
|
Chris@0
|
154
|
Chris@0
|
155 return $databases;
|
Chris@0
|
156 }
|
Chris@0
|
157
|
Chris@0
|
158 /**
|
Chris@0
|
159 * Returns all supported database driver installer objects.
|
Chris@0
|
160 *
|
Chris@0
|
161 * @return \Drupal\Core\Database\Install\Tasks[]
|
Chris@0
|
162 * An array of available database driver installer objects.
|
Chris@0
|
163 */
|
Chris@0
|
164 function drupal_get_database_types() {
|
Chris@0
|
165 $databases = [];
|
Chris@0
|
166 $drivers = [];
|
Chris@0
|
167
|
Chris@0
|
168 // The internal database driver name is any valid PHP identifier.
|
Chris@0
|
169 $mask = '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '$/';
|
Chris@0
|
170 $files = file_scan_directory(DRUPAL_ROOT . '/core/lib/Drupal/Core/Database/Driver', $mask, ['recurse' => FALSE]);
|
Chris@0
|
171 if (is_dir(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database')) {
|
Chris@0
|
172 $files += file_scan_directory(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database/', $mask, ['recurse' => FALSE]);
|
Chris@0
|
173 }
|
Chris@0
|
174 foreach ($files as $file) {
|
Chris@0
|
175 if (file_exists($file->uri . '/Install/Tasks.php')) {
|
Chris@0
|
176 $drivers[$file->filename] = $file->uri;
|
Chris@0
|
177 }
|
Chris@0
|
178 }
|
Chris@0
|
179 foreach ($drivers as $driver => $file) {
|
Chris@0
|
180 $installer = db_installer_object($driver);
|
Chris@0
|
181 if ($installer->installable()) {
|
Chris@0
|
182 $databases[$driver] = $installer;
|
Chris@0
|
183 }
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 // Usability: unconditionally put the MySQL driver on top.
|
Chris@0
|
187 if (isset($databases['mysql'])) {
|
Chris@0
|
188 $mysql_database = $databases['mysql'];
|
Chris@0
|
189 unset($databases['mysql']);
|
Chris@0
|
190 $databases = ['mysql' => $mysql_database] + $databases;
|
Chris@0
|
191 }
|
Chris@0
|
192
|
Chris@0
|
193 return $databases;
|
Chris@0
|
194 }
|
Chris@0
|
195
|
Chris@0
|
196 /**
|
Chris@0
|
197 * Replaces values in settings.php with values in the submitted array.
|
Chris@0
|
198 *
|
Chris@0
|
199 * This function replaces values in place if possible, even for
|
Chris@0
|
200 * multidimensional arrays. This way the old settings do not linger,
|
Chris@0
|
201 * overridden and also the doxygen on a value remains where it should be.
|
Chris@0
|
202 *
|
Chris@0
|
203 * @param $settings
|
Chris@0
|
204 * An array of settings that need to be updated. Multidimensional arrays
|
Chris@0
|
205 * are dumped up to a stdClass object. The object can have value, required
|
Chris@0
|
206 * and comment properties.
|
Chris@0
|
207 * @code
|
Chris@0
|
208 * $settings['config_directories'] = array(
|
Chris@0
|
209 * CONFIG_SYNC_DIRECTORY => (object) array(
|
Chris@0
|
210 * 'value' => 'config_hash/sync',
|
Chris@0
|
211 * 'required' => TRUE,
|
Chris@0
|
212 * ),
|
Chris@0
|
213 * );
|
Chris@0
|
214 * @endcode
|
Chris@0
|
215 * gets dumped as:
|
Chris@0
|
216 * @code
|
Chris@0
|
217 * $config_directories['sync'] = 'config_hash/sync'
|
Chris@0
|
218 * @endcode
|
Chris@0
|
219 */
|
Chris@0
|
220 function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
|
Chris@0
|
221 if (!isset($settings_file)) {
|
Chris@0
|
222 $settings_file = \Drupal::service('site.path') . '/settings.php';
|
Chris@0
|
223 }
|
Chris@0
|
224 // Build list of setting names and insert the values into the global namespace.
|
Chris@0
|
225 $variable_names = [];
|
Chris@0
|
226 $settings_settings = [];
|
Chris@0
|
227 foreach ($settings as $setting => $data) {
|
Chris@0
|
228 if ($setting != 'settings') {
|
Chris@0
|
229 _drupal_rewrite_settings_global($GLOBALS[$setting], $data);
|
Chris@0
|
230 }
|
Chris@0
|
231 else {
|
Chris@0
|
232 _drupal_rewrite_settings_global($settings_settings, $data);
|
Chris@0
|
233 }
|
Chris@0
|
234 $variable_names['$' . $setting] = $setting;
|
Chris@0
|
235 }
|
Chris@0
|
236 $contents = file_get_contents($settings_file);
|
Chris@0
|
237 if ($contents !== FALSE) {
|
Chris@0
|
238 // Initialize the contents for the settings.php file if it is empty.
|
Chris@0
|
239 if (trim($contents) === '') {
|
Chris@0
|
240 $contents = "<?php\n";
|
Chris@0
|
241 }
|
Chris@0
|
242 // Step through each token in settings.php and replace any variables that
|
Chris@0
|
243 // are in the passed-in array.
|
Chris@0
|
244 $buffer = '';
|
Chris@0
|
245 $state = 'default';
|
Chris@0
|
246 foreach (token_get_all($contents) as $token) {
|
Chris@0
|
247 if (is_array($token)) {
|
Chris@0
|
248 list($type, $value) = $token;
|
Chris@0
|
249 }
|
Chris@0
|
250 else {
|
Chris@0
|
251 $type = -1;
|
Chris@0
|
252 $value = $token;
|
Chris@0
|
253 }
|
Chris@0
|
254 // Do not operate on whitespace.
|
Chris@0
|
255 if (!in_array($type, [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
|
Chris@0
|
256 switch ($state) {
|
Chris@0
|
257 case 'default':
|
Chris@0
|
258 if ($type === T_VARIABLE && isset($variable_names[$value])) {
|
Chris@0
|
259 // This will be necessary to unset the dumped variable.
|
Chris@0
|
260 $parent = &$settings;
|
Chris@0
|
261 // This is the current index in parent.
|
Chris@0
|
262 $index = $variable_names[$value];
|
Chris@0
|
263 // This will be necessary for descending into the array.
|
Chris@0
|
264 $current = &$parent[$index];
|
Chris@0
|
265 $state = 'candidate_left';
|
Chris@0
|
266 }
|
Chris@0
|
267 break;
|
Chris@0
|
268 case 'candidate_left':
|
Chris@0
|
269 if ($value == '[') {
|
Chris@0
|
270 $state = 'array_index';
|
Chris@0
|
271 }
|
Chris@0
|
272 if ($value == '=') {
|
Chris@0
|
273 $state = 'candidate_right';
|
Chris@0
|
274 }
|
Chris@0
|
275 break;
|
Chris@0
|
276 case 'array_index':
|
Chris@0
|
277 if (_drupal_rewrite_settings_is_array_index($type, $value)) {
|
Chris@0
|
278 $index = trim($value, '\'"');
|
Chris@0
|
279 $state = 'right_bracket';
|
Chris@0
|
280 }
|
Chris@0
|
281 else {
|
Chris@0
|
282 // $a[foo()] or $a[$bar] or something like that.
|
Chris@0
|
283 throw new Exception('invalid array index');
|
Chris@0
|
284 }
|
Chris@0
|
285 break;
|
Chris@0
|
286 case 'right_bracket':
|
Chris@0
|
287 if ($value == ']') {
|
Chris@0
|
288 if (isset($current[$index])) {
|
Chris@0
|
289 // If the new settings has this index, descend into it.
|
Chris@0
|
290 $parent = &$current;
|
Chris@0
|
291 $current = &$parent[$index];
|
Chris@0
|
292 $state = 'candidate_left';
|
Chris@0
|
293 }
|
Chris@0
|
294 else {
|
Chris@0
|
295 // Otherwise, jump back to the default state.
|
Chris@0
|
296 $state = 'wait_for_semicolon';
|
Chris@0
|
297 }
|
Chris@0
|
298 }
|
Chris@0
|
299 else {
|
Chris@0
|
300 // $a[1 + 2].
|
Chris@0
|
301 throw new Exception('] expected');
|
Chris@0
|
302 }
|
Chris@0
|
303 break;
|
Chris@0
|
304 case 'candidate_right':
|
Chris@0
|
305 if (_drupal_rewrite_settings_is_simple($type, $value)) {
|
Chris@0
|
306 $value = _drupal_rewrite_settings_dump_one($current);
|
Chris@0
|
307 // Unsetting $current would not affect $settings at all.
|
Chris@0
|
308 unset($parent[$index]);
|
Chris@0
|
309 // Skip the semicolon because _drupal_rewrite_settings_dump_one() added one.
|
Chris@0
|
310 $state = 'semicolon_skip';
|
Chris@0
|
311 }
|
Chris@0
|
312 else {
|
Chris@0
|
313 $state = 'wait_for_semicolon';
|
Chris@0
|
314 }
|
Chris@0
|
315 break;
|
Chris@0
|
316 case 'wait_for_semicolon':
|
Chris@0
|
317 if ($value == ';') {
|
Chris@0
|
318 $state = 'default';
|
Chris@0
|
319 }
|
Chris@0
|
320 break;
|
Chris@0
|
321 case 'semicolon_skip':
|
Chris@0
|
322 if ($value == ';') {
|
Chris@0
|
323 $value = '';
|
Chris@0
|
324 $state = 'default';
|
Chris@0
|
325 }
|
Chris@0
|
326 else {
|
Chris@0
|
327 // If the expression was $a = 1 + 2; then we replaced 1 and
|
Chris@0
|
328 // the + is unexpected.
|
Chris@0
|
329 throw new Exception('Unexpected token after replacing value.');
|
Chris@0
|
330 }
|
Chris@0
|
331 break;
|
Chris@0
|
332 }
|
Chris@0
|
333 }
|
Chris@0
|
334 $buffer .= $value;
|
Chris@0
|
335 }
|
Chris@0
|
336 foreach ($settings as $name => $setting) {
|
Chris@0
|
337 $buffer .= _drupal_rewrite_settings_dump($setting, '$' . $name);
|
Chris@0
|
338 }
|
Chris@0
|
339
|
Chris@0
|
340 // Write the new settings file.
|
Chris@0
|
341 if (file_put_contents($settings_file, $buffer) === FALSE) {
|
Chris@0
|
342 throw new Exception(t('Failed to modify %settings. Verify the file permissions.', ['%settings' => $settings_file]));
|
Chris@0
|
343 }
|
Chris@0
|
344 else {
|
Chris@0
|
345 // In case any $settings variables were written, import them into the
|
Chris@0
|
346 // Settings singleton.
|
Chris@0
|
347 if (!empty($settings_settings)) {
|
Chris@0
|
348 $old_settings = Settings::getAll();
|
Chris@0
|
349 new Settings($settings_settings + $old_settings);
|
Chris@0
|
350 }
|
Chris@0
|
351 // The existing settings.php file might have been included already. In
|
Chris@0
|
352 // case an opcode cache is enabled, the rewritten contents of the file
|
Chris@0
|
353 // will not be reflected in this process. Ensure to invalidate the file
|
Chris@0
|
354 // in case an opcode cache is enabled.
|
Chris@0
|
355 OpCodeCache::invalidate(DRUPAL_ROOT . '/' . $settings_file);
|
Chris@0
|
356 }
|
Chris@0
|
357 }
|
Chris@0
|
358 else {
|
Chris@0
|
359 throw new Exception(t('Failed to open %settings. Verify the file permissions.', ['%settings' => $settings_file]));
|
Chris@0
|
360 }
|
Chris@0
|
361 }
|
Chris@0
|
362
|
Chris@0
|
363 /**
|
Chris@0
|
364 * Helper for drupal_rewrite_settings().
|
Chris@0
|
365 *
|
Chris@0
|
366 * Checks whether this token represents a scalar or NULL.
|
Chris@0
|
367 *
|
Chris@0
|
368 * @param int $type
|
Chris@0
|
369 * The token type.
|
Chris@0
|
370 * @param string $value
|
Chris@0
|
371 * The value of the token.
|
Chris@0
|
372 *
|
Chris@0
|
373 * @return bool
|
Chris@0
|
374 * TRUE if this token represents a scalar or NULL.
|
Chris@0
|
375 *
|
Chris@0
|
376 * @see token_name()
|
Chris@0
|
377 */
|
Chris@0
|
378 function _drupal_rewrite_settings_is_simple($type, $value) {
|
Chris@0
|
379 $is_integer = $type == T_LNUMBER;
|
Chris@0
|
380 $is_float = $type == T_DNUMBER;
|
Chris@0
|
381 $is_string = $type == T_CONSTANT_ENCAPSED_STRING;
|
Chris@0
|
382 $is_boolean_or_null = $type == T_STRING && in_array(strtoupper($value), ['TRUE', 'FALSE', 'NULL']);
|
Chris@0
|
383 return $is_integer || $is_float || $is_string || $is_boolean_or_null;
|
Chris@0
|
384 }
|
Chris@0
|
385
|
Chris@0
|
386 /**
|
Chris@0
|
387 * Helper for drupal_rewrite_settings().
|
Chris@0
|
388 *
|
Chris@0
|
389 * Checks whether this token represents a valid array index: a number or a
|
Chris@0
|
390 * string.
|
Chris@0
|
391 *
|
Chris@0
|
392 * @param int $type
|
Chris@0
|
393 * The token type.
|
Chris@0
|
394 *
|
Chris@0
|
395 * @return bool
|
Chris@0
|
396 * TRUE if this token represents a number or a string.
|
Chris@0
|
397 *
|
Chris@0
|
398 * @see token_name()
|
Chris@0
|
399 */
|
Chris@0
|
400 function _drupal_rewrite_settings_is_array_index($type) {
|
Chris@0
|
401 $is_integer = $type == T_LNUMBER;
|
Chris@0
|
402 $is_float = $type == T_DNUMBER;
|
Chris@0
|
403 $is_string = $type == T_CONSTANT_ENCAPSED_STRING;
|
Chris@0
|
404 return $is_integer || $is_float || $is_string;
|
Chris@0
|
405 }
|
Chris@0
|
406
|
Chris@0
|
407 /**
|
Chris@0
|
408 * Helper for drupal_rewrite_settings().
|
Chris@0
|
409 *
|
Chris@0
|
410 * Makes the new settings global.
|
Chris@0
|
411 *
|
Chris@0
|
412 * @param array|null $ref
|
Chris@0
|
413 * A reference to a nested index in $GLOBALS.
|
Chris@0
|
414 * @param array|object $variable
|
Chris@0
|
415 * The nested value of the setting being copied.
|
Chris@0
|
416 */
|
Chris@0
|
417 function _drupal_rewrite_settings_global(&$ref, $variable) {
|
Chris@0
|
418 if (is_object($variable)) {
|
Chris@0
|
419 $ref = $variable->value;
|
Chris@0
|
420 }
|
Chris@0
|
421 else {
|
Chris@0
|
422 foreach ($variable as $k => $v) {
|
Chris@0
|
423 _drupal_rewrite_settings_global($ref[$k], $v);
|
Chris@0
|
424 }
|
Chris@0
|
425 }
|
Chris@0
|
426 }
|
Chris@0
|
427
|
Chris@0
|
428 /**
|
Chris@0
|
429 * Helper for drupal_rewrite_settings().
|
Chris@0
|
430 *
|
Chris@0
|
431 * Dump the relevant value properties.
|
Chris@0
|
432 *
|
Chris@0
|
433 * @param array|object $variable
|
Chris@0
|
434 * The container for variable values.
|
Chris@0
|
435 * @param string $variable_name
|
Chris@0
|
436 * Name of variable.
|
Chris@0
|
437 * @return string
|
Chris@0
|
438 * A string containing valid PHP code of the variable suitable for placing
|
Chris@0
|
439 * into settings.php.
|
Chris@0
|
440 */
|
Chris@0
|
441 function _drupal_rewrite_settings_dump($variable, $variable_name) {
|
Chris@0
|
442 $return = '';
|
Chris@0
|
443 if (is_object($variable)) {
|
Chris@0
|
444 if (!empty($variable->required)) {
|
Chris@0
|
445 $return .= _drupal_rewrite_settings_dump_one($variable, "$variable_name = ", "\n");
|
Chris@0
|
446 }
|
Chris@0
|
447 }
|
Chris@0
|
448 else {
|
Chris@0
|
449 foreach ($variable as $k => $v) {
|
Chris@0
|
450 $return .= _drupal_rewrite_settings_dump($v, $variable_name . "['" . $k . "']");
|
Chris@0
|
451 }
|
Chris@0
|
452 }
|
Chris@0
|
453 return $return;
|
Chris@0
|
454 }
|
Chris@0
|
455
|
Chris@0
|
456 /**
|
Chris@0
|
457 * Helper for drupal_rewrite_settings().
|
Chris@0
|
458 *
|
Chris@0
|
459 * Dump the value of a value property and adds the comment if it exists.
|
Chris@0
|
460 *
|
Chris@0
|
461 * @param object $variable
|
Chris@0
|
462 * A stdClass object with at least a value property.
|
Chris@0
|
463 * @param string $prefix
|
Chris@0
|
464 * A string to prepend to the variable's value.
|
Chris@0
|
465 * @param string $suffix
|
Chris@0
|
466 * A string to append to the variable's value.
|
Chris@0
|
467 * @return string
|
Chris@0
|
468 * A string containing valid PHP code of the variable suitable for placing
|
Chris@0
|
469 * into settings.php.
|
Chris@0
|
470 */
|
Chris@0
|
471 function _drupal_rewrite_settings_dump_one(\stdClass $variable, $prefix = '', $suffix = '') {
|
Chris@0
|
472 $return = $prefix . var_export($variable->value, TRUE) . ';';
|
Chris@0
|
473 if (!empty($variable->comment)) {
|
Chris@0
|
474 $return .= ' // ' . $variable->comment;
|
Chris@0
|
475 }
|
Chris@0
|
476 $return .= $suffix;
|
Chris@0
|
477 return $return;
|
Chris@0
|
478 }
|
Chris@0
|
479
|
Chris@0
|
480 /**
|
Chris@0
|
481 * Creates the config directory and ensures it is operational.
|
Chris@0
|
482 *
|
Chris@0
|
483 * @see install_settings_form_submit()
|
Chris@0
|
484 * @see update_prepare_d8_bootstrap()
|
Chris@0
|
485 */
|
Chris@0
|
486 function drupal_install_config_directories() {
|
Chris@17
|
487 global $config_directories, $install_state;
|
Chris@0
|
488
|
Chris@17
|
489 // If settings.php does not contain a config sync directory name we need to
|
Chris@17
|
490 // configure one.
|
Chris@0
|
491 if (empty($config_directories[CONFIG_SYNC_DIRECTORY])) {
|
Chris@17
|
492 if (empty($install_state['config_install_path'])) {
|
Chris@17
|
493 // Add a randomized config directory name to settings.php
|
Chris@17
|
494 $config_directories[CONFIG_SYNC_DIRECTORY] = \Drupal::service('site.path') . '/files/config_' . Crypt::randomBytesBase64(55) . '/sync';
|
Chris@17
|
495 }
|
Chris@17
|
496 else {
|
Chris@17
|
497 // Install profiles can contain a config sync directory. If they do,
|
Chris@17
|
498 // 'config_install_path' is a path to the directory.
|
Chris@17
|
499 $config_directories[CONFIG_SYNC_DIRECTORY] = $install_state['config_install_path'];
|
Chris@17
|
500 }
|
Chris@0
|
501 $settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
|
Chris@0
|
502 'value' => $config_directories[CONFIG_SYNC_DIRECTORY],
|
Chris@0
|
503 'required' => TRUE,
|
Chris@0
|
504 ];
|
Chris@0
|
505 // Rewrite settings.php, which also sets the value as global variable.
|
Chris@0
|
506 drupal_rewrite_settings($settings);
|
Chris@0
|
507 }
|
Chris@0
|
508
|
Chris@0
|
509 // This should never fail, since if the config directory was specified in
|
Chris@0
|
510 // settings.php it will have already been created and verified earlier, and
|
Chris@0
|
511 // if it wasn't specified in settings.php, it is created here inside the
|
Chris@0
|
512 // public files directory, which has already been verified to be writable
|
Chris@0
|
513 // itself. But if it somehow fails anyway, the installation cannot proceed.
|
Chris@0
|
514 // Bail out using a similar error message as in system_requirements().
|
Chris@18
|
515 if (!\Drupal::service('file_system')->prepareDirectory($config_directories[CONFIG_SYNC_DIRECTORY], FileSystemInterface::CREATE_DIRECTORY)
|
Chris@0
|
516 && !file_exists($config_directories[CONFIG_SYNC_DIRECTORY])) {
|
Chris@0
|
517 throw new Exception(t('The directory %directory could not be created. To proceed with the installation, either create the directory or ensure that the installer has the permissions to create it automatically. For more information, see the <a href=":handbook_url">online handbook</a>.', [
|
Chris@0
|
518 '%directory' => config_get_config_directory(CONFIG_SYNC_DIRECTORY),
|
Chris@0
|
519 ':handbook_url' => 'https://www.drupal.org/server-permissions',
|
Chris@0
|
520 ]));
|
Chris@0
|
521 }
|
Chris@0
|
522 elseif (is_writable($config_directories[CONFIG_SYNC_DIRECTORY])) {
|
Chris@0
|
523 // Put a README.txt into the sync config directory. This is required so that
|
Chris@0
|
524 // they can later be added to git. Since this directory is auto-created, we
|
Chris@0
|
525 // have to write out the README rather than just adding it to the drupal core
|
Chris@0
|
526 // repo.
|
Chris@0
|
527 $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync.' . ' For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config';
|
Chris@18
|
528 file_put_contents(config_get_config_directory(CONFIG_SYNC_DIRECTORY) . '/README.txt', "$text\n");
|
Chris@0
|
529 }
|
Chris@0
|
530 }
|
Chris@0
|
531
|
Chris@0
|
532 /**
|
Chris@0
|
533 * Ensures that the config directory exists and is writable, or can be made so.
|
Chris@0
|
534 *
|
Chris@0
|
535 * @param string $type
|
Chris@0
|
536 * Type of config directory to return. Drupal core provides 'sync'.
|
Chris@0
|
537 *
|
Chris@0
|
538 * @return bool
|
Chris@0
|
539 * TRUE if the config directory exists and is writable.
|
Chris@0
|
540 *
|
Chris@0
|
541 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
|
Chris@18
|
542 * config_get_config_directory() and
|
Chris@18
|
543 * \Drupal\Core\File\FileSystemInterface::prepareDirectory() instead.
|
Chris@0
|
544 *
|
Chris@0
|
545 * @see https://www.drupal.org/node/2501187
|
Chris@0
|
546 */
|
Chris@0
|
547 function install_ensure_config_directory($type) {
|
Chris@18
|
548 @trigger_error('install_ensure_config_directory() is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. Use config_get_config_directory() and \Drupal\Core\File\FileSystemInterface::prepareDirectory() instead. See https://www.drupal.org/node/2501187.', E_USER_DEPRECATED);
|
Chris@0
|
549 // The config directory must be defined in settings.php.
|
Chris@0
|
550 global $config_directories;
|
Chris@0
|
551 if (!isset($config_directories[$type])) {
|
Chris@0
|
552 return FALSE;
|
Chris@0
|
553 }
|
Chris@0
|
554 // The logic here is similar to that used by system_requirements() for other
|
Chris@0
|
555 // directories that the installer creates.
|
Chris@0
|
556 else {
|
Chris@0
|
557 $config_directory = config_get_config_directory($type);
|
Chris@18
|
558 return \Drupal::service('file_system')->prepareDirectory($config_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
|
Chris@0
|
559 }
|
Chris@0
|
560 }
|
Chris@0
|
561
|
Chris@0
|
562 /**
|
Chris@0
|
563 * Verifies that all dependencies are met for a given installation profile.
|
Chris@0
|
564 *
|
Chris@0
|
565 * @param $install_state
|
Chris@0
|
566 * An array of information about the current installation state.
|
Chris@0
|
567 *
|
Chris@0
|
568 * @return
|
Chris@0
|
569 * The list of modules to install.
|
Chris@0
|
570 */
|
Chris@0
|
571 function drupal_verify_profile($install_state) {
|
Chris@0
|
572 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
573 $info = $install_state['profile_info'];
|
Chris@0
|
574
|
Chris@0
|
575 // Get the list of available modules for the selected installation profile.
|
Chris@0
|
576 $listing = new ExtensionDiscovery(\Drupal::root());
|
Chris@0
|
577 $present_modules = [];
|
Chris@0
|
578 foreach ($listing->scan('module') as $present_module) {
|
Chris@0
|
579 $present_modules[] = $present_module->getName();
|
Chris@0
|
580 }
|
Chris@0
|
581
|
Chris@0
|
582 // The installation profile is also a module, which needs to be installed
|
Chris@0
|
583 // after all the other dependencies have been installed.
|
Chris@0
|
584 $present_modules[] = $profile;
|
Chris@0
|
585
|
Chris@0
|
586 // Verify that all of the profile's required modules are present.
|
Chris@17
|
587 $missing_modules = array_diff($info['install'], $present_modules);
|
Chris@0
|
588
|
Chris@0
|
589 $requirements = [];
|
Chris@0
|
590
|
Chris@0
|
591 if ($missing_modules) {
|
Chris@0
|
592 $build = [
|
Chris@0
|
593 '#theme' => 'item_list',
|
Chris@0
|
594 '#context' => ['list_style' => 'comma-list'],
|
Chris@0
|
595 ];
|
Chris@0
|
596
|
Chris@0
|
597 foreach ($missing_modules as $module) {
|
Chris@0
|
598 $build['#items'][] = ['#markup' => '<span class="admin-missing">' . Unicode::ucfirst($module) . '</span>'];
|
Chris@0
|
599 }
|
Chris@0
|
600
|
Chris@0
|
601 $modules_list = \Drupal::service('renderer')->renderPlain($build);
|
Chris@0
|
602 $requirements['required_modules'] = [
|
Chris@0
|
603 'title' => t('Required modules'),
|
Chris@0
|
604 'value' => t('Required modules not found.'),
|
Chris@0
|
605 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
606 'description' => t('The following modules are required but were not found. Move them into the appropriate modules subdirectory, such as <em>/modules</em>. Missing modules: @modules', ['@modules' => $modules_list]),
|
Chris@0
|
607 ];
|
Chris@0
|
608 }
|
Chris@0
|
609 return $requirements;
|
Chris@0
|
610 }
|
Chris@0
|
611
|
Chris@0
|
612 /**
|
Chris@0
|
613 * Installs the system module.
|
Chris@0
|
614 *
|
Chris@0
|
615 * Separated from the installation of other modules so core system
|
Chris@0
|
616 * functions can be made available while other modules are installed.
|
Chris@0
|
617 *
|
Chris@0
|
618 * @param array $install_state
|
Chris@0
|
619 * An array of information about the current installation state. This is used
|
Chris@0
|
620 * to set the default language.
|
Chris@0
|
621 */
|
Chris@0
|
622 function drupal_install_system($install_state) {
|
Chris@0
|
623 // Remove the service provider of the early installer.
|
Chris@0
|
624 unset($GLOBALS['conf']['container_service_providers']['InstallerServiceProvider']);
|
Chris@17
|
625 // Add the normal installer service provider.
|
Chris@17
|
626 $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\NormalInstallerServiceProvider';
|
Chris@0
|
627
|
Chris@0
|
628 $request = \Drupal::request();
|
Chris@0
|
629 // Reboot into a full production environment to continue the installation.
|
Chris@0
|
630 /** @var \Drupal\Core\Installer\InstallerKernel $kernel */
|
Chris@0
|
631 $kernel = \Drupal::service('kernel');
|
Chris@0
|
632 $kernel->shutdown();
|
Chris@0
|
633 // Have installer rebuild from the disk, rather then building from scratch.
|
Chris@0
|
634 $kernel->rebuildContainer(FALSE);
|
Chris@0
|
635 $kernel->prepareLegacyRequest($request);
|
Chris@0
|
636
|
Chris@17
|
637 // Before having installed the system module and being able to do a module
|
Chris@17
|
638 // rebuild, prime the \Drupal\Core\Extension\ModuleExtensionList static cache
|
Chris@17
|
639 // with the module's location.
|
Chris@17
|
640 // @todo Try to install system as any other module, see
|
Chris@17
|
641 // https://www.drupal.org/node/2719315.
|
Chris@17
|
642 \Drupal::service('extension.list.module')->setPathname('system', 'core/modules/system/system.info.yml');
|
Chris@17
|
643
|
Chris@0
|
644 // Install base system configuration.
|
Chris@0
|
645 \Drupal::service('config.installer')->installDefaultConfig('core', 'core');
|
Chris@0
|
646
|
Chris@0
|
647 // Store the installation profile in configuration to populate the
|
Chris@0
|
648 // 'install_profile' container parameter.
|
Chris@0
|
649 \Drupal::configFactory()->getEditable('core.extension')
|
Chris@0
|
650 ->set('profile', $install_state['parameters']['profile'])
|
Chris@0
|
651 ->save();
|
Chris@0
|
652
|
Chris@0
|
653 // Install System module and rebuild the newly available routes.
|
Chris@0
|
654 $kernel->getContainer()->get('module_installer')->install(['system'], FALSE);
|
Chris@0
|
655 \Drupal::service('router.builder')->rebuild();
|
Chris@0
|
656
|
Chris@0
|
657 // Ensure default language is saved.
|
Chris@0
|
658 if (isset($install_state['parameters']['langcode'])) {
|
Chris@0
|
659 \Drupal::configFactory()->getEditable('system.site')
|
Chris@0
|
660 ->set('langcode', (string) $install_state['parameters']['langcode'])
|
Chris@0
|
661 ->set('default_langcode', (string) $install_state['parameters']['langcode'])
|
Chris@0
|
662 ->save(TRUE);
|
Chris@0
|
663 }
|
Chris@0
|
664 }
|
Chris@0
|
665
|
Chris@0
|
666 /**
|
Chris@0
|
667 * Verifies the state of the specified file.
|
Chris@0
|
668 *
|
Chris@0
|
669 * @param $file
|
Chris@0
|
670 * The file to check for.
|
Chris@0
|
671 * @param $mask
|
Chris@0
|
672 * An optional bitmask created from various FILE_* constants.
|
Chris@0
|
673 * @param $type
|
Chris@0
|
674 * The type of file. Can be file (default), dir, or link.
|
Chris@17
|
675 * @param bool $autofix
|
Chris@17
|
676 * (optional) Determines whether to attempt fixing the permissions according
|
Chris@17
|
677 * to the provided $mask. Defaults to TRUE.
|
Chris@0
|
678 *
|
Chris@0
|
679 * @return
|
Chris@0
|
680 * TRUE on success or FALSE on failure. A message is set for the latter.
|
Chris@0
|
681 */
|
Chris@17
|
682 function drupal_verify_install_file($file, $mask = NULL, $type = 'file', $autofix = TRUE) {
|
Chris@0
|
683 $return = TRUE;
|
Chris@0
|
684 // Check for files that shouldn't be there.
|
Chris@0
|
685 if (isset($mask) && ($mask & FILE_NOT_EXIST) && file_exists($file)) {
|
Chris@0
|
686 return FALSE;
|
Chris@0
|
687 }
|
Chris@0
|
688 // Verify that the file is the type of file it is supposed to be.
|
Chris@0
|
689 if (isset($type) && file_exists($file)) {
|
Chris@0
|
690 $check = 'is_' . $type;
|
Chris@0
|
691 if (!function_exists($check) || !$check($file)) {
|
Chris@0
|
692 $return = FALSE;
|
Chris@0
|
693 }
|
Chris@0
|
694 }
|
Chris@0
|
695
|
Chris@0
|
696 // Verify file permissions.
|
Chris@0
|
697 if (isset($mask)) {
|
Chris@0
|
698 $masks = [FILE_EXIST, FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE];
|
Chris@0
|
699 foreach ($masks as $current_mask) {
|
Chris@0
|
700 if ($mask & $current_mask) {
|
Chris@0
|
701 switch ($current_mask) {
|
Chris@0
|
702 case FILE_EXIST:
|
Chris@0
|
703 if (!file_exists($file)) {
|
Chris@17
|
704 if ($type == 'dir' && $autofix) {
|
Chris@0
|
705 drupal_install_mkdir($file, $mask);
|
Chris@0
|
706 }
|
Chris@0
|
707 if (!file_exists($file)) {
|
Chris@0
|
708 $return = FALSE;
|
Chris@0
|
709 }
|
Chris@0
|
710 }
|
Chris@0
|
711 break;
|
Chris@0
|
712 case FILE_READABLE:
|
Chris@17
|
713 if (!is_readable($file)) {
|
Chris@0
|
714 $return = FALSE;
|
Chris@0
|
715 }
|
Chris@0
|
716 break;
|
Chris@0
|
717 case FILE_WRITABLE:
|
Chris@17
|
718 if (!is_writable($file)) {
|
Chris@0
|
719 $return = FALSE;
|
Chris@0
|
720 }
|
Chris@0
|
721 break;
|
Chris@0
|
722 case FILE_EXECUTABLE:
|
Chris@17
|
723 if (!is_executable($file)) {
|
Chris@0
|
724 $return = FALSE;
|
Chris@0
|
725 }
|
Chris@0
|
726 break;
|
Chris@0
|
727 case FILE_NOT_READABLE:
|
Chris@17
|
728 if (is_readable($file)) {
|
Chris@0
|
729 $return = FALSE;
|
Chris@0
|
730 }
|
Chris@0
|
731 break;
|
Chris@0
|
732 case FILE_NOT_WRITABLE:
|
Chris@17
|
733 if (is_writable($file)) {
|
Chris@0
|
734 $return = FALSE;
|
Chris@0
|
735 }
|
Chris@0
|
736 break;
|
Chris@0
|
737 case FILE_NOT_EXECUTABLE:
|
Chris@17
|
738 if (is_executable($file)) {
|
Chris@0
|
739 $return = FALSE;
|
Chris@0
|
740 }
|
Chris@0
|
741 break;
|
Chris@0
|
742 }
|
Chris@0
|
743 }
|
Chris@0
|
744 }
|
Chris@0
|
745 }
|
Chris@17
|
746 if (!$return && $autofix) {
|
Chris@17
|
747 return drupal_install_fix_file($file, $mask);
|
Chris@17
|
748 }
|
Chris@0
|
749 return $return;
|
Chris@0
|
750 }
|
Chris@0
|
751
|
Chris@0
|
752 /**
|
Chris@0
|
753 * Creates a directory with the specified permissions.
|
Chris@0
|
754 *
|
Chris@0
|
755 * @param $file
|
Chris@0
|
756 * The name of the directory to create;
|
Chris@0
|
757 * @param $mask
|
Chris@0
|
758 * The permissions of the directory to create.
|
Chris@0
|
759 * @param $message
|
Chris@0
|
760 * (optional) Whether to output messages. Defaults to TRUE.
|
Chris@0
|
761 *
|
Chris@0
|
762 * @return
|
Chris@0
|
763 * TRUE/FALSE whether or not the directory was successfully created.
|
Chris@0
|
764 */
|
Chris@0
|
765 function drupal_install_mkdir($file, $mask, $message = TRUE) {
|
Chris@0
|
766 $mod = 0;
|
Chris@0
|
767 $masks = [FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE];
|
Chris@0
|
768 foreach ($masks as $m) {
|
Chris@0
|
769 if ($mask & $m) {
|
Chris@0
|
770 switch ($m) {
|
Chris@0
|
771 case FILE_READABLE:
|
Chris@0
|
772 $mod |= 0444;
|
Chris@0
|
773 break;
|
Chris@0
|
774 case FILE_WRITABLE:
|
Chris@0
|
775 $mod |= 0222;
|
Chris@0
|
776 break;
|
Chris@0
|
777 case FILE_EXECUTABLE:
|
Chris@0
|
778 $mod |= 0111;
|
Chris@0
|
779 break;
|
Chris@0
|
780 }
|
Chris@0
|
781 }
|
Chris@0
|
782 }
|
Chris@0
|
783
|
Chris@18
|
784 if (@\Drupal::service('file_system')->mkdir($file, $mod)) {
|
Chris@0
|
785 return TRUE;
|
Chris@0
|
786 }
|
Chris@0
|
787 else {
|
Chris@0
|
788 return FALSE;
|
Chris@0
|
789 }
|
Chris@0
|
790 }
|
Chris@0
|
791
|
Chris@0
|
792 /**
|
Chris@0
|
793 * Attempts to fix file permissions.
|
Chris@0
|
794 *
|
Chris@0
|
795 * The general approach here is that, because we do not know the security
|
Chris@0
|
796 * setup of the webserver, we apply our permission changes to all three
|
Chris@0
|
797 * digits of the file permission (i.e. user, group and all).
|
Chris@0
|
798 *
|
Chris@0
|
799 * To ensure that the values behave as expected (and numbers don't carry
|
Chris@0
|
800 * from one digit to the next) we do the calculation on the octal value
|
Chris@0
|
801 * using bitwise operations. This lets us remove, for example, 0222 from
|
Chris@0
|
802 * 0700 and get the correct value of 0500.
|
Chris@0
|
803 *
|
Chris@0
|
804 * @param $file
|
Chris@0
|
805 * The name of the file with permissions to fix.
|
Chris@0
|
806 * @param $mask
|
Chris@0
|
807 * The desired permissions for the file.
|
Chris@0
|
808 * @param $message
|
Chris@0
|
809 * (optional) Whether to output messages. Defaults to TRUE.
|
Chris@0
|
810 *
|
Chris@0
|
811 * @return
|
Chris@0
|
812 * TRUE/FALSE whether or not we were able to fix the file's permissions.
|
Chris@0
|
813 */
|
Chris@0
|
814 function drupal_install_fix_file($file, $mask, $message = TRUE) {
|
Chris@0
|
815 // If $file does not exist, fileperms() issues a PHP warning.
|
Chris@0
|
816 if (!file_exists($file)) {
|
Chris@0
|
817 return FALSE;
|
Chris@0
|
818 }
|
Chris@0
|
819
|
Chris@0
|
820 $mod = fileperms($file) & 0777;
|
Chris@0
|
821 $masks = [FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE];
|
Chris@0
|
822
|
Chris@0
|
823 // FILE_READABLE, FILE_WRITABLE, and FILE_EXECUTABLE permission strings
|
Chris@0
|
824 // can theoretically be 0400, 0200, and 0100 respectively, but to be safe
|
Chris@0
|
825 // we set all three access types in case the administrator intends to
|
Chris@0
|
826 // change the owner of settings.php after installation.
|
Chris@0
|
827 foreach ($masks as $m) {
|
Chris@0
|
828 if ($mask & $m) {
|
Chris@0
|
829 switch ($m) {
|
Chris@0
|
830 case FILE_READABLE:
|
Chris@0
|
831 if (!is_readable($file)) {
|
Chris@0
|
832 $mod |= 0444;
|
Chris@0
|
833 }
|
Chris@0
|
834 break;
|
Chris@0
|
835 case FILE_WRITABLE:
|
Chris@0
|
836 if (!is_writable($file)) {
|
Chris@0
|
837 $mod |= 0222;
|
Chris@0
|
838 }
|
Chris@0
|
839 break;
|
Chris@0
|
840 case FILE_EXECUTABLE:
|
Chris@0
|
841 if (!is_executable($file)) {
|
Chris@0
|
842 $mod |= 0111;
|
Chris@0
|
843 }
|
Chris@0
|
844 break;
|
Chris@0
|
845 case FILE_NOT_READABLE:
|
Chris@0
|
846 if (is_readable($file)) {
|
Chris@0
|
847 $mod &= ~0444;
|
Chris@0
|
848 }
|
Chris@0
|
849 break;
|
Chris@0
|
850 case FILE_NOT_WRITABLE:
|
Chris@0
|
851 if (is_writable($file)) {
|
Chris@0
|
852 $mod &= ~0222;
|
Chris@0
|
853 }
|
Chris@0
|
854 break;
|
Chris@0
|
855 case FILE_NOT_EXECUTABLE:
|
Chris@0
|
856 if (is_executable($file)) {
|
Chris@0
|
857 $mod &= ~0111;
|
Chris@0
|
858 }
|
Chris@0
|
859 break;
|
Chris@0
|
860 }
|
Chris@0
|
861 }
|
Chris@0
|
862 }
|
Chris@0
|
863
|
Chris@0
|
864 // chmod() will work if the web server is running as owner of the file.
|
Chris@0
|
865 if (@chmod($file, $mod)) {
|
Chris@0
|
866 return TRUE;
|
Chris@0
|
867 }
|
Chris@0
|
868 else {
|
Chris@0
|
869 return FALSE;
|
Chris@0
|
870 }
|
Chris@0
|
871 }
|
Chris@0
|
872
|
Chris@0
|
873 /**
|
Chris@0
|
874 * Sends the user to a different installer page.
|
Chris@0
|
875 *
|
Chris@0
|
876 * This issues an on-site HTTP redirect. Messages (and errors) are erased.
|
Chris@0
|
877 *
|
Chris@0
|
878 * @param $path
|
Chris@0
|
879 * An installer path.
|
Chris@0
|
880 */
|
Chris@0
|
881 function install_goto($path) {
|
Chris@0
|
882 global $base_url;
|
Chris@0
|
883 $headers = [
|
Chris@0
|
884 // Not a permanent redirect.
|
Chris@0
|
885 'Cache-Control' => 'no-cache',
|
Chris@0
|
886 ];
|
Chris@0
|
887 $response = new RedirectResponse($base_url . '/' . $path, 302, $headers);
|
Chris@0
|
888 $response->send();
|
Chris@0
|
889 }
|
Chris@0
|
890
|
Chris@0
|
891 /**
|
Chris@0
|
892 * Returns the URL of the current script, with modified query parameters.
|
Chris@0
|
893 *
|
Chris@0
|
894 * This function can be called by low-level scripts (such as install.php and
|
Chris@0
|
895 * update.php) and returns the URL of the current script. Existing query
|
Chris@0
|
896 * parameters are preserved by default, but new ones can optionally be merged
|
Chris@0
|
897 * in.
|
Chris@0
|
898 *
|
Chris@0
|
899 * This function is used when the script must maintain certain query parameters
|
Chris@0
|
900 * over multiple page requests in order to work correctly. In such cases (for
|
Chris@0
|
901 * example, update.php, which requires the 'continue=1' parameter to remain in
|
Chris@0
|
902 * the URL throughout the update process if there are any requirement warnings
|
Chris@0
|
903 * that need to be bypassed), using this function to generate the URL for links
|
Chris@0
|
904 * to the next steps of the script ensures that the links will work correctly.
|
Chris@0
|
905 *
|
Chris@0
|
906 * @param $query
|
Chris@0
|
907 * (optional) An array of query parameters to merge in to the existing ones.
|
Chris@0
|
908 *
|
Chris@0
|
909 * @return
|
Chris@0
|
910 * The URL of the current script, with query parameters modified by the
|
Chris@0
|
911 * passed-in $query. The URL is not sanitized, so it still needs to be run
|
Chris@0
|
912 * through \Drupal\Component\Utility\UrlHelper::filterBadProtocol() if it will be
|
Chris@0
|
913 * used as an HTML attribute value.
|
Chris@0
|
914 *
|
Chris@0
|
915 * @see drupal_requirements_url()
|
Chris@0
|
916 * @see Drupal\Component\Utility\UrlHelper::filterBadProtocol()
|
Chris@0
|
917 */
|
Chris@0
|
918 function drupal_current_script_url($query = []) {
|
Chris@0
|
919 $uri = $_SERVER['SCRIPT_NAME'];
|
Chris@0
|
920 $query = array_merge(UrlHelper::filterQueryParameters(\Drupal::request()->query->all()), $query);
|
Chris@0
|
921 if (!empty($query)) {
|
Chris@0
|
922 $uri .= '?' . UrlHelper::buildQuery($query);
|
Chris@0
|
923 }
|
Chris@0
|
924 return $uri;
|
Chris@0
|
925 }
|
Chris@0
|
926
|
Chris@0
|
927 /**
|
Chris@0
|
928 * Returns a URL for proceeding to the next page after a requirements problem.
|
Chris@0
|
929 *
|
Chris@0
|
930 * This function can be called by low-level scripts (such as install.php and
|
Chris@0
|
931 * update.php) and returns a URL that can be used to attempt to proceed to the
|
Chris@0
|
932 * next step of the script.
|
Chris@0
|
933 *
|
Chris@0
|
934 * @param $severity
|
Chris@0
|
935 * The severity of the requirements problem, as returned by
|
Chris@0
|
936 * drupal_requirements_severity().
|
Chris@0
|
937 *
|
Chris@0
|
938 * @return
|
Chris@0
|
939 * A URL for attempting to proceed to the next step of the script. The URL is
|
Chris@0
|
940 * not sanitized, so it still needs to be run through
|
Chris@0
|
941 * \Drupal\Component\Utility\UrlHelper::filterBadProtocol() if it will be used
|
Chris@0
|
942 * as an HTML attribute value.
|
Chris@0
|
943 *
|
Chris@0
|
944 * @see drupal_current_script_url()
|
Chris@0
|
945 * @see \Drupal\Component\Utility\UrlHelper::filterBadProtocol()
|
Chris@0
|
946 */
|
Chris@0
|
947 function drupal_requirements_url($severity) {
|
Chris@0
|
948 $query = [];
|
Chris@0
|
949 // If there are no errors, only warnings, append 'continue=1' to the URL so
|
Chris@0
|
950 // the user can bypass this screen on the next page load.
|
Chris@0
|
951 if ($severity == REQUIREMENT_WARNING) {
|
Chris@0
|
952 $query['continue'] = 1;
|
Chris@0
|
953 }
|
Chris@0
|
954 return drupal_current_script_url($query);
|
Chris@0
|
955 }
|
Chris@0
|
956
|
Chris@0
|
957 /**
|
Chris@0
|
958 * Checks an installation profile's requirements.
|
Chris@0
|
959 *
|
Chris@0
|
960 * @param string $profile
|
Chris@0
|
961 * Name of installation profile to check.
|
Chris@0
|
962 *
|
Chris@0
|
963 * @return array
|
Chris@0
|
964 * Array of the installation profile's requirements.
|
Chris@0
|
965 */
|
Chris@0
|
966 function drupal_check_profile($profile) {
|
Chris@0
|
967 $info = install_profile_info($profile);
|
Chris@0
|
968 // Collect requirement testing results.
|
Chris@0
|
969 $requirements = [];
|
Chris@0
|
970 // Performs an ExtensionDiscovery scan as the system module is unavailable and
|
Chris@0
|
971 // we don't yet know where all the modules are located.
|
Chris@0
|
972 // @todo Remove as part of https://www.drupal.org/node/2186491
|
Chris@0
|
973 $drupal_root = \Drupal::root();
|
Chris@0
|
974 $module_list = (new ExtensionDiscovery($drupal_root))->scan('module');
|
Chris@0
|
975
|
Chris@17
|
976 foreach ($info['install'] as $module) {
|
Chris@0
|
977 // If the module is in the module list we know it exists and we can continue
|
Chris@0
|
978 // including and registering it.
|
Chris@0
|
979 // @see \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory()
|
Chris@0
|
980 if (isset($module_list[$module])) {
|
Chris@0
|
981 $function = $module . '_requirements';
|
Chris@0
|
982 $module_path = $module_list[$module]->getPath();
|
Chris@0
|
983 $install_file = "$drupal_root/$module_path/$module.install";
|
Chris@0
|
984
|
Chris@0
|
985 if (is_file($install_file)) {
|
Chris@0
|
986 require_once $install_file;
|
Chris@0
|
987 }
|
Chris@0
|
988
|
Chris@0
|
989 drupal_classloader_register($module, $module_path);
|
Chris@0
|
990
|
Chris@0
|
991 if (function_exists($function)) {
|
Chris@0
|
992 $requirements = array_merge($requirements, $function('install'));
|
Chris@0
|
993 }
|
Chris@0
|
994 }
|
Chris@0
|
995 }
|
Chris@0
|
996
|
Chris@17
|
997 // Add the profile requirements.
|
Chris@17
|
998 $function = $profile . '_requirements';
|
Chris@17
|
999 if (function_exists($function)) {
|
Chris@17
|
1000 $requirements = array_merge($requirements, $function('install'));
|
Chris@17
|
1001 }
|
Chris@17
|
1002
|
Chris@0
|
1003 return $requirements;
|
Chris@0
|
1004 }
|
Chris@0
|
1005
|
Chris@0
|
1006 /**
|
Chris@0
|
1007 * Extracts the highest severity from the requirements array.
|
Chris@0
|
1008 *
|
Chris@0
|
1009 * @param $requirements
|
Chris@0
|
1010 * An array of requirements, in the same format as is returned by
|
Chris@0
|
1011 * hook_requirements().
|
Chris@0
|
1012 *
|
Chris@0
|
1013 * @return
|
Chris@0
|
1014 * The highest severity in the array.
|
Chris@0
|
1015 */
|
Chris@0
|
1016 function drupal_requirements_severity(&$requirements) {
|
Chris@0
|
1017 $severity = REQUIREMENT_OK;
|
Chris@0
|
1018 foreach ($requirements as $requirement) {
|
Chris@0
|
1019 if (isset($requirement['severity'])) {
|
Chris@0
|
1020 $severity = max($severity, $requirement['severity']);
|
Chris@0
|
1021 }
|
Chris@0
|
1022 }
|
Chris@0
|
1023 return $severity;
|
Chris@0
|
1024 }
|
Chris@0
|
1025
|
Chris@0
|
1026 /**
|
Chris@0
|
1027 * Checks a module's requirements.
|
Chris@0
|
1028 *
|
Chris@0
|
1029 * @param $module
|
Chris@0
|
1030 * Machine name of module to check.
|
Chris@0
|
1031 *
|
Chris@0
|
1032 * @return
|
Chris@0
|
1033 * TRUE or FALSE, depending on whether the requirements are met.
|
Chris@0
|
1034 */
|
Chris@0
|
1035 function drupal_check_module($module) {
|
Chris@0
|
1036 module_load_install($module);
|
Chris@0
|
1037 // Check requirements
|
Chris@0
|
1038 $requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', ['install']);
|
Chris@0
|
1039 if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
|
Chris@0
|
1040 // Print any error messages
|
Chris@0
|
1041 foreach ($requirements as $requirement) {
|
Chris@0
|
1042 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
|
Chris@0
|
1043 $message = $requirement['description'];
|
Chris@0
|
1044 if (isset($requirement['value']) && $requirement['value']) {
|
Chris@0
|
1045 $message = t('@requirements_message (Currently using @item version @version)', ['@requirements_message' => $requirement['description'], '@item' => $requirement['title'], '@version' => $requirement['value']]);
|
Chris@0
|
1046 }
|
Chris@17
|
1047 \Drupal::messenger()->addError($message);
|
Chris@0
|
1048 }
|
Chris@0
|
1049 }
|
Chris@0
|
1050 return FALSE;
|
Chris@0
|
1051 }
|
Chris@0
|
1052 return TRUE;
|
Chris@0
|
1053 }
|
Chris@0
|
1054
|
Chris@0
|
1055 /**
|
Chris@0
|
1056 * Retrieves information about an installation profile from its .info.yml file.
|
Chris@0
|
1057 *
|
Chris@0
|
1058 * The information stored in a profile .info.yml file is similar to that stored
|
Chris@0
|
1059 * in a normal Drupal module .info.yml file. For example:
|
Chris@0
|
1060 * - name: The real name of the installation profile for display purposes.
|
Chris@0
|
1061 * - description: A brief description of the profile.
|
Chris@0
|
1062 * - dependencies: An array of shortnames of other modules that this install
|
Chris@0
|
1063 * profile requires.
|
Chris@17
|
1064 * - install: An array of shortname of other modules to install that are not
|
Chris@17
|
1065 * required by this install profile.
|
Chris@0
|
1066 *
|
Chris@0
|
1067 * Additional, less commonly-used information that can appear in a
|
Chris@0
|
1068 * profile.info.yml file but not in a normal Drupal module .info.yml file
|
Chris@0
|
1069 * includes:
|
Chris@0
|
1070 *
|
Chris@0
|
1071 * - distribution: Existence of this key denotes that the installation profile
|
Chris@0
|
1072 * is intended to be the only eligible choice in a distribution and will be
|
Chris@0
|
1073 * auto-selected during installation, whereas the installation profile
|
Chris@0
|
1074 * selection screen will be skipped. If more than one distribution profile is
|
Chris@0
|
1075 * found then the first one discovered will be selected.
|
Chris@0
|
1076 * The following subproperties may be set:
|
Chris@0
|
1077 * - name: The name of the distribution that is being installed, to be shown
|
Chris@0
|
1078 * throughout the installation process. If omitted,
|
Chris@0
|
1079 * drupal_install_profile_distribution_name() defaults to 'Drupal'.
|
Chris@0
|
1080 * - install: Optional parameters to override the installer:
|
Chris@0
|
1081 * - theme: The machine name of a theme to use in the installer instead of
|
Chris@0
|
1082 * Drupal's default installer theme.
|
Chris@17
|
1083 * - finish_url: A destination to visit after the installation of the
|
Chris@17
|
1084 * distribution is finished
|
Chris@0
|
1085 *
|
Chris@0
|
1086 * Note that this function does an expensive file system scan to get info file
|
Chris@0
|
1087 * information for dependencies. If you only need information from the info
|
Chris@0
|
1088 * file itself, use system_get_info().
|
Chris@0
|
1089 *
|
Chris@0
|
1090 * Example of .info.yml file:
|
Chris@0
|
1091 * @code
|
Chris@0
|
1092 * name: Minimal
|
Chris@0
|
1093 * description: Start fresh, with only a few modules enabled.
|
Chris@17
|
1094 * install:
|
Chris@0
|
1095 * - block
|
Chris@0
|
1096 * - dblog
|
Chris@0
|
1097 * @endcode
|
Chris@0
|
1098 *
|
Chris@0
|
1099 * @param $profile
|
Chris@0
|
1100 * Name of profile.
|
Chris@0
|
1101 * @param $langcode
|
Chris@0
|
1102 * Language code (if any).
|
Chris@0
|
1103 *
|
Chris@0
|
1104 * @return
|
Chris@0
|
1105 * The info array.
|
Chris@0
|
1106 */
|
Chris@0
|
1107 function install_profile_info($profile, $langcode = 'en') {
|
Chris@0
|
1108 $cache = &drupal_static(__FUNCTION__, []);
|
Chris@0
|
1109
|
Chris@0
|
1110 if (!isset($cache[$profile][$langcode])) {
|
Chris@0
|
1111 // Set defaults for module info.
|
Chris@0
|
1112 $defaults = [
|
Chris@0
|
1113 'dependencies' => [],
|
Chris@17
|
1114 'install' => [],
|
Chris@0
|
1115 'themes' => ['stark'],
|
Chris@0
|
1116 'description' => '',
|
Chris@0
|
1117 'version' => NULL,
|
Chris@0
|
1118 'hidden' => FALSE,
|
Chris@0
|
1119 'php' => DRUPAL_MINIMUM_PHP,
|
Chris@17
|
1120 'config_install_path' => NULL,
|
Chris@0
|
1121 ];
|
Chris@17
|
1122 $profile_path = drupal_get_path('profile', $profile);
|
Chris@17
|
1123 $info = \Drupal::service('info_parser')->parse("$profile_path/$profile.info.yml");
|
Chris@0
|
1124 $info += $defaults;
|
Chris@0
|
1125
|
Chris@18
|
1126 $dependency_name_function = function ($dependency) {
|
Chris@18
|
1127 return Dependency::createFromString($dependency)->getName();
|
Chris@18
|
1128 };
|
Chris@17
|
1129 // Convert dependencies in [project:module] format.
|
Chris@18
|
1130 $info['dependencies'] = array_map($dependency_name_function, $info['dependencies']);
|
Chris@17
|
1131
|
Chris@17
|
1132 // Convert install key in [project:module] format.
|
Chris@18
|
1133 $info['install'] = array_map($dependency_name_function, $info['install']);
|
Chris@17
|
1134
|
Chris@0
|
1135 // drupal_required_modules() includes the current profile as a dependency.
|
Chris@0
|
1136 // Remove that dependency, since a module cannot depend on itself.
|
Chris@0
|
1137 $required = array_diff(drupal_required_modules(), [$profile]);
|
Chris@0
|
1138
|
Chris@0
|
1139 $locale = !empty($langcode) && $langcode != 'en' ? ['locale'] : [];
|
Chris@0
|
1140
|
Chris@17
|
1141 // Merge dependencies, required modules and locale into install list and
|
Chris@17
|
1142 // remove any duplicates.
|
Chris@17
|
1143 $info['install'] = array_unique(array_merge($info['install'], $required, $info['dependencies'], $locale));
|
Chris@0
|
1144
|
Chris@17
|
1145 // If the profile has a config/sync directory use that to install drupal.
|
Chris@17
|
1146 if (is_dir($profile_path . '/config/sync')) {
|
Chris@17
|
1147 $info['config_install_path'] = $profile_path . '/config/sync';
|
Chris@17
|
1148 }
|
Chris@0
|
1149 $cache[$profile][$langcode] = $info;
|
Chris@0
|
1150 }
|
Chris@0
|
1151 return $cache[$profile][$langcode];
|
Chris@0
|
1152 }
|
Chris@0
|
1153
|
Chris@0
|
1154 /**
|
Chris@0
|
1155 * Returns a database installer object.
|
Chris@0
|
1156 *
|
Chris@0
|
1157 * @param $driver
|
Chris@0
|
1158 * The name of the driver.
|
Chris@0
|
1159 *
|
Chris@0
|
1160 * @return \Drupal\Core\Database\Install\Tasks
|
Chris@0
|
1161 * A class defining the requirements and tasks for installing the database.
|
Chris@0
|
1162 */
|
Chris@0
|
1163 function db_installer_object($driver) {
|
Chris@0
|
1164 // We cannot use Database::getConnection->getDriverClass() here, because
|
Chris@0
|
1165 // the connection object is not yet functional.
|
Chris@0
|
1166 $task_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Install\\Tasks";
|
Chris@0
|
1167 if (class_exists($task_class)) {
|
Chris@0
|
1168 return new $task_class();
|
Chris@0
|
1169 }
|
Chris@0
|
1170 else {
|
Chris@0
|
1171 $task_class = "Drupal\\Driver\\Database\\{$driver}\\Install\\Tasks";
|
Chris@0
|
1172 return new $task_class();
|
Chris@0
|
1173 }
|
Chris@0
|
1174 }
|