diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php
index d3a1f8b..e71be03 100644
--- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php
+++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php
@@ -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.
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.
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 " . $sFile . "";
+ $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
+ return FALSE;
+ }
+ # Asserting DB directory is writable
+ if(!is_writable(dirname($sFile))) {
+ $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . "";
+ $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
+ return FALSE;
+ }
+
$oDb = new \Flake\Core\Database\Sqlite(
$sFile
diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php
index c369277..8f61b54 100644
--- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php
+++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php
@@ -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 " . $sFile . "";
+ $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"),$sMessage);
+ return;
+ }
+ # Asserting DB directory is writable
+ if(!is_writable(dirname($sFile))) {
+ $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . "";
+ $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 = "
Database is not structurally complete.
"; + $sMessage .= "Missing tables are: " . implode(", ", $aMissingTables) . "
"; + $sMessage .= "You will find the SQL definition of Baïkal tables in this file: Core/Resources/Db/SQLite/db.sql
"; + $sMessage .= "Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.
"; + + $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.