commit f3d0354f6e266d6845c37b14255fdb202de7d3a9
parent 26210bb3ed21f19c0d5417327358b68d7dd4a401
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 23 Dec 2011 15:54:12 +0100
Refactoring of the MySQL UTF-8 test, fixes #73
Diffstat:
4 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/SchemaSetup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/SchemaSetup.php
@@ -12,4 +12,23 @@ class SchemaSetup extends AbstractSetup {
$tool->updateSchema($classes);
$this->logMessage("Database Schema created/updated");
}
+
+ /**
+ * Checks if the specified database has UTF-8 encoding
+ * @param $connection The DBAL connection
+ * @param string $dbname
+ */
+ public static function mysqlHasUTF8Encoding ($connection, $dbname) {
+ $statement = $connection->prepare("SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = :schema");
+ $statement->bindValue("schema", $dbname);
+ $statement->execute();
+
+ $encoding = $statement->fetchColumn(0);
+
+ if ($encoding != "utf8") {
+ return false;
+ } else {
+ return true;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/Setup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/Setup.php
@@ -156,4 +156,19 @@ class Setup {
break;
}
}
+
+ /**
+ * Runs some checks for the CLI setup
+ */
+ public function runCLIChecks () {
+
+ if (PartKeeprConfiguration::getOption("partkeepr.database.driver") == "pdo_mysql") {
+ $dbname = PartKeeprConfiguration::getOption("partkeepr.database.dbname");
+ if (!SchemaSetup::mysqlHasUTF8Encoding(PartKeepr::getEM()->getConnection(), $dbname )) {
+ echo "Error: The database $dbname hasn't got the UTF-8 encoding. You need to set the database encoding to UTF-8. Aborting.\n";
+ die;
+ }
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/setup/tests/check-database-connectivity.php b/src/setup/tests/check-database-connectivity.php
@@ -6,7 +6,8 @@ include("../../src/backend/de/RaumZeitLabor/PartKeepr/PartKeepr.php");
use Doctrine\Common\ClassLoader;
use de\RaumZeitLabor\PartKeepr\PartKeepr,
- de\RaumZeitLabor\PartKeepr\Setup\Setup;
+ de\RaumZeitLabor\PartKeepr\Setup\Setup,
+ de\RaumZeitLabor\PartKeepr\Setup\SchemaSetup;
PartKeepr::initializeClassLoaders();
@@ -58,13 +59,7 @@ switch ($_REQUEST["driver"]) {
}
function performAdditionalMySQLTests ($connection, $dbname) {
- $statement = $connection->prepare("SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = :schema");
- $statement->bindValue("schema", $dbname);
- $statement->execute();
-
- $encoding = $statement->fetchColumn(0);
-
- if ($encoding != "utf8") {
+ if (!SchemaSetup::mysqlHasUTF8Encoding($connection, $dbname)) {
echo json_encode(array("error" => true, "errormessage" => "Your database doesn't have the proper encoding. Please change it using the following SQL statement: <br/><br/><code>ALTER DATABASE ".$dbname." CHARACTER SET utf8;</code>"));
exit;
}
diff --git a/testing/SetupDatabase.php b/testing/SetupDatabase.php
@@ -70,7 +70,8 @@ if ($ask) {
echo "Performing actions...\n";
$setup = new Setup();
-$setup->setConsole();
+$setup->setConsole();
+$setup->runCLIChecks();
$setup->run();