function ProcessDatabaseSetup($data) { // Setting the database type for the ADODB connection extract($data, EXTR_REFS | EXTR_SKIP); $this->mDbConnection = @NewDatabase(array('dbtype' => $db_type, 'dbhost' => $db_hostname, 'dbuser' => $db_username, 'dbpass' => $db_password, 'dbname' => $db_name)); $res = $this->mDbConnection->connect(); if (PEAR::isError($res)) { $info = $this->mDbConnection->errorInfo(); $_SESSION['page_heading'] = 'Database Processing'; switch ($info[1]) { case 2005: // Could not connect to database with the hostname provided $_SESSION['page_message'][] = $info[2]; $_SESSION['page_message'][] = 'Usually the database host name is "localhost". In some occassions, it maybe an internal ip-address or another host name to your webserver.'; $_SESSION['page_message'][] = 'Double check with your hosting provider or System Administrator.'; return false; break; case 1049: // Database does not exist, try to create one $this->mDbConnection->setDatabase(''); $res = $this->mDbConnection->manager->createDatabase($db_name); if (PEAR::isError($res)) { $_SESSION['page_message'][] = $res->getMessage(); $_SESSION['page_message'][] = 'Your database does not exist and could not be created. Either create the database yourself, choose an existing database or use a database user with sufficient permissions to create a database.'; return false; } else { $this->mDbConnection->setDatabase($db_name); unset($_SESSION['page_heading']); break; } case 1045: // Username passwords don't match for the hostname provided $_SESSION['page_message'][] = $info[2]; $_SESSION['page_message'][] = "Apparently you haven't set up the right permissions for the database hostname provided."; $_SESSION['page_message'][] = 'Double check the provided credentials or contact your System Administrator for further assistance.'; return false; break; default: $_SESSION['page_message'][] = "Please verify your username/password/database details (error={$info[1]}): " . $info[2]; return false; break; } } // Check that table prefix is OK, some DBs don't like it $prefix = array_get($data, 'db_prefix'); if (strlen($prefix) > 0 && is_numeric($prefix[0])) { $_SESSION['page_heading'] = 'Database Processing'; $_SESSION['page_message'][] = 'The table prefix may not start with a number.'; return false; } // Populate the database with the new tables and return the result (boolean) return $this->PopulateDb($data); }
<?php // This is just a developer's tool. Needs tables with flyspray_ prefix. error_reporting(E_ALL); define('IN_FS', true); $file = 'exportdb.xml'; require_once dirname(__FILE__) . '/../includes/fix.inc.php'; require_once dirname(__FILE__) . '/../includes/class.database.php'; $conf = @parse_ini_file('../flyspray.conf.php', true) or die('Cannot open config file.'); define('DEBUG_SQL', true); $db = NewDatabase($conf['database']); require_once dirname(__FILE__) . '/../includes/external/MDB2/MDB2/Schema.php'; // Now build schema object based on existing connection $db->setOption('idxname_format', '%s'); $schema =& MDB2_Schema::factory($db); $def = $schema->getDefinitionFromDatabase(); $schema->dumpDatabase($def, array('output_mode' => 'file', 'output' => $file), MDB2_SCHEMA_DUMP_STRUCTURE); // Now make prefix a variable, so that it can be replaced during setup or upgrade $xml = file_get_contents($file); $xml = str_replace('flyspray_', '<variable>db_prefix</variable>', $xml); // workaround for quotes bug $xml = str_replace('"', '"', $xml); // empty default values might cause problems $xml = str_replace("<notnull>true</notnull>\n <default></default>", '<notnull>true</notnull>', $xml); // also make database name variable $xml = str_replace('<name>' . $conf['database']['dbname'] . '</name>', '<name><variable>db_name</variable></name>', $xml); file_put_contents($file, $xml);