partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 1d3080267bb0a36ce603604f3bf54b5aee8bfaf9
parent c5df62a8f76696226cbe631d2a67faaef2eccf97
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun, 15 Nov 2015 18:37:46 +0100

Refactored existing config response to include only the "config" key and not "config.values". Also changed the config parser to parse the new config file first, then the legacy.

Diffstat:
Msrc/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php | 113++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mweb/setup/js/SetupTests/ExistingConfigurationTest.js | 2+-
2 files changed, 58 insertions(+), 57 deletions(-)

diff --git a/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php b/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php @@ -30,87 +30,88 @@ class ExistingConfigParserController extends SetupController ); try { - $config = array( - "values" => array(), - ); + $response["config"] = $this->configParser(); - $legacyConfig = $this->legacyConfigParser(); + if (count($response["config"]) == 0) { + $response["config"] = $this->getLegacyConfig(); + } - if (count($legacyConfig) > 0) { - if (array_key_exists("partkeepr.database.driver", $legacyConfig)) { - $config["values"]["database_driver"] = $legacyConfig["partkeepr.database.driver"]; - } + if (count($response["config"]) == 0) { + $response["message"] = "No configuration found"; + } - if (array_key_exists("partkeepr.database.host", $legacyConfig)) { - $config["values"]["database_host"] = $legacyConfig["partkeepr.database.host"]; - } + } catch (\Exception $e) { + $response["success"] = false; + $response["message"] = "Configuration parse error"; + $response["errors"] = [$e->getMessage()]; + } - if (array_key_exists("partkeepr.database.username", $legacyConfig)) { - $config["values"]["database_user"] = $legacyConfig["partkeepr.database.username"]; - } + return new JsonResponse($response); + } - if (array_key_exists("partkeepr.database.password", $legacyConfig)) { - $config["values"]["database_password"] = $legacyConfig["partkeepr.database.password"]; - } + protected function getLegacyConfig() + { + $config = array(); - if (array_key_exists("partkeepr.database.dbname", $legacyConfig)) { - $config["values"]["database_name"] = $legacyConfig["partkeepr.database.dbname"]; - } + $legacyConfig = $this->legacyConfigParser(); - if (array_key_exists("partkeepr.database.port", $legacyConfig)) { - $config["values"]["database_port"] = $legacyConfig["partkeepr.database.port"]; - } + if (count($legacyConfig) > 0) { + if (array_key_exists("partkeepr.database.driver", $legacyConfig)) { + $config["database_driver"] = $legacyConfig["partkeepr.database.driver"]; + } - $config["values"]["authentication_provider"] = "PartKeepr.Auth.HTTPBasicAuthenticationProvider"; + if (array_key_exists("partkeepr.database.host", $legacyConfig)) { + $config["database_host"] = $legacyConfig["partkeepr.database.host"]; + } - if (array_key_exists("partkeepr.frontend.motd", $legacyConfig)) { - $config["values"]["partkeepr.frontend.motd"] = $legacyConfig["partkeepr.frontend.motd"]; - } + if (array_key_exists("partkeepr.database.username", $legacyConfig)) { + $config["database_user"] = $legacyConfig["partkeepr.database.username"]; + } - if (array_key_exists("partkeepr.frontend.autologin.enabled", $legacyConfig)) { - $config["values"]["partkeepr.frontend.auto_login.enabled"] = $legacyConfig["partkeepr.frontend.autologin.enabled"]; - } + if (array_key_exists("partkeepr.database.password", $legacyConfig)) { + $config["database_password"] = $legacyConfig["partkeepr.database.password"]; + } - if (array_key_exists("partkeepr.frontend.autologin.username", $legacyConfig)) { - $config["values"]["partkeepr.frontend.auto_login.username"] = $legacyConfig["partkeepr.frontend.autologin.username"]; - } + if (array_key_exists("partkeepr.database.dbname", $legacyConfig)) { + $config["database_name"] = $legacyConfig["partkeepr.database.dbname"]; + } - if (array_key_exists("partkeepr.frontend.autologin.password", $legacyConfig)) { - $config["values"]["partkeepr.frontend.auto_login.password"] = $legacyConfig["partkeepr.frontend.autologin.password"]; - } + if (array_key_exists("partkeepr.database.port", $legacyConfig)) { + $config["database_port"] = $legacyConfig["partkeepr.database.port"]; + } - if (array_key_exists("partkeepr.cronjobs.disablecheck", $legacyConfig)) { - $config["values"]["partkeepr.cronjob.check"] = $legacyConfig["partkeepr.cronjobs.disablecheck"]; - } + $config["authentication_provider"] = "PartKeepr.Auth.HTTPBasicAuthenticationProvider"; - if (array_key_exists("partkeepr.category.path_separator", $legacyConfig)) { - $config["values"]["partkeepr.category.path_separator"] = $legacyConfig["partkeepr.category.path_separator"]; - } + if (array_key_exists("partkeepr.frontend.motd", $legacyConfig)) { + $config["partkeepr.frontend.motd"] = $legacyConfig["partkeepr.frontend.motd"]; + } - if (array_key_exists("partkeepr.frontend.allow_password_change", $legacyConfig)) { - $config["values"]["partkeepr.auth.allow_password_change"] = $legacyConfig["partkeepr.frontend.allow_password_change"]; - } + if (array_key_exists("partkeepr.frontend.autologin.enabled", $legacyConfig)) { + $config["partkeepr.frontend.auto_login.enabled"] = $legacyConfig["partkeepr.frontend.autologin.enabled"]; + } - $response["config"] = $config; + if (array_key_exists("partkeepr.frontend.autologin.username", $legacyConfig)) { + $config["partkeepr.frontend.auto_login.username"] = $legacyConfig["partkeepr.frontend.autologin.username"]; } - $config = $this->configParser(); + if (array_key_exists("partkeepr.frontend.autologin.password", $legacyConfig)) { + $config["partkeepr.frontend.auto_login.password"] = $legacyConfig["partkeepr.frontend.autologin.password"]; + } - if (count($config) > 0) { - $response["config"]["values"] = $config; + if (array_key_exists("partkeepr.cronjobs.disablecheck", $legacyConfig)) { + $config["partkeepr.cronjob.check"] = $legacyConfig["partkeepr.cronjobs.disablecheck"]; } - if (count($response["config"]) == 0) { - $response["message"] = "No configuration found"; + if (array_key_exists("partkeepr.category.path_separator", $legacyConfig)) { + $config["partkeepr.category.path_separator"] = $legacyConfig["partkeepr.category.path_separator"]; } - } catch (\Exception $e) { - $response["success"] = false; - $response["message"] = "Configuration parse error"; - $response["errors"] = [$e->getMessage()]; + if (array_key_exists("partkeepr.frontend.allow_password_change", $legacyConfig)) { + $config["partkeepr.auth.allow_password_change"] = $legacyConfig["partkeepr.frontend.allow_password_change"]; + } } - return new JsonResponse($response); + return $config; } protected function legacyConfigParser() diff --git a/web/setup/js/SetupTests/ExistingConfigurationTest.js b/web/setup/js/SetupTests/ExistingConfigurationTest.js @@ -11,7 +11,7 @@ Ext.define('PartKeeprSetup.ExistingConfigurationTest', { if (data.config) { var config = PartKeeprSetup.getApplication().getSetupConfig(); - Ext.merge(config, data.config); + Ext.merge(config.values, data.config); config.existingConfig = true; } }