HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

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

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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

  • Options

    I changed the first saveToConfig in bootstrap.early.php to save the Database.name in config.php, and left the three other lines to false. That resolved the issue. Final bootstrap.early.php is 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.

Sign In or Register to comment.