public static function createDb($eventData = '', $log = '') { $result = false; $reg = \Innomatic\Util\Registry::instance(); $innomatic = \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer'); $dasn_string = $eventData['dbtype'] . '://' . $eventData['dbuser'] . ':' . $eventData['dbpass'] . '@' . $eventData['dbhost'] . ':' . $eventData['dbport'] . '/' . $eventData['dbname'] . '?' . 'logfile=' . $innomatic->getHome() . 'core/log/innomatic_root_db.log'; $tmpdb = \Innomatic\Dataaccess\DataAccessFactory::getDataAccess(new \Innomatic\Dataaccess\DataAccessSourceName($dasn_string)); if ($tmpdb->Connect()) { $tmpdb->DropDB($eventData); $tmpdb->Close(); } if ($tmpdb->CreateDB($eventData)) { if ($tmpdb->Connect()) { // Tables creation // $xmldb = new \Innomatic\Dataaccess\DataAccessXmlTable($tmpdb, \Innomatic\Dataaccess\DataAccessXmlTable::SQL_CREATE); if ($xmldb->load_DefFile($innomatic->getHome() . 'core/db/innomatic_root.xml')) { if ($tmpdb->execute($xmldb->getSQL())) { // Database configuration file creation // $fh = @fopen($innomatic->getHome() . 'core/conf/innomatic.ini', 'a'); if ($fh) { fputs($fh, 'RootDatabaseType = ' . $eventData['dbtype'] . "\n"); fputs($fh, 'RootDatabaseName = ' . $eventData['dbname'] . "\n"); fputs($fh, 'RootDatabaseHost = ' . $eventData['dbhost'] . "\n"); fputs($fh, 'RootDatabasePort = ' . $eventData['dbport'] . "\n"); fputs($fh, 'RootDatabaseUser = '******'dbuser'] . "\n"); fputs($fh, 'RootDatabasePassword = '******'dbpass'] . "\n"); fputs($fh, 'RootDatabaseDebug = 0' . "\n"); fclose($fh); $result = true; @touch($innomatic->getHome() . 'core/temp/setup_dbcreated', time()); if (file_exists($innomatic->getHome() . 'core/temp/setup_creatingdb')) { @unlink($innomatic->getHome() . 'core/temp/setup_creatingdb'); } } else { $log->logevent('innomatic.root.main_php', 'Unable to create root database configuration file during initialization', \Innomatic\Logging\Logger::ERROR); } } else { $log->logevent('innomatic.root.main_php', 'Unable to create root database tables during initialization', \Innomatic\Logging\Logger::ERROR); } } else { $log->logevent('innomatic.root.main_php', 'Unable to open Innomatic structure file during initialization', \Innomatic\Logging\Logger::ERROR); } } else { $log->logevent('innomatic.root.main_php', 'Unable to connect to root database during initialization', \Innomatic\Logging\Logger::ERROR); } } else { $log->logevent('innomatic.root.main_php', 'Unable to create root database during initialization: ' . $tmpdb->getLastError(), \Innomatic\Logging\Logger::ERROR); } return $result; }