1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Tutorial Configuration Version

Discussion in 'Resources' started by Axon, May 25, 2022.

  1. Axon

    Axon Zombie

    The entirety of poggit plugins that checks for a config-version uses a constant integer from the plugin's code.
    That is a bad practice and could be improved since most people forget to change their config-version in the plugin's code.
    I came up with this simple solution when I fixed a bug in another plugin that forgot to change the config version.
    This code snippet gets the config version from the resources folder of the plugin, and then it checks it with the plugin_data config version.

    Spoon feed below:

    private function checkConfig() :void{
    $configVersionKey "config-version";
    $pluginConfigResource $this->getResource("config.yml");
    $pluginConfig yaml_parse(stream_get_contents($pluginConfigResource));
    $config $this->getConfig();

    $pluginConfig == false) {
    $this->getLogger()->critical("Something went wrong with the stream.");
    $config->get($configVersionKey) === $pluginConfig[$configVersionKey]) return;
    $this->getLogger()->notice("Your config is outdated!");
    $this->getLogger()->info("Your old config.yml is renamed as old-config.yml");
    rename($this->getDataFolder(). 'config.yml''old-config.yml');
    Happy Coding!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.