private function AcsfInitCommands::defaultSettingsPhpUpdate in Acquia Cloud Site Factory Connector 8.2
Updates the default settings.php with the ACSF specific script include.
Parameters
string $default_settings_php_path: The path to the default settings.php file.
1 call to AcsfInitCommands::defaultSettingsPhpUpdate()
- AcsfInitCommands::init in acsf_init/
src/ Commands/ AcsfInitCommands.php - Make this repository compatible with Acquia Site Factory.
File
- acsf_init/
src/ Commands/ AcsfInitCommands.php, line 749
Class
- AcsfInitCommands
- Provides drush commands to set up a codebase for Acquia Cloud Site Factory.
Namespace
Drush\CommandsCode
private function defaultSettingsPhpUpdate($default_settings_php_path) {
$default_settings_php_contents = file_get_contents($default_settings_php_path);
// Check if the default settings.php contains our code block. The m modifier
// makes it possible to match text over multiple lines and the s modifier
// allows the . wildcard to match newline characters.
if (!preg_match('/' . preg_quote(self::ACSF_INIT_CODE_DELIMITER_START, '/') . '.*?' . preg_quote(self::ACSF_INIT_CODE_DELIMITER_END, '/') . '/ms', $default_settings_php_contents)) {
// Code block not detected: add it after the opening php tag.
$this
->logger()
->notice(dt('ACSF include not detected in sites/default/settings.php.'));
// Using preg_replace instead of str_replace to be able to control how
// many times the replace gets executed.
$default_settings_php_contents = preg_replace('/<\\?php/', "<?php\n\n" . $this
->defaultSettingsPhpIncludeGet() . "\n", $default_settings_php_contents, 1, $count);
if ($count === 0) {
$this
->logger()
->error(dt('Could not find <?php tag in sites/default/settings.php.'));
}
}
else {
// Code block found: update it with the latest version.
$this
->logger()
->notice(dt('ACSF include detected in sites/default/settings.php.'));
$default_settings_php_contents = preg_replace('/' . preg_quote(self::ACSF_INIT_CODE_DELIMITER_START, '/') . '.*?' . preg_quote(self::ACSF_INIT_CODE_DELIMITER_END, '/') . '/ms', $this
->defaultSettingsPhpIncludeGet(), $default_settings_php_contents);
}
$result = file_put_contents($default_settings_php_path, $default_settings_php_contents);
if ($result) {
$this
->logger()
->success(dt('File edit success: sites/default/settings.php'));
}
else {
$this
->logger()
->error(dt('File edit error: sites/default/settings.php'));
}
}