Ejemplo n.º 1
0
 public static function bootstrap()
 {
     # Registering Baikal classloader
     define("BAIKAL_PATH_FRAMEWORKROOT", dirname(__FILE__) . "/");
     \Baikal\Core\Tools::assertEnvironmentIsOk();
     \Baikal\Core\Tools::configureEnvironment();
     # Check that a config file exists
     if (!file_exists(PROJECT_PATH_SPECIFIC . "config.php") || !file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) {
         self::installTool();
     } else {
         require_once PROJECT_PATH_SPECIFIC . "config.php";
         require_once PROJECT_PATH_SPECIFIC . "config.system.php";
         date_default_timezone_set(PROJECT_TIMEZONE);
         # Check that Baïkal is already configured
         if (!defined("BAIKAL_CONFIGURED_VERSION")) {
             self::installTool();
         } else {
             # Check that running version matches configured version
             if (version_compare(BAIKAL_VERSION, BAIKAL_CONFIGURED_VERSION) > 0) {
                 self::installTool();
             } else {
                 # Check that admin password is set
                 if (!defined("BAIKAL_ADMIN_PASSWORDHASH")) {
                     self::installTool();
                 }
                 \Baikal\Core\Tools::assertBaikalIsOk();
                 set_error_handler("\\Baikal\\Framework::exception_error_handler");
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho)
 {
     if (intval($oForm->modelInstance()->get("PROJECT_DB_MYSQL")) === 1) {
         # We have to check the MySQL connection
         $sHost = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_HOST");
         $sDbName = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_DBNAME");
         $sUsername = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_USERNAME");
         $sPassword = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_PASSWORD");
         try {
             $oDB = new \Flake\Core\Database\Mysql($sHost, $sDbName, $sUsername, $sPassword);
         } catch (\Exception $e) {
             $sMessage = "<strong>MySQL error:</strong> " . $e->getMessage();
             $sMessage .= "<br /><strong>Nothing has been saved</strong>";
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST"), $sMessage);
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD"));
             return;
         }
         if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDB)) !== TRUE) {
             $sMessage = "<strong>MySQL error:</strong> These tables, required by Baïkal, are missing: <strong>" . implode(", ", $aMissingTables) . "</strong><br />";
             $sMessage .= "You may want create these tables using the file <strong>Core/Resources/Db/MySQL/db.sql</strong>";
             $sMessage .= "<br /><br /><strong>Nothing has been saved</strong>";
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"), $sMessage);
             return;
         }
     }
 }
Ejemplo n.º 3
0
 protected function getConfigAsString()
 {
     if (file_exists($this->sConfigFilePath)) {
         $sContent = file_get_contents($this->sConfigFilePath);
         return str_replace(LF . CR, LF, $sContent);
     } else {
         $sConfig = "<?php\n" . \Baikal\Core\Tools::getCopyrightNotice() . "\n\n";
         $sConfig .= static::getDefaultConfig();
         return $sConfig;
     }
 }
Ejemplo n.º 4
0
 public function validateMySQLConnection($oForm, $oMorpho)
 {
     $bMySQLEnabled = $oMorpho->element("PROJECT_DB_MYSQL")->value();
     if ($bMySQLEnabled) {
         $sHost = $oMorpho->element("PROJECT_DB_MYSQL_HOST")->value();
         $sDbname = $oMorpho->element("PROJECT_DB_MYSQL_DBNAME")->value();
         $sUsername = $oMorpho->element("PROJECT_DB_MYSQL_USERNAME")->value();
         $sPassword = $oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")->value();
         try {
             $oDb = new \Flake\Core\Database\Mysql($sHost, $sDbname, $sUsername, $sPassword);
             if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== TRUE) {
                 # Checking if all tables are missing
                 $aRequiredTables = \Baikal\Core\Tools::getRequiredTablesList();
                 if (count($aRequiredTables) !== count($aMissingTables)) {
                     $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/MySQL/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_DB_MYSQL"), $sMessage);
                 } else {
                     # All tables are missing
                     # We add these tables ourselves to the database, to initialize Baïkal
                     $sSqlDefinition = file_get_contents(PROJECT_PATH_CORERESOURCES . "Db/MySQL/db.sql");
                     $oDb->query($sSqlDefinition);
                 }
             }
             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"));
         }
     }
 }
