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