Settings not saved to config.php when using bootstrap.early.php (Vanilla 3.0.2)
Moved the tangential discussion about unable to save to config.php from this thread to a new thread here.
I'm using the following bootstrap.early.php file to retrieve my Vanilla database credentials from several environment variables:
<?php
// Get the info from environment
// Save it __temporarily__ to the config.
saveToConfig('Database.Name', 'Vanilla', array('Save' => false));
saveToConfig('Database.Host', getenv('MYSQL_DBHOST'), array('Save' => false));
saveToConfig('Database.User', getenv('MYSQL_DBUSER'), array('Save' => false));
saveToConfig('Database.Password', getenv('MYSQL_DBPASS'), array('Save' => false));
Whenever I change a setting in the dashboard, e.g., turning on a plug-in, the settings are not written to the config.php file.
I tracked it down to the following block of code in class.configurationsource.php (line 519 in Vanilla 3.0.2):
if (!isset($data['Database'])) {
if ($pm = Gdn::pluginManager()) {
$pm->EventArguments['Data'] = $data;
$pm->EventArguments['Backtrace'] = debug_backtrace();
$pm->fireEvent('ConfigError');
}
return false;
}
$data['Database'] does not exist, and the method save() in class.configurationsource.php bails out early prior to actually saving the file.
Because I've got 'Save' => false in the bootstrap.early.php file, the database information does not exist in the settings array to be written to config.php, and the function bails out.
How can I utilize bootstrap.early.php to retrieve my database credentials, but get the settings to write to config.php?
Comments
Have you already tried to simply give some dummy values in the config? I do not know if your bootstrap.early values would be overwritten by that dummy values, but it's worth a try since that would be the easiest solution
I changed the first
saveToConfiginbootstrap.early.phpto save theDatabase.nameinconfig.php, and left the three other lines tofalse. That resolved the issue. Finalbootstrap.early.phpis then:<?php // Get the info from environment // Save it __temporarily__ to the config. saveToConfig('Database.Name', 'Vanilla', array('Save' => true)); saveToConfig('Database.Host', getenv('MYSQL_DBHOST'), array('Save' => false)); saveToConfig('Database.User', getenv('MYSQL_DBUSER'), array('Save' => false)); saveToConfig('Database.Password', getenv('MYSQL_DBPASS'), array('Save' => false));This gets the settings to save in
config.php.