PluginBase: Automatically save default config if it doesn't exist (#2285)

I wasn't sure whether this would be considered a bug fix or a feature. Nonetheless, it's a behavioural change, so it belongs in 3.1 if anywhere.

Prior to this, plugins would be required to call saveDefaultConfig() before calling getConfig() or anything else. Calling getConfig() without saveDefaultConfig() first would generate an empty configuration file. Instead, it now saves the default config before loading it.
This commit is contained in:
Dylan K. Taylor
2018-07-12 19:25:48 +01:00
committed by GitHub
parent 3a373b880d
commit 1d5c741f28

View File

@ -256,7 +256,9 @@ abstract class PluginBase implements Plugin{
}
public function reloadConfig(){
@mkdir($this->dataFolder);
if(!$this->saveDefaultConfig()){
@mkdir($this->dataFolder);
}
$this->config = new Config($this->configFile);
if(($configStream = $this->getResource("config.yml")) !== null){
$this->config->setDefaults(yaml_parse(Config::fixYAMLIndexes(stream_get_contents($configStream))));