Merge pull request #485 from fabianwolf/master
Fix multiple bugs related to database settings
This commit is contained in:
commit
c0a1cb401c
3 changed files with 91 additions and 32 deletions
|
@ -78,7 +78,9 @@ class Database extends \Flake\Core\Controller {
|
|||
}
|
||||
|
||||
public function validateConnection($oForm, $oMorpho) {
|
||||
|
||||
if($oForm->refreshed()){
|
||||
return TRUE;
|
||||
}
|
||||
$bMySQLEnabled = $oMorpho->element("PROJECT_DB_MYSQL")->value();
|
||||
|
||||
if($bMySQLEnabled) {
|
||||
|
@ -120,26 +122,12 @@ class Database extends \Flake\Core\Controller {
|
|||
|
||||
return TRUE;
|
||||
} catch(\Exception $e) {
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_DB_MYSQL"),
|
||||
"Baïkal was not able to establish a connexion to the MySQL database as configured.<br />MySQL says: " . $e->getMessage()
|
||||
);
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_DB_MYSQL_HOST")
|
||||
);
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_DB_MYSQL_DBNAME")
|
||||
);
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_DB_MYSQL_USERNAME")
|
||||
);
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")
|
||||
);
|
||||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"),
|
||||
"Baïkal was not able to establish a connexion to the MySQL database as configured.<br />MySQL says: " . $e->getMessage());
|
||||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST"));
|
||||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME"));
|
||||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME"));
|
||||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD"));
|
||||
}
|
||||
} else {
|
||||
|
||||
|
@ -153,6 +141,19 @@ class Database extends \Flake\Core\Controller {
|
|||
// We'll have to clean this up later.
|
||||
$sFile = eval('return ' . $sFile . ';');
|
||||
|
||||
# Asserting DB file is writable
|
||||
if(file_exists($sFile) && !is_writable($sFile)) {
|
||||
$sMessage = "DB file is not writable. Please give write permissions on file <span style='font-family: monospace'>" . $sFile . "</span>";
|
||||
$oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
|
||||
return FALSE;
|
||||
}
|
||||
# Asserting DB directory is writable
|
||||
if(!is_writable(dirname($sFile))) {
|
||||
$sMessage = "The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder <span style='font-family: monospace'>" . dirname($sFile) . "</span>";
|
||||
$oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
$oDb = new \Flake\Core\Database\Sqlite(
|
||||
$sFile
|
||||
|
|
|
@ -80,6 +80,9 @@ class System extends \Flake\Core\Controller {
|
|||
}
|
||||
|
||||
public function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
|
||||
if($oForm->refreshed()){
|
||||
return TRUE;
|
||||
}
|
||||
if(intval($oForm->modelInstance()->get("PROJECT_DB_MYSQL")) === 1) {
|
||||
|
||||
# We have to check the MySQL connection
|
||||
|
@ -113,6 +116,54 @@ class System extends \Flake\Core\Controller {
|
|||
$oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"), $sMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
$sFile = $oMorpho->element("PROJECT_SQLITE_FILE")->value();
|
||||
|
||||
try {
|
||||
|
||||
// not sure yet how to better address this
|
||||
// yup! this is mental, but even if we don't use eval, effectively these
|
||||
// config settings are eval'ed because they are written as raw php files.
|
||||
// We'll have to clean this up later.
|
||||
$sFile = eval('return ' . $sFile . ';');
|
||||
|
||||
# Asserting DB file is writable
|
||||
if(file_exists($sFile) && !is_writable($sFile)) {
|
||||
$sMessage = "DB file is not writable. Please give write permissions on file <span style='font-family: monospace'>" . $sFile . "</span>";
|
||||
$oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
|
||||
return;
|
||||
}
|
||||
# Asserting DB directory is writable
|
||||
if(!is_writable(dirname($sFile))) {
|
||||
$sMessage = "The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder <span style='font-family: monospace'>" . dirname($sFile) . "</span>";
|
||||
$oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$oDb = new \Flake\Core\Database\Sqlite(
|
||||
$sFile
|
||||
);
|
||||
|
||||
if(($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== TRUE) {
|
||||
$sMessage = "<br /><p><strong>Database is not structurally complete.</strong></p>";
|
||||
$sMessage .= "<p>Missing tables are: <strong>" . implode("</strong>, <strong>", $aMissingTables) . "</strong></p>";
|
||||
$sMessage .= "<p>You will find the SQL definition of Baïkal tables in this file: <strong>Core/Resources/Db/SQLite/db.sql</strong></p>";
|
||||
$sMessage .= "<br /><p>Nothing has been saved. <strong>Please, add these tables to the database before pursuing Baïkal initialization.</strong></p>";
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_SQLITE_FILE"),
|
||||
$sMessage
|
||||
);
|
||||
}
|
||||
return ;
|
||||
} catch(\Exception $e) {
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("PROJECT_SQLITE_FILE"),
|
||||
"Baïkal was not able to establish a connexion to the SQLite database as configured.<br />SQLite says: " . $e->getMessage() . (string)$e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,7 +224,10 @@ class Framework extends \Flake\Core\Framework {
|
|||
}
|
||||
|
||||
protected static function initDb() {
|
||||
|
||||
# Dont init db on install, but in normal mode and when upgrading
|
||||
if(defined("BAIKAL_CONTEXT_INSTALL") && (BAIKAL_CONFIGURED_VERSION === BAIKAL_VERSION)) {
|
||||
return true;
|
||||
}
|
||||
if(defined("PROJECT_DB_MYSQL") && PROJECT_DB_MYSQL === TRUE) {
|
||||
self::initDbMysql();
|
||||
} else {
|
||||
|
@ -274,15 +277,19 @@ class Framework extends \Flake\Core\Framework {
|
|||
die("<h3>The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.<br />You should set it in Specific/config.system.php</h3>");
|
||||
}
|
||||
|
||||
$GLOBALS["DB"] = new \Flake\Core\Database\Mysql(
|
||||
PROJECT_DB_MYSQL_HOST,
|
||||
PROJECT_DB_MYSQL_DBNAME,
|
||||
PROJECT_DB_MYSQL_USERNAME,
|
||||
PROJECT_DB_MYSQL_PASSWORD
|
||||
);
|
||||
try {
|
||||
$GLOBALS["DB"] = new \Flake\Core\Database\Mysql(
|
||||
PROJECT_DB_MYSQL_HOST,
|
||||
PROJECT_DB_MYSQL_DBNAME,
|
||||
PROJECT_DB_MYSQL_USERNAME,
|
||||
PROJECT_DB_MYSQL_PASSWORD
|
||||
);
|
||||
|
||||
# We now setup the connection to use UTF8
|
||||
$GLOBALS["DB"]->query("SET NAMES UTF8");
|
||||
# We now setup t6he connexion to use UTF8
|
||||
$GLOBALS["DB"]->query("SET NAMES UTF8");
|
||||
} catch(\Exception $e) {
|
||||
die("<h3>Baïkal was not able to establish a connexion to the configured MySQL database (as configured in Specific/config.system.php).</h3>");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue