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.
SQLite says: " . $e->getMessage() . (string)$e + ); + } + } } -} \ No newline at end of file +} diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 98781f5..775ab8d 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -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("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in Specific/config.system.php

"); } - $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("

Baïkal was not able to establish a connexion to the configured MySQL database (as configured in Specific/config.system.php).

"); + } return TRUE; }