Add initial setup global settings
This commit is contained in:
parent
a7af0f64d2
commit
6eab3ac311
7 changed files with 113 additions and 11 deletions
|
|
@ -40,7 +40,6 @@ function set_setting(string $name, mixed $value): bool {
|
|||
try {
|
||||
drupal_rewrite_settings($settings, $filename);
|
||||
} catch(Throwable $t) {
|
||||
throw $t; // DEBUG
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -52,4 +51,43 @@ function set_setting(string $name, mixed $value): bool {
|
|||
/** Sets the trusted host to the specified domain */
|
||||
function set_trusted_domain(string $domain): bool {
|
||||
return set_setting("trusted_host_patterns", [preg_quote($domain)]);
|
||||
}
|
||||
|
||||
/** Sets up including a settings.php file from the given path */
|
||||
function install_settings_include(array $paths): bool {
|
||||
// find the original filename
|
||||
$filename = DRUPAL_ROOT . "/" . \Drupal::getContainer()->getParameter("site.path") . "/settings.php";
|
||||
|
||||
// read the original file
|
||||
$original_content = file_get_contents($filename);
|
||||
if ($original_content === FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// remove any old <distillery-settings-includes>
|
||||
$pattern = '/\/\/(\s*)<distillery-settings-include>(.*?)\/\/(\s*)<\/distillery-settings-include>/s';
|
||||
$new_content = preg_replace($pattern, '', $originalContent);
|
||||
|
||||
$code = "// <distillery-settings-include>>\n//\n// DO NOT MODIFY THIS BLOCK AND KEEP IT AT THE END OF THE FILE.\n// DO NOT REMOVE CONFIG TAGS\n";
|
||||
foreach ($paths as $path) {
|
||||
// escape the path to be included
|
||||
$the_path = "'" . addslashes($path) . "'";
|
||||
// resolve it (if it isn't absolute)
|
||||
if (!str_starts_with($path, '/')) {
|
||||
$the_path = '$app_root . \'/\' . $site_path . \'/\' . ' . $the_path;
|
||||
}
|
||||
|
||||
// add code to include the file if it exists
|
||||
$code = $code . 'if (file_exists(' . $the_path . ')) { include_once ' . $the_path . '; }' . "\n";
|
||||
}
|
||||
$code = $code . "// </distillery-settings-include>";
|
||||
|
||||
// and store the settings
|
||||
try {
|
||||
file_put_contents($filename, $original_content . $code);
|
||||
} catch(Throwable $t) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue