Ejemplo n.º 1
0
// How many chars are read per time
define('MAX_QUERY_LINES', 300);
// How many lines may be considered to be one query (except text lines)
define('TESTMODE', false);
// Set to true to process the file without actually accessing the database
@ini_set('auto_detect_line_endings', true);
@set_time_limit(0);
if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get")) {
    @date_default_timezone_set(@date_default_timezone_get());
}
header('Content-Type: text/html; charset=' . $LANG_CHARSET);
echo Installer::getHeader($LANG_MIGRATE[17]);
$error = false;
$file = false;
// Check if mysql extension is available
$availableDrivers = Geeklog\Db::getDrivers();
if (!$error && count($availableDrivers) === 0) {
    echo '<p>' . $LANG_BIGDUMP[11] . '</p>' . PHP_EOL;
    $error = true;
}
// Get the current directory
$upload_dir = __DIR__;
// Connect to the database
$db = false;
$dbConnection = false;
$errorMessage = '';
$args = array('host' => $_DB_host, 'user' => $_DB_user, 'pass' => $_DB_pass, 'name' => $_DB_name, 'charset' => $db_connection_charset);
if (!$error && !TESTMODE) {
    try {
        $dbConnection = Geeklog\Db::connect(Geeklog\Db::DB_MYSQLI, $args);
        $db = true;
Ejemplo n.º 2
0
 /**
  * Modify db-config.php
  *
  * @param   string $dbConfigFilePath Full path to db-config.php
  * @param   array  $db               Database information to save
  * @return  bool True if successful, false if not
  */
 private function writeConfig($dbConfigFilePath, array $db)
 {
     // We may have included db-config.php elsewhere already, in which case
     // all of these variables need to be imported from the global namespace
     global $_DB_host, $_DB_name, $_DB_user, $_DB_pass, $_DB_table_prefix, $_DB_dbms, $_DB_charset;
     require_once $dbConfigFilePath;
     // Grab the current DB values
     $isUtf8 = false;
     if (!empty($_DB_charset)) {
         $isUtf8 = $_DB_charset === 'utf8' || $_DB_charset === 'utf8mb4';
     } elseif (isset($db['utf8'])) {
         $isUtf8 = $db['utf8'];
     }
     $db = array('host' => isset($db['host']) ? $db['host'] : $_DB_host, 'name' => isset($db['name']) ? $db['name'] : $_DB_name, 'user' => isset($db['user']) ? $db['user'] : $_DB_user, 'pass' => isset($db['pass']) ? $db['pass'] : $_DB_pass, 'table_prefix' => isset($db['table_prefix']) ? $db['table_prefix'] : $_DB_table_prefix, 'type' => isset($db['type']) ? $db['type'] : $_DB_dbms);
     if ($db['type'] === 'mysql-innodb') {
         $db['type'] = 'mysql';
     }
     // Read in db-config.php so we can insert the DB information
     clearstatcache();
     $dbConfigData = @file_get_contents($dbConfigFilePath);
     // Replace the values with the new ones
     $dbConfigData = str_replace("\$_DB_host = '" . $_DB_host . "';", "\$_DB_host = '" . $db['host'] . "';", $dbConfigData);
     // Host
     $dbConfigData = str_replace("\$_DB_name = '" . $_DB_name . "';", "\$_DB_name = '" . $db['name'] . "';", $dbConfigData);
     // Database
     $dbConfigData = str_replace("\$_DB_user = '******';", "\$_DB_user = '******'user'] . "';", $dbConfigData);
     // Username
     $dbConfigData = str_replace("\$_DB_pass = '******';", "\$_DB_pass = '******'pass'] . "';", $dbConfigData);
     // Password
     $dbConfigData = str_replace("\$_DB_table_prefix = '" . $_DB_table_prefix . "';", "\$_DB_table_prefix = '" . $db['table_prefix'] . "';", $dbConfigData);
     // Table prefix
     $dbConfigData = str_replace("\$_DB_dbms = '" . $_DB_dbms . "';", "\$_DB_dbms = '" . $db['type'] . "';", $dbConfigData);
     // Database type ('mysql' or 'pgsql')
     if ($db['type'] === 'mysql' && $isUtf8 && version_compare(self::GL_VERSION, '2.1.2', '>=') && (!empty($_DB_charset) || $this->env['mode'] === 'install')) {
         if (!empty($_DB_charset)) {
             $db['charset'] = $_DB_charset;
         } else {
             require_once __DIR__ . '/db.class.php';
             $dbTypes = Geeklog\Db::getDrivers();
             if (in_array(Geeklog\Db::DB_MYSQLI, $dbTypes)) {
                 $driver = Geeklog\Db::connect(Geeklog\Db::DB_MYSQLI, $db);
             } else {
                 $driver = Geeklog\Db::connect(Geeklog\Db::DB_MYSQL, $db);
             }
             $db['charset'] = $driver->getVersion() >= 50503 ? 'utf8mb4' : 'utf8';
         }
         $dbConfigData = str_replace("\$_DB_charset = '" . $_DB_charset . "';", "\$_DB_charset = '" . $db['charset'] . "';", $dbConfigData);
         // Charset
     }
     // Write our changes to db-config.php
     $result = @file_put_contents($dbConfigFilePath, $dbConfigData) !== false;
     return $result;
 }