commit 6109c7b38f3d67432dd03dd29541fa8e0a367a2f
parent e27045d92636296ecb14b19b5f5527503d7ec7f0
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 20 Dec 2011 09:02:02 +0100
Added lots of documentation, refactored the test cards, minor changes and improvements
Diffstat:
19 files changed, 417 insertions(+), 344 deletions(-)
diff --git a/src/setup/index.html b/src/setup/index.html
@@ -35,13 +35,14 @@
<script type="text/javascript" src="js/TestResultPanel.js"></script>
<script type="text/javascript" src="js/TestRunner.js"></script>
+ <script type="text/javascript" src="js/Cards/AbstractTestCard.js"></script>
<script type="text/javascript" src="js/Cards/PrequisitesTestCard.js"></script>
<script type="text/javascript" src="js/Cards/DatabaseParametersCard.js"></script>
<script type="text/javascript" src="js/Cards/DatabaseParametersCard.MySQL.js"></script>
<script type="text/javascript" src="js/Cards/DatabaseParametersCard.PostgreSQL.js"></script>
<script type="text/javascript" src="js/Cards/DatabaseConnectivityTestCard.js"></script>
- <script type="text/javascript" src="js/SetupTests/BaseSetupTest.js"></script>
+ <script type="text/javascript" src="js/SetupTests/AbstractTest.js"></script>
<script type="text/javascript" src="js/SetupTests/PHPTest.js"></script>
<script type="text/javascript" src="js/SetupTests/PHPPrequisitesTest.js"></script>
<script type="text/javascript" src="js/SetupTests/DoctrineTest.js"></script>
diff --git a/src/setup/js/Cards/AbstractTestCard.js b/src/setup/js/Cards/AbstractTestCard.js
@@ -0,0 +1,132 @@
+/**
+ * This class represents an abstract test card. The purpose of this card is to run
+ * specific tests, display the test results and offer a "re-test" button which the
+ * user can click in order to perform the tests.
+ *
+ * Additionally, the "next" button of the wizward will be disabled if the test fails.
+ */
+Ext.define('PartKeeprSetup.AbstractTestCard', {
+ extend: 'Ext.ux.wizard.Card',
+
+ /**
+ * Contains the test results for this card
+ * @var PartKeeprSetup.TestResultPanel
+ */
+ testResultPanel: null,
+
+ /**
+ * Contains the initially hidden "Re-test" button to re-trigger the tests.
+ */
+ retestButton: null,
+
+ /**
+ * Contains the test which will be run
+ * @var array
+ */
+ tests: null,
+
+ /**
+ * Text which will be shown above the test result panel.
+ * @var string
+ */
+ cardMessage: null,
+
+ /**
+ * Various Style Settings
+ */
+ title: 'Checking Database Connectivity',
+ showTitle: true,
+ titleCls: '',
+ titleStyle: 'font-size: 2.5em;',
+ cls: 'x-partkeepr-setup-basecard',
+ autoScroll: true,
+
+
+ /**
+ * Inits the component
+ */
+ initComponent: function () {
+ this.testResultPanel = Ext.create("PartKeeprSetup.TestResultPanel");
+ this.testResultPanel.on("test-error", this.onTestError, this);
+
+ this.retestButton = Ext.create("Ext.button.Button", {
+ text: 'Re-run checks',
+ hidden: true
+ });
+
+ this.retestButton.on("click", this.retest, this);
+
+ this.items = [{
+ border: false,
+ bodyStyle: 'background:none;padding-bottom: 10px;',
+ html: this.cardMessage
+ },
+ this.testResultPanel,
+ this.retestButton ];
+
+ this.tests = new Array();
+ this.setupTests();
+ this.callParent();
+ this.on("activate", this.onActivate, this);
+ },
+
+ /**
+ * Re-runs the configured tests and hides the Re-test button,
+ * because we don't know if the tests will be successful.
+ */
+ retest: function () {
+ this.retestButton.hide();
+ this.runTests();
+ },
+ /**
+ * Called when an error occurs. Shows the "re-test" button
+ * and disables the "next" button.
+ */
+ onTestError: function () {
+ this.retestButton.show();
+ this.ownerCt.ownerCt.nextButton.setDisabled(true);
+ },
+ /**
+ * Called when all tests are successful. Hides the "re-test"
+ * button and enables the "next" button.
+ */
+ onTestSuccessful: function () {
+ this.retestButton.hide();
+ this.ownerCt.ownerCt.nextButton.setDisabled(false);
+ },
+ /**
+ * Invokes the test runner with all configured tests
+ */
+ runTests: function () {
+ this.testResultPanel.clear();
+
+ var tr = Ext.create("PartKeeprSetup.TestRunner");
+
+ // We need to clone the test array, because we wouldn't be able to run all tests twice
+ var clonedTests = this.tests.slice(0);
+ tr.run(clonedTests);
+ tr.on("success", this.onTestSuccessful, this);
+ },
+ /**
+ * When the card is activated, automatically invoke all tests.
+ */
+ onActivate: function () {
+ this.ownerCt.ownerCt.nextButton.setDisabled(true);
+ this.retestButton.hide();
+
+ this.runTests();
+ },
+ /**
+ * This method needs to be overridden by subclasses. Subclasses
+ * need to append tests to the "tests" array, e.g.
+ *
+ * var j = Ext.create("PartKeeprSetup.FilesystemPermissionTest");
+ * j.callback = this.testResultPanel;
+ * this.tests.push(j);
+ *
+ */
+ setupTests: function () {
+ window.alert("The method setupTests() need to be overridden in a subclass!");
+ }
+});
+
diff --git a/src/setup/js/Cards/DatabaseConnectivityTestCard.js b/src/setup/js/Cards/DatabaseConnectivityTestCard.js
@@ -1,88 +1,20 @@
-
/**
* This card tests the database connectivity for the MySQL database.
+ *
+ * Basically this submits all connection settings to a special PHP script,
+ * which then attempts to establish the database connection.
*/
Ext.define('PartKeeprSetup.DatabaseConnectivityTestCard', {
- extend: 'Ext.ux.wizard.Card',
+ extend: 'PartKeeprSetup.AbstractTestCard',
- /**
- * Contains the test results for this card
- * @var PartKeeprSetup.TestResultPanel
- */
- testResultPanel: null,
+ cardMessage: "Setup tests if the database is reachable. Please note that this may take a minute or two to display a status if your database is not reachable.",
/**
- * Contains the initially hidden "Re-test" button to re-trigger the tests.
- */
- retestButton: null,
-
- /**
- * Various Style Settings
- */
- title: 'Checking Database Connectivity',
- showTitle: true,
- titleCls: '',
- titleStyle: 'font-size: 2.5em;',
- cls: 'x-partkeepr-setup-basecard',
-
- autoScroll: true,
-
-
-
- /**
- * Inits the component
+ * Sets up the tests
*/
- initComponent: function () {
- this.testResultPanel = Ext.create("PartKeeprSetup.TestResultPanel");
- this.testResultPanel.on("test-error", this.onTestError, this);
-
- this.retestButton = Ext.create("Ext.button.Button", {
- text: 'Re-run checks',
- hidden: true
- });
-
- this.retestButton.on("click", this.retest, this);
-
- this.items = [{
- border: false,
- bodyStyle: 'background:none;padding-bottom: 10px;',
- html: 'Setup tests if the database is reachable...'
- },
- this.testResultPanel,
- this.retestButton ];
-
- this.callParent();
- this.on("activate", this.onActivate, this);
- },
- retest: function () {
- this.retestButton.hide();
- this.runTests();
- },
- onActivate: function () {
- this.ownerCt.ownerCt.nextButton.setDisabled(true);
- this.retestButton.hide();
-
- this.runTests();
- },
- runTests: function () {
- this.testResultPanel.clear();
-
- var tests = new Array();
-
+ setupTests: function () {
var j = Ext.create("PartKeeprSetup.DatabaseConnectivityTest");
- j.params = Ext.getCmp("database-parameters-card").dbparams;
-
j.callback = this.testResultPanel;
- tests.push(j);
-
- var tr = Ext.create("PartKeeprSetup.TestRunner");
- tr.run(tests);
- tr.on("success", this.onTestSuccessful, this);
- },
- onTestError: function () {
- this.retestButton.show();
- },
- onTestSuccessful: function () {
- this.ownerCt.ownerCt.nextButton.setDisabled(false);
+ this.tests.push(j);
}
});
diff --git a/src/setup/js/Cards/DatabaseParametersCard.MySQL.js b/src/setup/js/Cards/DatabaseParametersCard.MySQL.js
@@ -4,6 +4,9 @@
Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
extend: 'Ext.panel.Panel',
+ /*
+ * Various style settings
+ */
border: false,
layout: 'column',
bodyStyle: {
@@ -13,6 +16,9 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
labelWidth: 120
},
+ /**
+ * Initializes the component and creates the various fields
+ */
initComponent: function () {
this.createHintTemplate = Ext.create("Ext.Template", [
"<code>CREATE DATABASE {dbname} CHARACTER SET UTF8;<br/>GRANT USAGE ON *.* TO {user}@{host} IDENTIFIED BY '{password}';<br/>GRANT ALL PRIVILEGES ON {dbname}.* TO {user}@{host};<br/><br/>"
@@ -49,6 +55,21 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
this.databaseName.on("change", this.onUpdateParameters, this);
+ this.port = Ext.create("Ext.form.field.Number", {
+ fieldLabel: 'Database Port',
+ minValue: 0,
+ value: '3306',
+ labelWidth: this.defaults.labelWidth,
+ validateOnBlur: true,
+ validateOnChange: false,
+ validator: function (value) {
+ if (value == "" || value == 0) {
+ this.setValue(3306);
+ }
+ return true;
+ }
+ });
+
this.showHintCheckbox = Ext.create("Ext.form.field.Checkbox", {
xtype: 'checkboxfield',
boxLabel: 'Show commands to create the database',
@@ -69,7 +90,8 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
this.hostname,
this.databaseName,
this.username,
- this.password
+ this.password,
+ this.port
]
},{
xtype: 'panel',
@@ -95,6 +117,12 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
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) {
this.createHintTemplate.overwrite(Ext.get("mysql-parameters-hint"), {
@@ -120,5 +148,9 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard.MySQL', {
password: this.password.getValue(),
dbname: this.databaseName.getValue()
};
+
+ if (this.port.getValue() != 3306) {
+ 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
@@ -1,5 +1,7 @@
/**
* This card displays the database parameters.
+ *
+ * This card supports multiple database types along with their special parameters.
*/
Ext.define('PartKeeprSetup.DatabaseParametersCard', {
extend: 'Ext.ux.wizard.Card',
@@ -15,8 +17,6 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', {
id: 'database-parameters-card',
autoScroll: true,
-
-
/**
* Inits the component
*/
@@ -54,12 +54,15 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', {
this.callParent();
this.on("activate", this.onActivate, this);
},
+ /**
+ * Creates the dropdown with all available database types.
+ */
createDatabaseDropdown: function () {
- // The data store containing the list of states
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"}
]
});
@@ -78,6 +81,10 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', {
this.databaseDropdown.on("select", this.onDriverSelect, this);
},
+ /**
+ * This method is a callback from the database dropdown and displays
+ * the correct database settings page.
+ */
onDriverSelect: function (a,r) {
if (r.length == 1) {
switch (r[0].get("type")) {
@@ -96,11 +103,11 @@ Ext.define('PartKeeprSetup.DatabaseParametersCard', {
this.ownerCt.ownerCt.nextButton.setDisabled(true);
},
- retest: function () {
- this.retestButton.hide();
- this.runTests();
- },
+ /**
+ * Gets called when the card is activated
+ */
onActivate: function () {
+ // Disable the "next" button, this needs to get enabled by the database cards
this.ownerCt.ownerCt.nextButton.setDisabled(true);
// Manually fire the activate event, in case the user switched cards back/forth.
diff --git a/src/setup/js/Cards/PrequisitesTestCard.js b/src/setup/js/Cards/PrequisitesTestCard.js
@@ -2,99 +2,32 @@
* This card runs the prequisites test to make sure basic things like PHP and Doctrine are installed and configured.
*/
Ext.define('PartKeeprSetup.PrequisitesTestCard', {
- extend: 'Ext.ux.wizard.Card',
+ extend: 'PartKeeprSetup.AbstractTestCard',
+ cardMessage: "Setup now checks if your server is capable of running PartKeepr.",
+
/**
- * Contains the test results for this card
- * @var PartKeeprSetup.TestResultPanel
+ * Sets up all tests
*/
- testResultPanel: null,
-
- /**
- * Contains the initially hidden "Re-test" button to re-trigger the tests.
- */
- retestButton: null,
-
- /**
- * Various Style Settings
- */
- title: 'Checking prequisites',
- showTitle: true,
- titleCls: '',
- titleStyle: 'font-size: 2.5em;',
- cls: 'x-partkeepr-setup-basecard',
-
- autoScroll: true,
-
-
-
- /**
- * Inits the component
- */
- initComponent: function () {
- this.testResultPanel = Ext.create("PartKeeprSetup.TestResultPanel");
- this.testResultPanel.on("test-error", this.onTestError, this);
-
- this.retestButton = Ext.create("Ext.button.Button", {
- text: 'Re-run checks',
- hidden: true
- });
-
- this.retestButton.on("click", this.retest, this);
-
- this.items = [{
- border: false,
- bodyStyle: 'background:none;padding-bottom: 10px;',
- html: 'Setup now checks if your server is capable of running PartKeepr.'
- },
- this.testResultPanel,
- this.retestButton ];
-
- this.callParent();
- this.on("activate", this.onActivate, this);
- },
- retest: function () {
- this.retestButton.hide();
- this.runTests();
- },
- onActivate: function () {
- this.ownerCt.ownerCt.nextButton.setDisabled(true);
- this.retestButton.hide();
- this.runTests();
- },
- runTests: function () {
- this.testResultPanel.clear();
-
- var tests = new Array();
-
+ setupTests: function () {
var j = Ext.create("PartKeeprSetup.PHPTest");
j.callback = this.testResultPanel;
- tests.push(j);
+ this.tests.push(j);
var j = Ext.create("PartKeeprSetup.PHPPrequisitesTest");
j.callback = this.testResultPanel;
- tests.push(j);
+ this.tests.push(j);
- var j = Ext.create("PartKeeprSetup.DoctrineTest");
+ var j = Ext.create("PartKeeprSetup.PHPSettingsTest");
j.callback = this.testResultPanel;
- tests.push(j);
+ this.tests.push(j);
- var j = Ext.create("PartKeeprSetup.PHPSettingsTest");
+ var j = Ext.create("PartKeeprSetup.DoctrineTest");
j.callback = this.testResultPanel;
- tests.push(j);
+ this.tests.push(j);
var j = Ext.create("PartKeeprSetup.FilesystemPermissionTest");
j.callback = this.testResultPanel;
- tests.push(j);
-
- var tr = Ext.create("PartKeeprSetup.TestRunner");
- tr.run(tests);
- tr.on("success", this.onTestSuccessful, this);
- },
- onTestError: function () {
- this.retestButton.show();
- },
- onTestSuccessful: function () {
- this.ownerCt.ownerCt.nextButton.setDisabled(false);
+ this.tests.push(j);
}
});
diff --git a/src/setup/js/PartKeeprSetup.js b/src/setup/js/PartKeeprSetup.js
@@ -1,28 +1,7 @@
Ext.application({
- name: 'PartKeepr',
+ name: 'PartKeeprSetup',
launch: function() {
-
this.createLayout();
-
- var tests = new Array();
-
-
- /*var j = Ext.create("PartKeeprSetup.PHPTest");
- j.callback = this.testResultPanel;
- tests.push(j);
-
- var j = Ext.create("PartKeeprSetup.PHPPrequisitesTest");
- j.callback = this.testResultPanel;
- tests.push(j);
-
- var j = Ext.create("PartKeeprSetup.DoctrineTest");
- j.callback = this.testResultPanel;
- tests.push(j);
-
- var tr = Ext.create("PartKeeprSetup.TestRunner");
- tr.run(tests);*/
-
- //j.on("complete", function () { this.testResultPanel.appendTestResult(this); }, j);
},
/**
* Creates the main viewport
@@ -30,12 +9,5 @@ Ext.application({
createLayout: function () {
var wizard = Ext.create("PartKeeprSetup.SetupWizard");
wizard.show();
- /*this.testResultPanel = Ext.create("PartKeeprSetup.TestResultPanel");
-
- Ext.create('Ext.container.Viewport', {
- layout: 'fit',
- items: [this.testResultPanel]
-
- });*/
}
});
\ No newline at end of file
diff --git a/src/setup/js/SetupTests/AbstractTest.js b/src/setup/js/SetupTests/AbstractTest.js
@@ -0,0 +1,93 @@
+/**
+ * Represents a test.
+ *
+ * Calls a specific PHP file on the server via AJAX and interprets the response.
+ */
+Ext.define('PartKeeprSetup.AbstractTest', {
+ extend: 'Ext.util.Observable',
+
+ /**
+ * Defines the URL to call
+ */
+ url: 'check.php',
+
+ /**
+ * Defines if the call was successful or not.
+ */
+ success: false,
+
+ /**
+ * Defines the callback. This needs to be an object which implements the "appendTestResult" method.
+ */
+ callback: null,
+
+ /**
+ * Defines the name of this test.
+ */
+ name: null,
+
+ /**
+ * Defines additional parameters which are to be sent with the request. The format is an object,
+ * e.g.
+ * {
+ * username: "foo",
+ * password: "bar"
+ * }
+ *
+ *
+ */
+ params: null,
+
+ /**
+ * Constructs the test
+ */
+ constructor: function () {
+ this.addEvents({
+ "complete" : true
+ });
+ },
+ /**
+ * Runs a given test, and processes the response
+ */
+ run: function () {
+ this.onBeforeRunTest();
+
+ Ext.Ajax.request({
+ url: this.url,
+ success: this.onSuccess,
+ scope: this,
+ params: this.params
+ });
+ },
+
+ /**
+ * Callback for the Ext.Ajax.request method. Decodes the response, sets the object parameters, fires the "complete"
+ * event and calls back the test result panel.
+ *
+ * @param response
+ */
+ onSuccess: function (response) {
+ var obj = Ext.decode(response.responseText);
+
+ if (obj.error == false) {
+ this.success = true;
+ } else {
+ this.success = false;
+ this.errorMessage = obj.errormessage;
+ }
+
+ if (this.callback) {
+ this.callback.appendTestResult(this);
+ }
+
+ if (this.success) {
+ this.fireEvent("complete");
+ }
+ },
+ /**
+ * Gets called prior test execution. Most tests won't use this, but some tests need to inject parameters.
+ */
+ onBeforeRunTest: function () {
+ return;
+ }
+});+
\ No newline at end of file
diff --git a/src/setup/js/SetupTests/BaseSetupTest.js b/src/setup/js/SetupTests/BaseSetupTest.js
@@ -1,87 +0,0 @@
-/**
- * Represents a test.
- *
- * Calls a specific PHP file on the server and
- * interprets the response.
- */
-Ext.define('PartKeeprSetup.BaseSetupTest', {
- extend: 'Ext.util.Observable',
-
- /**
- * Defines the URL to call
- */
- url: 'check.php',
-
- /**
- * Defines if the call was successful or not.
- */
- success: false,
-
- /**
- * Defines the callback. This needs to be
- * an object which implements the "appendTestResult" method.
- */
- callback: null,
-
- /**
- * Defines the name of this test.
- */
- name: null,
-
- /**
- * Defines additional parameters which are to
- * be sent with the request. The format is an object,
- * e.g.
- * {
- * username: "foo",
- * password: "bar"
- * }
- *
- *
- */
- params: null,
-
- /**
- * Constructs the test
- */
- constructor: function () {
- this.addEvents({
- "complete" : true
- });
- },
- /**
- * Runs a given test, and processes the response
- */
- run: function () {
- Ext.Ajax.request({
- url: this.url,
- success: this.onSuccess,
- scope: this,
- params: this.params
- });
- },
-
- /**
- * Callback for the Ext.Ajax.request method.
- * Decodes the response, sets the object
- * parameters, fires the "complete" event
- * and calls back the test result panel.
- *
- * @param response
- */
- onSuccess: function (response) {
- var obj = Ext.decode(response.responseText);
-
- if (obj.error == false) {
- this.success = true;
- } else {
- this.success = false;
- this.errorMessage = obj.errormessage;
- }
-
- if (this.callback) {
- this.callback.appendTestResult(this);
- }
- this.fireEvent("complete");
- }
-});-
\ No newline at end of file
diff --git a/src/setup/js/SetupTests/DatabaseConnectivityTest.js b/src/setup/js/SetupTests/DatabaseConnectivityTest.js
@@ -1,9 +1,13 @@
/**
- * A minimalistic PHP check to make sure PHP is installed on the server and activated as PHP module.
+ * Tests if the database can be reached
*/
Ext.define('PartKeeprSetup.DatabaseConnectivityTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'tests/check-database-connectivity.php',
name: "Database",
- message: "Testing for database connectivity"
+ message: "Testing for database connectivity",
+
+ onBeforeRunTest: function () {
+ this.params = Ext.getCmp("database-parameters-card").dbparams;
+ }
});
\ No newline at end of file
diff --git a/src/setup/js/SetupTests/DoctrineTest.js b/src/setup/js/SetupTests/DoctrineTest.js
@@ -1,8 +1,8 @@
/**
- * A minimalistic PHP check to make sure PHP is installed on the server and activated as PHP module.
+ * Tests is doctrine is installed correctly on the server
*/
Ext.define('PartKeeprSetup.DoctrineTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'tests/check-doctrine.php',
name: "PHP",
message: "Testing for Doctrine ORM"
diff --git a/src/setup/js/SetupTests/FilesystemPermissionTest.js b/src/setup/js/SetupTests/FilesystemPermissionTest.js
@@ -2,7 +2,7 @@
* Tests if the filesystem permissions are OK
*/
Ext.define('PartKeeprSetup.FilesystemPermissionTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'tests/check-permissions.php',
name: "Filesystem",
message: "Testing for proper filesystem permissions"
diff --git a/src/setup/js/SetupTests/PHPPrequisitesTest.js b/src/setup/js/SetupTests/PHPPrequisitesTest.js
@@ -1,8 +1,8 @@
/**
- * A minimalistic PHP check to make sure PHP is installed on the server and activated as PHP module.
+ * Tests if the most important PHP prequisites are met (e.g. json_encode).
*/
Ext.define('PartKeeprSetup.PHPPrequisitesTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'check-php-prequisites.php',
name: "PHP",
message: "Testing for PHP prequisites"
diff --git a/src/setup/js/SetupTests/PHPSettingsTest.js b/src/setup/js/SetupTests/PHPSettingsTest.js
@@ -1,8 +1,8 @@
/**
- * A minimalistic PHP check to make sure PHP is installed on the server and activated as PHP module.
+ * Tests if the PHP configuration is OK.
*/
Ext.define('PartKeeprSetup.PHPSettingsTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'tests/check-php-settings.php',
name: "PHP",
message: "Testing for correct PHP settings"
diff --git a/src/setup/js/SetupTests/PHPTest.js b/src/setup/js/SetupTests/PHPTest.js
@@ -2,7 +2,7 @@
* A minimalistic PHP check to make sure PHP is installed on the server and activated as PHP module.
*/
Ext.define('PartKeeprSetup.PHPTest', {
- extend: 'PartKeeprSetup.BaseSetupTest',
+ extend: 'PartKeeprSetup.AbstractTest',
url: 'check-php.php',
name: "PHP",
message: "Testing for PHP"
diff --git a/src/setup/js/SetupWizard.js b/src/setup/js/SetupWizard.js
@@ -1,11 +1,19 @@
Ext.define('PartKeeprSetup.SetupWizard', {
extend: 'Ext.ux.Wizard',
- width: 850,
- height: 800,
+ /**
+ * The wizard's window shouldn't have a close button
+ */
closable: false,
- name: 'FOO',
+
+ /**
+ * Title. Ovbiously.
+ */
title: 'PartKeepr Setup',
+
+ /**
+ * Some style settings for the individual cards
+ */
cardPanelConfig: {
defaults: {
baseCls: 'x-small-editor',
@@ -15,27 +23,37 @@ Ext.define('PartKeeprSetup.SetupWizard', {
layout: 'card'
},
- // no headConfig suplied no header will be shown.
+ /**
+ * Configure the header
+ */
+ includeHeaderPanel: true,
headConfig: {
- // title: 'Simple Wizard Head title Example',
headerPosition: 'bottom',
- position: 'top', // or bottom
+ position: 'top',
cls: "x-setup-header",
- stepText: "<center>Step {0} of {1}: {2}</center>"
+ stepText: ''
},
- width: 800, height: 500,
- closable: false,
+ /**
+ * The width and height of the window, in pixels
+ */
+ width: 800,
+ height: 500,
- includeHeaderPanel: true,
-
+
+ /**
+ * Initializes the component
+ */
initComponent: function () {
this.cards = this.setupCards();
this.callParent();
this.headPanel.show();
},
-
+ /**
+ * Sets up all cards
+ * @returns {Array}
+ */
setupCards: function () {
var cards = new Array();
@@ -56,31 +74,6 @@ Ext.define('PartKeeprSetup.SetupWizard', {
cards.push(Ext.create("PartKeeprSetup.PrequisitesTestCard"));
cards.push(Ext.create("PartKeeprSetup.DatabaseParametersCard"));
cards.push(Ext.create("PartKeeprSetup.DatabaseConnectivityTestCard"));
- /*
- Ext.create('Ext.ux.wizard.Card', {
- deferredRender: true,
- title: 'Checking prequisites',
- showTitle: true,
- titleCls: '',
- autoScroll: true,
- titleStyle: 'font-size: 2.5em;',
- cls: 'x-partkeepr-setup-basecard',
- items: [{
- border: false,
- bodyStyle: 'background:none;margin-bottom: 2px;',
- html: 'Setup now checks if your server is capable of running PartKeepr.'
- }, this.testResultPanel, this.retestPrequisitesButton ],
- listeners: {
- activate: function () {
- this.nextButton.setDisabled(true);
-
- this.testResultPanel.clear();
-
-
- },
- scope: this
- }
- }));*/
return cards;
}
diff --git a/src/setup/js/TestResultPanel.js b/src/setup/js/TestResultPanel.js
@@ -23,7 +23,7 @@ Ext.define('PartKeeprSetup.TestResultPanel', {
* Appends the specific test to the output panel,
* and fires the error event if an error occured.
*
- * @param test PartKeeprSetup.BaseSetupTest
+ * @param test PartKeeprSetup.AbstractTest
*/
appendTestResult: function (test) {
var response;
diff --git a/src/setup/js/TestRunner.js b/src/setup/js/TestRunner.js
@@ -1,11 +1,25 @@
+/**
+ * Implements a sequential test runner, which waits for previous tests to complete.
+ *
+ * This is used with asynchronous tests.
+ */
Ext.define('PartKeeprSetup.TestRunner', {
extend: 'Ext.util.Observable',
+ /**
+ * Initialize the component
+ */
initComponent: function () {
this.addEvents("success");
this.callParent();
},
+ /**
+ * Runs the given tests. Each test must fire the "complete" event in
+ * order to be runable.
+ *
+ * @param tests An array of tests
+ */
run: function (tests) {
test = tests.shift();
diff --git a/src/setup/tests/check-database-connectivity.php b/src/setup/tests/check-database-connectivity.php
@@ -1,21 +1,36 @@
<?php
+/**
+ * Tests the connection to the database.
+ */
require_once 'Doctrine/Common/ClassLoader.php';
use Doctrine\Common\ClassLoader;
$classLoader = new ClassLoader('Doctrine\DBAL');
-$classLoader->register(); // register on SPL autoload stack
+$classLoader->register();
$classLoader = new ClassLoader('Doctrine\Common');
-$classLoader->register(); // register on SPL autoload stack
-
+$classLoader->register();
$config = new \Doctrine\DBAL\Configuration();
+/**
+ * Check which driver we are going to use, and set the connection parameters accordingly.
+ */
switch ($_REQUEST["driver"]) {
case "mysql":
- $driver = "pdo_mysql";
+ $connectionOptions = array(
+ 'driver' => "pdo_mysql",
+ 'dbname' => $_REQUEST["dbname"],
+ 'user' => $_REQUEST["user"],
+ 'password' => $_REQUEST["password"],
+ 'host' => $_REQUEST["host"],
+ );
+
+ if (isset($_REQUEST['port'])) {
+ $connectionOptions['port'] = $_REQUEST['port'];
+ }
break;
default:
echo json_encode(array("error" => true, "errormessage" => "Unknown driver ".$_REQUEST["driver"]));
@@ -23,20 +38,14 @@ switch ($_REQUEST["driver"]) {
break;
}
-$connectionOptions = array(
- 'driver' => $driver,
- 'dbname' => $_REQUEST["dbname"],
- 'user' => $_REQUEST["user"],
- 'password' => $_REQUEST["password"],
- 'host' => $_REQUEST["host"]
-);
-
-
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionOptions, $config);
+
try {
$conn->connect();
} catch (\PDOException $e) {
- echo json_encode(array("error" => true, "errormessage" => "There was an error connecting to the database:<br/><code>".$e->getMessage()."</code>"));
+ $additionalMessage = getPlatformSpecificErrorMessage($_REQUEST["driver"], $e->getCode());
+
+ echo json_encode(array("error" => true, "errormessage" => "There was an error connecting to the database:<br/><code>".$e->getMessage()."</code>".$additionalMessage));
exit;
} catch (\Exception $e) {
echo json_encode(array("error" => true, "errormessage" => "An unknown error occured. The error is: <code>".$e->getMessage()."</code>"));
@@ -44,3 +53,40 @@ try {
}
echo json_encode(array("error" => false));
+
+/**
+ * Returns error messages for a specific platform and PDOException code
+ * @param string $platform
+ * @param int $code
+ * @return An error message, or "" if no message is available.
+ */
+function getPlatformSpecificErrorMessage($platform, $code) {
+ switch ($platform) {
+ case "mysql":
+ return getMySQLSpecificErrorMessage($code);
+ break;
+ default:
+ return "";
+ }
+}
+
+/**
+ * Returns error messages for a specific PDOException code.
+ * @param int $code
+ * @return An error message, or "" if no message is available.
+ */
+function getMySQLSpecificErrorMessage ($code) {
+ switch ($code) {
+ case 1044:
+ return "<br/><br/>You need to grant permissions to the database, or you haven't created the database yet.";
+ break;
+ case 1045:
+ return "<br/><br/>It seems that you have mistyped your username or password.";
+ break;
+ case 2013:
+ return "<br/><br/>This error is an indication that the database host you have specified is not reachable, or that your database runs on a different port.";
+ break;
+ default:
+ return "";
+ }
+}+
\ No newline at end of file