partkeepr

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

commit a6c43732fe02b93f0b26d851e3bfbe3a9c9988b2
parent cd417d5c2983c44f9f9bf6f7b0ab6ae8b5df7661
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun, 15 Nov 2015 16:49:19 +0100

Refactored setup to use arbitrary config values, related to #461

Diffstat:
Msrc/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php | 2+-
Msrc/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php | 16++++++++--------
Msrc/PartKeepr/SetupBundle/Controller/SetupController.php | 107+++++++++++++++++++++++++++++++++++--------------------------------------------
Msrc/PartKeepr/SetupBundle/Resources/views/parameters.php.twig | 44+++-----------------------------------------
Mweb/setup.php | 2+-
Mweb/setup/js/Cards/DatabaseParametersCard.MySQL.js | 38+++++++++++++++++++-------------------
Mweb/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js | 12++++++------
Mweb/setup/js/Cards/DatabaseParametersCard.js | 4++--
Mweb/setup/js/PartKeeprSetup.js | 16+++++++++-------
9 files changed, 96 insertions(+), 145 deletions(-)

diff --git a/src/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php b/src/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php @@ -14,7 +14,7 @@ class CacheWarmupSetupController extends SetupController /** * @Route("/setup/_int_cache_warmup") */ - public function intSetupSchemaAction() + public function intCacheWarmupAction() { $response = array( "success" => true, diff --git a/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php b/src/PartKeepr/SetupBundle/Controller/ExistingConfigParserController.php @@ -37,34 +37,34 @@ class ExistingConfigParserController extends SetupController $response["message"] = "No configuration found"; } else { $config = array( - "database" => array() + "values" => array() ); if (array_key_exists("partkeepr.database.driver", $legacyConfig)) { - $config["database"]["driver"] = $legacyConfig["partkeepr.database.driver"]; + $config["values"]["database_driver"] = $legacyConfig["partkeepr.database.driver"]; } if (array_key_exists("partkeepr.database.host", $legacyConfig)) { - $config["database"]["host"] = $legacyConfig["partkeepr.database.host"]; + $config["values"]["database_host"] = $legacyConfig["partkeepr.database.host"]; } if (array_key_exists("partkeepr.database.username", $legacyConfig)) { - $config["database"]["user"] = $legacyConfig["partkeepr.database.username"]; + $config["values"]["database_user"] = $legacyConfig["partkeepr.database.username"]; } if (array_key_exists("partkeepr.database.password", $legacyConfig)) { - $config["database"]["password"] = $legacyConfig["partkeepr.database.password"]; + $config["values"]["database_password"] = $legacyConfig["partkeepr.database.password"]; } if (array_key_exists("partkeepr.database.dbname", $legacyConfig)) { - $config["database"]["name"] = $legacyConfig["partkeepr.database.dbname"]; + $config["values"]["database_name"] = $legacyConfig["partkeepr.database.dbname"]; } if (array_key_exists("partkeepr.database.port", $legacyConfig)) { - $config["database"]["port"] = $legacyConfig["partkeepr.database.port"]; + $config["values"]["database_port"] = $legacyConfig["partkeepr.database.port"]; } - $config["legacyAuth"] = true; + $config["values"]["authentication_provider"] = "PartKeepr.Auth.HTTPBasicAuthenticationProvider"; $response["config"] = $config; } diff --git a/src/PartKeepr/SetupBundle/Controller/SetupController.php b/src/PartKeepr/SetupBundle/Controller/SetupController.php @@ -2,7 +2,10 @@ namespace PartKeepr\SetupBundle\Controller; use Doctrine\DBAL\Exception\DriverException; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -139,72 +142,56 @@ class SetupController extends Controller { $data = json_decode($request->getContent(), true); - $parameters = array(); - $parameters["database"] = array( - "driver" => null, - "host" => null, - "user" => null, - "password" => null, - "name" => null, - "port" => 3306, - ); - - $parameters["mailer"] = array( - "transport" => null, - "host" => null, - "port" => null, - "encryption" => null, - "username" => null, - "password" => null, - "auth_mode" => null, - ); - - $parameters["ldap"] = array( - "enabled" => false, - "host" => "127.0.0.1", - "port" => null, - "username" => null, - "password" => null, - "bindrequiresdn" => false, - "basedn" => "", - "ssl" => null, - "starttls" => null, - "user_basedn" => "dc=blabla,dc=com", - "user_filter" => null, - "user_username" => null, - "user_name" => null, - "user_email" => null, + $parameters = array( + "database_driver" => null, + "database_host" => null, + "database_port" => null, + "database_name" => null, + "database_password" => null, + + "mailer_transport" => null, + "mailer_host" => null, + "mailer_port" => null, + "mailer_encryption" => null, + "mailer_user" => null, + "mailer_password" => null, + "mailer_auth_mode" => null, + + "authentication_provider" => "PartKeepr.Auth.HTTPBasicAuthenticationProvider", + + "locale" => "en", + + "secret" => $this->generateSecret(), + + "fr3d_ldap.driver.host" => "127.0.0.1", + "fr3d_ldap.driver.port" => null, + "fr3d_ldap.driver.username" => null, + "fr3d_ldap.driver.password" => null, + "fr3d_ldap.driver.bindRequiresDn" => false, + "fr3d_ldap.driver.baseDn" => "", + "fr3d_ldap.driver.accountFilterFormat" => null, + "fr3d_ldap.driver.optReferrals" => null, + "fr3d_ldap.driver.useSsl" => null, + "fr3d_ldap.driver.useStartTls" => null, + "fr3d_ldap.driver.accountCanonicalForm" => null, + "fr3d_ldap.driver.accountDomainName" => null, + "fr3d_ldap.driver.accountDomainNameShort" => null, + "fr3d_ldap.user.enabled" => false, + "fr3d_ldap.user.baseDn" => "dc=example,dc=com", + "fr3d_ldap.user.filter" => null, + "fr3d_ldap.user.attribute.username" => null, + "fr3d_ldap.user.attribute.name" => null, + "fr3d_ldap.user.attribute.email" => null, ); - $parameters["legacyAuth"] = false; - - $secret = ""; - for ($i = 0; $i < 32; $i++) { - $secret .= chr(65 + rand(0, 16)); - } - $parameters["secret"] = $this->generateSecret(); - - - if (array_key_exists("database", $data)) { - $parameters["database"] = $this->applyIf($parameters["database"], $data["database"]); - } - - if (array_key_exists("mailer", $data)) { - $parameters["mailer"] = $this->applyIf($parameters["mailer"], $data["mailer"]); - } - - if (array_key_exists("ldap", $data)) { - $parameters["ldap"] = $this->applyIf($parameters["ldap"], $data["ldap"]); - } - - if (array_key_exists("legacyAuth", $data)) { - $parameters["legacyAuth"] = $data["legacyAuth"]; - } + $this->applyIf($parameters, $data["values"]); + $parameters = array_merge($parameters, $data["values"]); array_walk_recursive($parameters, function (&$item, $key) { $item = var_export($item, true); }); + ksort($parameters); - $contents = $this->container->get('templating')->render('PartKeeprSetupBundle::parameters.php.twig', $parameters); + $contents = $this->container->get('templating')->render('PartKeeprSetupBundle::parameters.php.twig', array("parameters" => $parameters)); file_put_contents($this->getConfigPath($test), $contents); } diff --git a/src/PartKeepr/SetupBundle/Resources/views/parameters.php.twig b/src/PartKeepr/SetupBundle/Resources/views/parameters.php.twig @@ -1,42 +1,4 @@ <?php -$container->setParameter('database_driver', {{ database.driver|raw }}); -$container->setParameter('database_host', {{ database.host|raw }}); -$container->setParameter('database_port', {{ database.port|raw }}); -$container->setParameter('database_name', {{ database.name|raw }}); -$container->setParameter('database_user', {{ database.user|raw }}); -$container->setParameter('database_password', {{ database.password|raw }}); - - -$container->setParameter('mailer_transport', {{ mailer.transport|raw }}); -$container->setParameter('mailer_host', {{ mailer.host|raw }}); -$container->setParameter('mailer_port', {{ mailer.port|raw }}); -$container->setParameter('mailer_encryption', {{ mailer.encryption|raw }}); -$container->setParameter('mailer_user', {{ mailer.username|raw }}); -$container->setParameter('mailer_password', {{ mailer.password|raw }}); -$container->setParameter('mailer_auth_mode', {{ mailer.auth_mode|raw }}); - -$container->setParameter('authentication_provider', '{% if legacyAuth == "true" %}PartKeepr.Auth.HTTPBasicAuthenticationProvider{% else %}PartKeepr.Auth.WSSEAuthenticationProvider{% endif %}'); - -$container->setParameter('locale', 'en'); - -$container->setParameter('secret', {{ secret|raw }}); - -$container->setParameter('fr3d_ldap.driver.host', {{ ldap.host|raw }}); -$container->setParameter('fr3d_ldap.driver.port', {{ ldap.port|raw }}); -$container->setParameter('fr3d_ldap.driver.username', {{ ldap.username|raw }}); -$container->setParameter('fr3d_ldap.driver.password', {{ ldap.password|raw }}); -$container->setParameter('fr3d_ldap.driver.bindRequiresDn', {{ ldap.bindrequiresdn|raw }}); -$container->setParameter('fr3d_ldap.driver.baseDn', {{ ldap.basedn|raw }}); -$container->setParameter('fr3d_ldap.driver.accountFilterFormat', null); -$container->setParameter('fr3d_ldap.driver.optReferrals', null); -$container->setParameter('fr3d_ldap.driver.useSsl', {{ ldap.ssl|raw }}); -$container->setParameter('fr3d_ldap.driver.useStartTls', {{ ldap.starttls|raw }}); -$container->setParameter('fr3d_ldap.driver.accountCanonicalForm', null); -$container->setParameter('fr3d_ldap.driver.accountDomainName', null); -$container->setParameter('fr3d_ldap.driver.accountDomainNameShort', null); -$container->setParameter('fr3d_ldap.user.enabled', {{ ldap.enabled|raw }}); -$container->setParameter('fr3d_ldap.user.baseDn', {{ ldap.user_basedn|raw }}); -$container->setParameter('fr3d_ldap.user.filter', {{ ldap.user_filter|raw }}); -$container->setParameter('fr3d_ldap.user.attribute.username', {{ ldap.user_username|raw }}); -$container->setParameter('fr3d_ldap.user.attribute.name', {{ ldap.user_name|raw }}); -$container->setParameter('fr3d_ldap.user.attribute.email', {{ ldap.user_email|raw }}); +{% for name,value in parameters %} +$container->setParameter('{{ name }}', {{ value|raw }}); +{% endfor %} diff --git a/web/setup.php b/web/setup.php @@ -7,7 +7,7 @@ $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/SetupAppKernel.php'; require_once __DIR__.'/../app/AppKernel.php'; -$kernel = new SetupAppKernel('setup', false); +$kernel = new SetupAppKernel('setup', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); diff --git a/web/setup/js/Cards/DatabaseParametersCard.MySQL.js b/web/setup/js/Cards/DatabaseParametersCard.MySQL.js @@ -31,7 +31,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { this.hostname = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Hostname', labelWidth: this.defaults.labelWidth, - value: PartKeeprSetup.getApplication().getSetupConfig().database.host + value: PartKeeprSetup.getApplication().getSetupConfig().values.database_host }); this.hostname.on("change", this.onUpdateParameters, this); @@ -39,7 +39,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { this.username = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Username', labelWidth: this.defaults.labelWidth, - value: PartKeeprSetup.getApplication().getSetupConfig().database.username + value: PartKeeprSetup.getApplication().getSetupConfig().values.database_user }); this.username.on("change", this.onUpdateParameters, this); @@ -48,7 +48,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { fieldLabel: 'Database Password', inputType: "password", labelWidth: this.defaults.labelWidth, - value: PartKeeprSetup.getApplication().getSetupConfig().database.password + value: PartKeeprSetup.getApplication().getSetupConfig().values.database_password }); this.password.on("change", this.onUpdateParameters, this); @@ -56,7 +56,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { this.databaseName = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Name', labelWidth: this.defaults.labelWidth, - value: PartKeeprSetup.getApplication().getSetupConfig().database.name + value: PartKeeprSetup.getApplication().getSetupConfig().values.database_name }); this.databaseName.on("change", this.onUpdateParameters, this); @@ -72,7 +72,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { validator: function (value) { if (value === "" || value === 0) { - this.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.port); + this.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_port); } return true; }, @@ -85,7 +85,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { this.portDefault = Ext.create("Ext.form.field.Checkbox", { boxLabel: 'Default', flex: 1, - checked: (PartKeeprSetup.getApplication().getSetupConfig().database.port === 3306), + checked: (PartKeeprSetup.getApplication().getSetupConfig().values.database_port === 3306), listeners: { change: function (field) { @@ -164,13 +164,13 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { }, onActivate: function () { this.initial = true; - this.hostname.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.host); - this.username.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.user); - this.password.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.password); - this.databaseName.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.name); + this.hostname.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_host); + this.username.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_user); + this.password.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_password); + this.databaseName.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_name); - if (PartKeeprSetup.getApplication().getSetupConfig().database.port) { - this.port.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.port); + if (PartKeeprSetup.getApplication().getSetupConfig().values.database_port) { + this.port.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_port); this.portDefault.setValue(false); this.port.setDisabled(false); } @@ -215,13 +215,13 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', { var config = PartKeeprSetup.getApplication().getSetupConfig(); Ext.apply(config, { - database: { - driver: 'pdo_mysql', - host: this.hostname.getValue(), - user: this.username.getValue(), - password: this.password.getValue(), - name: this.databaseName.getValue(), - port: this.port.getValue() + values: { + database_driver: 'pdo_mysql', + database_host: this.hostname.getValue(), + database_user: this.username.getValue(), + database_password: this.password.getValue(), + database_name: this.databaseName.getValue(), + database_port: this.port.getValue() } }); diff --git a/web/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js b/web/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js @@ -190,12 +190,12 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.PostgreSQL', { Ext.apply(config, { database: { - driver: 'pdo_pgsql', - host: this.hostname.getValue(), - user: this.username.getValue(), - password: this.password.getValue(), - name: this.databaseName.getValue(), - port: this.port.getValue() + database_driver: 'pdo_pgsql', + database_host: this.hostname.getValue(), + database_user: this.username.getValue(), + database_password: this.password.getValue(), + database_name: this.databaseName.getValue(), + database_port: this.port.getValue() } }); } diff --git a/web/setup/js/Cards/DatabaseParametersCard.js b/web/setup/js/Cards/DatabaseParametersCard.js @@ -77,7 +77,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', { valueField: 'type', triggerAction: 'all', editable: false, - value: PartKeeprSetup.getApplication().getSetupConfig().database.driver + value: PartKeeprSetup.getApplication().getSetupConfig().values.database_driver }); this.databaseDropdown.on("change", this.onDriverSelect, this); @@ -107,7 +107,7 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', { */ onActivate: function () { - this.databaseDropdown.setValue(PartKeeprSetup.getApplication().getSetupConfig().database.driver); + this.databaseDropdown.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_driver); this.onDriverSelect(null, this.databaseDropdown.getValue()); // Disable the "next" button, this needs to get enabled by the database cards diff --git a/web/setup/js/PartKeeprSetup.js b/web/setup/js/PartKeeprSetup.js @@ -12,13 +12,15 @@ Ext.application({ createLayout: function () { var initialConfig = { - database: { - driver: "", - host: "", - name: "", - user: "", - password: "", - port: null + values: { + database_driver: "", + database_host: "", + database_port: "", + database_name: "", + database_user: "", + database_password: "", + authentication_provider: "PartKeepr.Auth.WSSEAuthenticationProvider", + locale: "en" }, adminuser: { username: "",