X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=inline;f=application%2FUpdater.php;h=8552850c276463318533d02d435bd322419ab80f;hb=b74b96bfbd0b778ac50fd17f5e107c51435b1678;hp=6b92af3d2d294164235f0feac77c53354051d8b6;hpb=684e662a58b02bde225e44d3677987b6fc3adf0b;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Updater.php b/application/Updater.php index 6b92af3d..8552850c 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -142,6 +142,48 @@ class Updater $this->linkDB->savedb($conf->get('config.PAGECACHE')); return true; } + + /** + * Move old configuration in PHP to the new config system in JSON format. + * + * Will rename 'config.php' into 'config.save.php' and create 'config.json'. + */ + public function updateMethodConfigToJson() + { + $conf = ConfigManager::getInstance(); + + // JSON config already exists, nothing to do. + if ($conf->getConfigIO() instanceof ConfigJson) { + return true; + } + + $configPhp = new ConfigPhp(); + $configJson = new ConfigJson(); + $oldConfig = $configPhp->read($conf::$CONFIG_FILE . '.php'); + rename($conf->getConfigFile(), $conf::$CONFIG_FILE . '.save.php'); + $conf->setConfigIO($configJson); + $conf->reload(); + + foreach (ConfigPhp::$ROOT_KEYS as $key) { + $conf->set($key, $oldConfig[$key]); + } + + // Set sub config keys (config and plugins) + $subConfig = array('config', 'plugins'); + foreach ($subConfig as $sub) { + foreach ($oldConfig[$sub] as $key => $value) { + $conf->set($sub .'.'. $key, $value); + } + } + + try{ + $conf->write($this->isLoggedIn); + return true; + } catch (IOException $e) { + error_log($e->getMessage()); + return false; + } + } } /** @@ -199,7 +241,6 @@ class UpdaterException extends Exception } } - /** * Read the updates file, and return already done updates. *