Ejemplo n.º 5
0
 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
         $sHost = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_HOST");
         $sDbName = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_DBNAME");
         $sUsername = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_USERNAME");
         $sPassword = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_PASSWORD");
         try {
             $oDB = new \Flake\Core\Database\Mysql($sHost, $sDbName, $sUsername, $sPassword);
         } catch (\Exception $e) {
             $sMessage = "<strong>MySQL error:</strong> " . $e->getMessage();
             $sMessage .= "<br /><strong>Nothing has been saved</strong>";
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST"), $sMessage);
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME"));
             $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD"));
             return;
         }
         if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDB)) !== true) {
             $sMessage = "<strong>MySQL error:</strong> These tables, required by Baïkal, are missing: <strong>" . implode(", ", $aMissingTables) . "</strong><br />";
             $sMessage .= "You may want create these tables using the file <strong>Core/Resources/Db/MySQL/db.sql</strong>";
             $sMessage .= "<br /><br /><strong>Nothing has been saved</strong>";
             $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);
         }
     }
 }
Ejemplo n.º 6
0
 protected function createDefaultConfigFilesIfNeeded()
 {
     # Create empty config.php if needed
     if (!file_exists(PROJECT_PATH_SPECIFIC . "config.php")) {
         @touch(PROJECT_PATH_SPECIFIC . "config.php");
         $sContent = "<?php\n" . \Baikal\Core\Tools::getCopyrightNotice() . "\n\n";
         $sContent .= $this->getDefaultConfig();
         file_put_contents(PROJECT_PATH_SPECIFIC . "config.php", $sContent);
     }
     # Create empty config.system.php if needed
     if (!file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) {
         @touch(PROJECT_PATH_SPECIFIC . "config.system.php");
         $sContent = "<?php\n" . \Baikal\Core\Tools::getCopyrightNotice() . "\n\n";
         $sContent .= $this->getDefaultSystemConfig();
         file_put_contents(PROJECT_PATH_SPECIFIC . "config.system.php", $sContent);
     }
 }
Ejemplo n.º 7
0
 function validateConnection($oForm, $oMorpho)
 {
     if ($oForm->refreshed()) {
         return true;
     }
     $bMySQLEnabled = $oMorpho->element("PROJECT_DB_MYSQL")->value();
     if ($bMySQLEnabled) {
         $sHost = $oMorpho->element("PROJECT_DB_MYSQL_HOST")->value();
         $sDbname = $oMorpho->element("PROJECT_DB_MYSQL_DBNAME")->value();
         $sUsername = $oMorpho->element("PROJECT_DB_MYSQL_USERNAME")->value();
         $sPassword = $oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")->value();
         try {
             $oDb = new \Flake\Core\Database\Mysql($sHost, $sDbname, $sUsername, $sPassword);
             if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== true) {
                 # Checking if all tables are missing
                 $aRequiredTables = \Baikal\Core\Tools::getRequiredTablesList();
                 if (count($aRequiredTables) !== count($aMissingTables)) {
                     $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/MySQL/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_DB_MYSQL"), $sMessage);
                 } else {
                     # All tables are missing
                     # We add these tables ourselves to the database, to initialize Baïkal
                     $sSqlDefinition = file_get_contents(PROJECT_PATH_CORERESOURCES . "Db/MySQL/db.sql");
                     $oDb->query($sSqlDefinition);
                 }
             }
             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"));
         }
     } 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 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);
             if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== true) {
                 # Checking if all tables are missing
                 $aRequiredTables = \Baikal\Core\Tools::getRequiredTablesList();
                 if (count($aRequiredTables) !== count($aMissingTables)) {
                     $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);
                 } else {
                     # All tables are missing
                     # We add these tables ourselves to the database, to initialize Baïkal
                     $sSqlDefinition = file_get_contents(PROJECT_PATH_CORERESOURCES . "Db/SQLite/db.sql");
                     foreach (explode(';', $sSqlDefinition) as $query) {
                         if (!trim($query)) {
                             continue;
                         }
                         $oDb->query($query);
                     }
                 }
             }
             return true;
         } 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);
         }
         // SQLite
     }
 }