partkeepr

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

commit 694f5d7b75485e1449b7353e83da38c6e5dd4dff
parent a3d2dd79bdda2f3d5986736d5b67a5c73bcff6b0
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 23 Dec 2011 08:42:55 +0100

Added initial postgresql support

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/Category/AbstractCategory.php | 2+-
Msrc/backend/de/RaumZeitLabor/PartKeepr/FootprintCategory/FootprintCategory.php | 2+-
Msrc/backend/de/RaumZeitLabor/PartKeepr/PartCategory/PartCategory.php | 2+-
Msrc/backend/de/RaumZeitLabor/PartKeepr/Setup/PartUnitSetup.php | 5+++--
Msrc/backend/de/RaumZeitLabor/PartKeepr/Setup/Setup.php | 29+++++++++++++++++++++--------
Msrc/backend/de/RaumZeitLabor/PartKeepr/Setup/UserSetup.php | 3++-
Msrc/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js | 161++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/setup/js/Cards/DatabaseParametersCard.js | 5++---
Msrc/setup/setup.php | 4++--
9 files changed, 188 insertions(+), 25 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Category/AbstractCategory.php b/src/backend/de/RaumZeitLabor/PartKeepr/Category/AbstractCategory.php @@ -9,7 +9,7 @@ declare(encoding = 'UTF-8'); /** * @MappedSuperclass - * @Table(indexes={@index(name="lft", columns={"lft"}),@index(name="rgt", columns={"rgt"})}) + * @Table(indexes={@index(columns={"lft"}),@index(columns={"rgt"})}) * * Represents an abstract category */ diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/FootprintCategory/FootprintCategory.php b/src/backend/de/RaumZeitLabor/PartKeepr/FootprintCategory/FootprintCategory.php @@ -7,7 +7,7 @@ declare(encoding = 'UTF-8'); /** * @Entity - * @Table(indexes={@index(name="lft", columns={"lft"}),@index(name="rgt", columns={"rgt"})}) + * @Table(indexes={@index(columns={"lft"}),@index(columns={"rgt"})}) * The entity for our footprint categories * */ diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/PartCategory/PartCategory.php b/src/backend/de/RaumZeitLabor/PartKeepr/PartCategory/PartCategory.php @@ -7,7 +7,7 @@ declare(encoding = 'UTF-8'); /** * @Entity - * @Table(indexes={@index(name="lft", columns={"lft"}),@index(name="rgt", columns={"rgt"})}) + * @Table(indexes={@index(columns={"lft"}),@index(columns={"rgt"})}) * The entity for our part categories * */ diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/PartUnitSetup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/PartUnitSetup.php @@ -15,8 +15,9 @@ class PartUnitSetup extends AbstractSetup { * Sets up the default part unit if none exists */ public function run () { - $dql = "SELECT COUNT(p) FROM de\RaumZeitLabor\PartKeepr\Part\PartUnit p WHERE p.is_default = 1"; - $query = $this->entityManager->createQuery($dql); + $dql = "SELECT COUNT(p) FROM de\RaumZeitLabor\PartKeepr\Part\PartUnit p WHERE p.is_default = :default"; + $query = $this->entityManager->createQuery($dql); + $query->setParameter("default", true); if ($query->getSingleScalarResult() == 0) { $partUnit = new PartUnit(); diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/Setup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/Setup.php @@ -126,17 +126,30 @@ class Setup { * Sets the database configuration array from $_REQUEST */ public static function setDatabaseConfigurationFromRequest () { + if (isset($_REQUEST["dbname"])) { + PartKeeprConfiguration::setOption("partkeepr.database.dbname", $_REQUEST["dbname"]); + } + + if (isset($_REQUEST["user"])) { + PartKeeprConfiguration::setOption("partkeepr.database.username", $_REQUEST["user"]); + } + if (isset($_REQUEST["password"])) { + PartKeeprConfiguration::setOption("partkeepr.database.password", $_REQUEST["password"]); + } + if (isset($_REQUEST["host"])) { + PartKeeprConfiguration::setOption("partkeepr.database.host", $_REQUEST["host"]); + } + + if (isset($_REQUEST['port'])) { + PartKeeprConfiguration::setOption("partkeepr.database.port", $_REQUEST["port"]); + } + switch ($_REQUEST["driver"]) { case "mysql": PartKeeprConfiguration::setOption("partkeepr.database.driver","pdo_mysql"); - PartKeeprConfiguration::setOption("partkeepr.database.dbname", $_REQUEST["dbname"]); - PartKeeprConfiguration::setOption("partkeepr.database.username", $_REQUEST["user"]); - PartKeeprConfiguration::setOption("partkeepr.database.password", $_REQUEST["password"]); - PartKeeprConfiguration::setOption("partkeepr.database.host", $_REQUEST["host"]); - - if (isset($_REQUEST['port'])) { - PartKeeprConfiguration::setOption("partkeepr.database.mysql_port", $_REQUEST["port"]); - } + break; + case "pgsql": + PartKeeprConfiguration::setOption("partkeepr.database.driver","pdo_pgsql"); break; default: throw new \Exception(sprintf("Invalid driver %s specified.", $_REQUEST["driver"])); diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/UserSetup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/UserSetup.php @@ -8,9 +8,10 @@ use de\RaumZeitLabor\PartKeepr\User\User; */ class UserSetup extends AbstractSetup { public function run () { - $dql = "SELECT COUNT(u) FROM de\RaumZeitLabor\PartKeepr\User\User u WHERE u.username = :username OR u.admin = 1"; + $dql = "SELECT COUNT(u) FROM de\RaumZeitLabor\PartKeepr\User\User u WHERE u.username = :username OR u.admin = :admin"; $query = $this->entityManager->createQuery($dql); $query->setParameter("username", "admin"); + $query->setParameter("admin", true); if ($query->getSingleScalarResult() == 0) { $user = new User(); diff --git a/src/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js b/src/setup/js/Cards/DatabaseParametersCard.PostgreSQL.js @@ -4,7 +4,11 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.PostgreSQL', { extend: 'Ext.panel.Panel', + /* + * Various style settings + */ border: false, + layout: 'column', bodyStyle: { background: "none" }, @@ -12,35 +16,180 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.PostgreSQL', { labelWidth: 120 }, + /** + * Initializes the component and creates the various fields + */ initComponent: function () { + this.createHintTemplate = Ext.create("Ext.Template", [ + "<code>CREATE USER {user} WITH UNENCRYPTED PASSWORD '{password}; CREATE DATABASE {dbname} OWNER {user}<br/><br/></code>" + ]); + + this.masterTemplate = Ext.create("Ext.Template", ["The database must be manually created prior installation." ]); + this.hostname = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Hostname', labelWidth: this.defaults.labelWidth }); + this.hostname.on("change", this.onUpdateParameters, this); + this.username = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Username', labelWidth: this.defaults.labelWidth }); + this.username.on("change", this.onUpdateParameters, this); + this.password = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Password', inputType: "password", labelWidth: this.defaults.labelWidth }); + this.password.on("change", this.onUpdateParameters, this); + this.databaseName = Ext.create("Ext.form.field.Text", { fieldLabel: 'Database Name', labelWidth: this.defaults.labelWidth }); - this.items = [ - this.hostname, - this.databaseName, - this.username, - this.password - ]; + this.databaseName.on("change", this.onUpdateParameters, this); + + this.port = Ext.create("Ext.form.field.Number", { + minValue: 0, + flex: 1, + disabled: true, + value: '5432', + labelWidth: this.defaults.labelWidth, + validateOnBlur: true, + validateOnChange: false, + validator: function (value) { + if (value === "" || value === 0) { + this.setValue(5432); + } + return true; + } + }); + + this.portDefault = Ext.create("Ext.form.field.Checkbox", { + boxLabel: 'Default', + flex: 1, + checked: true, + listeners: { + change: function (field) { + if (field.getValue()) { + this.port.disable(); + this.port.setValue(5432); + } else { + this.port.enable(); + } + }, + scope: this + } + }); + + this.showHintCheckbox = Ext.create("Ext.form.field.Checkbox", { + xtype: 'checkboxfield', + boxLabel: 'Show commands to create the database', + listeners: { + change: this.onUpdateParameters, + scope: this + } + }); + + this.items = [{ + xtype: 'panel', + border: false, + width: "300px", + bodyStyle: { + background: "none" + }, + items: [ + this.hostname, + this.databaseName, + this.username, + this.password, + { + xtype: 'fieldcontainer', + labelWidth: this.defaults.labelWidth, + layout: 'hbox', + width: 300, + fieldLabel: 'Database Port', + items: [ this.port, this.portDefault ] + } + + ] + },{ + xtype: 'panel', + border: false, + bodyStyle: { + background: "none" + }, + items: [ + this.showHintCheckbox, + { + border: false, + style: 'overflow: auto;', + width: "450px", + height: "100px", + autoScroll: true, + layout: 'fit', + id: 'postgresql-parameters-hint', + html: "&nbsp" + }] + }]; this.callParent(); + + this.on("activate", this.onUpdateParameters, this); + }, + /** + * This method gets fired as soon as something in the form was changed. + * + * We do this because of the real-time update of the "hints" message, which + * assists the user with commands to execute on the database. + */ + onUpdateParameters: function () { + if (this.showHintCheckbox.checked) { + var host; + + if (this.hostname.getValue() == "localhost" || this.hostname.getValue() == "127.0.0.1") { + host = this.hostname.getValue(); + } else { + host = "&lt;YOUR-CONNECTING-IP&gt;"; + } + + this.createHintTemplate.overwrite(Ext.get("postgresql-parameters-hint"), { + localhost: host, + user: this.username.getValue(), + password: this.password.getValue(), + dbname: this.databaseName.getValue() + }); + + this.masterTemplate.append(Ext.get("postgresql-parameters-hint")); + } else { + this.masterTemplate.overwrite(Ext.get("postgresql-parameters-hint")); + } + + if (this.hostname.getValue() !== "" && this.username.getValue() !== "" && this.password.getValue() !== "" && + this.databaseName.getValue() !== "") { + + this.paramsheet.ownerCt.ownerCt.nextButton.setDisabled(false); + } + + this.paramsheet.dbparams = { + driver: 'pgsql', + host: this.hostname.getValue(), + user: this.username.getValue(), + password: this.password.getValue(), + dbname: this.databaseName.getValue() + }; + + if (!this.portDefault.getValue()) { + if (this.port.getValue() != 5432) { + this.paramsheet.dbparams.port = this.port.getValue(); + } + } + } }); \ No newline at end of file diff --git a/src/setup/js/Cards/DatabaseParametersCard.js b/src/setup/js/Cards/DatabaseParametersCard.js @@ -61,9 +61,8 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', { var databaseTypes = Ext.create('Ext.data.Store', { fields: ['type', 'name'], data : [ - {"type":"mysql", "name":"MySQL"} - //For the first version, we only support MySQL as database - //{"type":"postgresql", "name":"PostgreSQL"} + {"type":"mysql", "name":"MySQL"}, + {"type":"postgresql", "name":"PostgreSQL"} ] }); diff --git a/src/setup/setup.php b/src/setup/setup.php @@ -12,13 +12,13 @@ include("../src/backend/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); PartKeepr::initializeClassLoaders(); try { - $onnectionOptions = Setup::setDatabaseConfigurationFromRequest(); + Setup::setDatabaseConfigurationFromRequest(); } catch (\Exception $e) { echo json_encode(array("error" => true, "errormessage" => $e->getMessage())); exit; } -PartKeepr::initialize(); +PartKeepr::initializeDoctrine(); $setup = new Setup();