Example #1
0
function getMigrationCharsetFlag()
{
    global $adb;
    $db_status = check_db_utf8_support($adb);
    $config_status = get_config_status();
    if ($db_status == $config_status) {
        if ($db_status == 1) {
            // Both are UTF-8
            $db_migration_status = MIG_CHARSET_PHP_UTF8_DB_UTF8;
        } else {
            // Both are Non UTF-8
            $db_migration_status = MIG_CHARSET_PHP_NONUTF8_DB_NONUTF8;
        }
    } else {
        if ($db_status == 1) {
            // Database charset is UTF-8 and CRM charset is Non UTF-8
            $db_migration_status = MIG_CHARSET_PHP_NONUTF8_DB_UTF8;
        } else {
            // Database charset is Non UTF-8 and CRM charset is UTF-8
            $db_migration_status = MIG_CHARSET_PHP_UTF8_DB_NONUTF8;
        }
    }
    return $db_migration_status;
}
Example #2
0
    static function verifyMigrationInfo($migrationInfo)
    {
        global $installationStrings, $vtiger_current_version;
        $dbVerifyResult = array();
        $dbVerifyResult['flag'] = false;
        $configInfo = array();
        if (isset($migrationInfo['source_directory'])) {
            $source_directory = $migrationInfo['source_directory'];
        }
        if (isset($migrationInfo['root_directory'])) {
            $configInfo['root_directory'] = $migrationInfo['root_directory'];
        }
        if (is_dir($source_directory)) {
            if (!is_file($source_directory . "config.inc.php")) {
                $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_CONFIG_FILE'];
                return $dbVerifyResult;
            }
            if (!is_dir($source_directory . "user_privileges")) {
                $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_USER_PRIV_DIR'];
                return $dbVerifyResult;
            }
            if (!is_dir($source_directory . "storage")) {
                $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_STORAGE_DIR'];
                return $dbVerifyResult;
            }
        } else {
            $dbVerifyResult['error_msg'] = $installationStrings['ERR_NO_SOURCE_DIR'];
            return $dbVerifyResult;
        }
        global $dbconfig;
        require_once $source_directory . "config.inc.php";
        $old_db_name = $dbconfig['db_name'];
        $db_hostname = $dbconfig['db_server'] . $dbconfig['db_port'];
        $db_username = $dbconfig['db_username'];
        $db_password = $dbconfig['db_password'];
        $db_type = $dbconfig['db_type'];
        if (isset($migrationInfo['user_name'])) {
            $user_name = $migrationInfo['user_name'];
        }
        if (isset($migrationInfo['user_pwd'])) {
            $user_pwd = $migrationInfo['user_pwd'];
        }
        if (isset($migrationInfo['old_version'])) {
            $source_version = $migrationInfo['old_version'];
        }
        if (isset($migrationInfo['new_dbname'])) {
            $new_db_name = $migrationInfo['new_dbname'];
        }
        $configInfo['db_name'] = $new_db_name;
        $configInfo['db_type'] = $db_type;
        $configInfo['db_hostname'] = $db_hostname;
        $configInfo['db_username'] = $db_username;
        $configInfo['db_password'] = $db_password;
        $configInfo['admin_email'] = $HELPDESK_SUPPORT_EMAIL_ID;
        $configInfo['currency_name'] = $currency_name;
        $dbVerifyResult['old_dbname'] = $old_db_name;
        $db_type_status = false;
        // is there a db type?
        $db_server_status = false;
        // does the db server connection exist?
        $old_db_exist_status = false;
        // does the old database exist?
        $db_utf8_support = false;
        // does the database support utf8?
        $new_db_exist_status = false;
        // does the new database exist?
        $new_db_has_tables = false;
        // does the new database has tables in it?
        require_once 'include/DatabaseUtil.php';
        //Checking for database connection parameters and copying old database into new database
        if ($db_type) {
            $conn =& NewADOConnection($db_type);
            $db_type_status = true;
            if (@$conn->Connect($db_hostname, $db_username, $db_password)) {
                $db_server_status = true;
                $serverInfo = $conn->ServerInfo();
                if (Common_Install_Wizard_Utils::isMySQL($db_type)) {
                    $mysql_server_version = Common_Install_Wizard_Utils::getMySQLVersion($serverInfo);
                }
                // test the connection to the old database
                $olddb_conn =& NewADOConnection($db_type);
                if (@$olddb_conn->Connect($db_hostname, $db_username, $db_password, $old_db_name)) {
                    $old_db_exist_status = true;
                    if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
                        $sql = 'alter table vtiger_users change user_password user_password varchar(128)';
                        $alterResult = $olddb_conn->_Execute($sql);
                        if (!is_object($alterResult)) {
                            $dbVerifyResult['error_msg'] = $installationStrings['LBL_PASSWORD_FIELD_CHANGE_FAILURE'];
                        }
                        if (!is_array($_SESSION['migration_info']['user_messages'])) {
                            unset($_SESSION['migration_info']['user_messages']);
                            $_SESSION['migration_info']['user_messages'] = array();
                            $_SESSION['migration_info']['user_messages'][] = array('status' => "<span style='color: red;font-weight: bold'>" . $installationStrings['LBL_IMPORTANT_NOTE'] . "</span>", 'msg' => "<span style='color: #3488cc;font-weight: bold'>" . $installationStrings['LBL_USER_PASSWORD_CHANGE_NOTE'] . "</span>");
                        }
                        if (self::resetUserPasswords($olddb_conn)) {
                            $_SESSION['migration_info']['user_pwd'] = $user_name;
                            $migrationInfo['user_pwd'] = $user_name;
                            $user_pwd = $user_name;
                        }
                    }
                    if (Migration_Utils::authenticateUser($olddb_conn, $user_name, $user_pwd) == true) {
                        $is_admin = true;
                    } else {
                        $dbVerifyResult['error_msg'] = $installationStrings['ERR_NOT_VALID_USER'];
                        return $dbVerifyResult;
                    }
                    $olddb_conn->Close();
                }
                // test the connection to the new database
                $newdb_conn =& NewADOConnection($db_type);
                if (@$newdb_conn->Connect($db_hostname, $db_username, $db_password, $new_db_name)) {
                    $new_db_exist_status = true;
                    $noOfTablesInNewDb = Migration_Utils::getNumberOfTables($newdb_conn);
                    if ($noOfTablesInNewDb > 0) {
                        $new_db_has_tables = true;
                    }
                    $db_utf8_support = check_db_utf8_support($newdb_conn);
                    $configInfo['vt_charset'] = $db_utf8_support ? "UTF-8" : "ISO-8859-1";
                    $newdb_conn->Close();
                }
            }
            $conn->Close();
        }
        if (!$db_type_status || !$db_server_status) {
            $error_msg = $installationStrings['ERR_DATABASE_CONNECTION_FAILED'] . '. ' . $installationStrings['ERR_INVALID_MYSQL_PARAMETERS'];
            $error_msg_info = $installationStrings['MSG_LIST_REASONS'] . ':<br>
					-  ' . $installationStrings['MSG_DB_PARAMETERS_INVALID'] . '. <a href="http://www.vtiger.com/products/crm/help/' . $vtiger_current_version . '/vtiger_CRM_Database_Hostname.pdf" target="_blank">' . $installationStrings['LBL_MORE_INFORMATION'] . '</a><BR>
					-  ' . $installationStrings['MSG_DB_USER_NOT_AUTHORIZED'];
        } elseif (Common_Install_Wizard_Utils::isMySQL($db_type) && $mysql_server_version < '4.1') {
            $error_msg = $mysql_server_version . ' -> ' . $installationStrings['ERR_INVALID_MYSQL_VERSION'];
        } elseif (!$old_db_exist_status) {
            $error_msg = $old_db_name . ' -> ' . $installationStrings['ERR_DATABASE_NOT_FOUND'];
        } elseif (!$new_db_exist_status) {
            $error_msg = $new_db_name . ' -> ' . $installationStrings['ERR_DATABASE_NOT_FOUND'];
        } elseif (!$new_db_has_tables) {
            $error_msg = $new_db_name . ' -> ' . $installationStrings['ERR_MIGRATION_DATABASE_IS_EMPTY'];
        } else {
            $web_root = $_SERVER["HTTP_HOST"] ? $_SERVER["HTTP_HOST"] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
            $web_root .= $_SERVER["REQUEST_URI"];
            $web_root = preg_replace("/\\/install.php(.)*/i", "", $web_root);
            $site_URL = "http://" . $web_root;
            $configInfo['site_URL'] = $site_URL;
            $dbVerifyResult['config_info'] = $configInfo;
            $dbVerifyResult['flag'] = true;
            return $dbVerifyResult;
        }
        $dbVerifyResult['config_info'] = $configInfo;
        $dbVerifyResult['error_msg'] = $error_msg;
        $dbVerifyResult['error_msg_info'] = $error_msg_info;
        return $dbVerifyResult;
    }
Example #3
0
    function process()
    {
        set_time_limit(0);
        //ADDED TO AVOID UNEXPECTED TIME OUT WHILE MIGRATING
        if (isset($_SESSION['migration_info']['source_directory'])) {
            $source_directory = $_SESSION['migration_info']['source_directory'];
        }
        if (is_dir($source_directory)) {
            if (!is_file($source_directory . "config.inc.php")) {
                echo "NO_CONFIG_FILE";
                return false;
            }
            if (!is_dir($source_directory . "user_privileges")) {
                echo "NO_USER_PRIV_DIR";
                return false;
            }
            if (!is_dir($source_directory . "storage")) {
                echo "NO_STORAGE_DIR";
                return false;
            }
        } else {
            echo "NO_SOURCE_DIR";
            return false;
        }
        global $dbconfig;
        require_once $source_directory . "config.inc.php";
        $old_db_name = $dbconfig['db_name'];
        $db_hostname = $dbconfig['db_server'] . $dbconfig['db_port'];
        $db_username = $dbconfig['db_username'];
        $db_password = $dbconfig['db_password'];
        $db_type = $dbconfig['db_type'];
        if (isset($_SESSION['migration_info']['user_name'])) {
            $user_name = $_SESSION['migration_info']['user_name'];
        }
        if (isset($_SESSION['migration_info']['user_pwd'])) {
            $user_pwd = $_SESSION['migration_info']['user_pwd'];
        }
        if (isset($_SESSION['migration_info']['old_version'])) {
            $source_version = $_SESSION['migration_info']['old_version'];
        }
        if (isset($_SESSION['migration_info']['new_dbname'])) {
            $new_db_name = $_SESSION['migration_info']['new_dbname'];
        }
        $_SESSION['migration_info']['db_type'] = $db_type;
        $_SESSION['migration_info']['db_hostname'] = $db_hostname;
        $_SESSION['migration_info']['db_username'] = $db_username;
        $_SESSION['migration_info']['db_password'] = $db_password;
        $_SESSION['migration_info']['old_dbname'] = $old_db_name;
        $_SESSION['migration_info']['db_server'] = $dbconfig['db_server'];
        $_SESSION['migration_info']['db_port'] = $dbconfig['db_port'];
        $_SESSION['migration_info']['admin_emailid'] = $HELPDESK_SUPPORT_EMAIL_ID;
        $_SESSION['migration_info']['currency_name'] = $currency_name;
        $db_type_status = false;
        // is there a db type?
        $db_server_status = false;
        // does the db server connection exist?
        $old_db_exist_status = false;
        // does the old database exist?
        $db_utf8_support = false;
        // does the database support utf8?
        $new_db_exist_status = false;
        // does the new database exist?
        require_once 'include/DatabaseUtil.php';
        //Checking for database connection parameters and copying old database into new database
        if ($db_type) {
            $conn =& NewADOConnection($db_type);
            $db_type_status = true;
            if (@$conn->Connect($db_hostname, $db_username, $db_password)) {
                $db_server_status = true;
                $serverInfo = $conn->ServerInfo();
                if ($db_type == 'mysql') {
                    $version = explode('-', $serverInfo);
                    $mysql_server_version = $version[0];
                }
                // test the connection to the old database
                $olddb_conn =& NewADOConnection($db_type);
                if (@$olddb_conn->Connect($db_hostname, $db_username, $db_password, $old_db_name)) {
                    $old_db_exist_status = true;
                    if (authenticate_user($user_name, $user_pwd) == true) {
                        $is_admin = true;
                    } else {
                        echo 'NOT_VALID_USER';
                        return false;
                    }
                    $olddb_conn->Close();
                }
                // test the connection to the new database
                $newdb_conn =& NewADOConnection($db_type);
                if (@$newdb_conn->Connect($db_hostname, $db_username, $db_password, $new_db_name)) {
                    $new_db_exist_status = true;
                    $_SESSION['migration_info']['db_utf8_support'] = check_db_utf8_support($newdb_conn);
                    $newdb_conn->Close();
                }
            }
            $conn->Close();
        }
        if (!$db_type_status || !$db_server_status) {
            $error_msg = 'ERR - Unable to connect to database Server. Invalid mySQL Connection Parameters specified';
            $error_msg_info = 'This may be due to the following reasons:<br>
					-  specified database user, password, hostname, database type, or port is invalid. <a href="http://www.vtiger.com/products/crm/help/5.1.0/vtiger_CRM_Database_Hostname.pdf" target="_blank">More Information</a><BR>
					-  specified database user does not have access to connect to the database server from the host';
        } elseif ($db_type == 'mysql' && $mysql_server_version < '4.1') {
            $error_msg = 'ERR - MySQL version ' . $mysql_server_version . ' is not supported, kindly connect to MySQL 4.1.x or above';
        } elseif (!$old_db_exist_status) {
            $error_msg = 'ERR - The Database "' . $old_db_name . '" is not found. Provide the correct database name';
        } elseif (!$new_db_exist_status) {
            $error_msg = 'ERR - The Database "' . $new_db_name . '" is not found. Provide the correct database name';
        } else {
            $_SESSION['authentication_key'] = md5(microtime());
            return true;
        }
        echo $error_msg . "\n" . $error_msg_info;
        return false;
    }
// Remove the MigrationStep0.tpl file from Smarty cache
$migration_tpl_file = get_smarty_compiled_file('MigrationStep0.tpl');
if ($migration_tpl_file != null) {
    unlink($migration_tpl_file);
}
global $adb, $default_charset, $theme;
$theme_path = "themes/" . $theme . "/";
$image_path = $theme_path . "images/";
$smarty = new vtigerCRM_Smarty();
$smarty->assign("MOD", $mod_strings);
$smarty->assign("APP", $app_strings);
$smarty->assign("MODULE", "Migration");
$smarty->assign("THEME", $theme);
$smarty->assign("IMAGE_PATH", $image_path);
if ($adb->isPostgres()) {
    $db_status = '1';
} else {
    $db_status = check_db_utf8_support($adb);
}
$config_status = get_config_status();
$smarty->assign("DB_CHARSET", get_db_charset($adb));
$smarty->assign("DB_STATUS", $db_status);
$smarty->assign("CONFIG_CHARSET", $default_charset);
$smarty->assign("CONFIG_STATUS", $config_status);
$data_conversion_msg = array('1' => array('msg1' => '', 'msg2' => '', 'checked' => 'true'), '2' => array('msg1' => "To have complete UTF-8 support:- <ol><li>Set \$default_charset='UTF-8'; in config.inc.php </li><li>Select the check box below for database charset handling and data conversion.</li></ol>", 'msg2' => 'To continue without UTF-8 support, keep the above option unchecked.', 'checked' => 'false'), '3' => array('msg1' => "To have complete UTF-8 support, we recommend you to set \$default_charset='UTF-8'; in config.inc.php.", 'msg2' => "Select the above check box after changing the config file, if you need UTF-8 data conversion (Unicode support).", 'checked' => 'false'), '4' => array('msg1' => "UTF-8 should be enabled for database to have complete unicode support. This will be handled in data conversion to UTF-8.", 'msg2' => "De-select the above check box, if you do not need UTF-8 data conversion (Unicode support will be inconsistent).", 'checked' => 'true'));
$db_migration_status = getMigrationCharsetFlag();
if ($db_migration_status == MIG_CHARSET_PHP_UTF8_DB_UTF8) {
    header("Location: index.php?module=Migration&action=index&parenttab=Settings");
}
$smarty->assign("CONVERSION_MSG", $data_conversion_msg[$db_migration_status]);
$smarty->display("MigrationStep0.tpl");
                        $query .= " default character set utf8 default collate utf8_general_ci";
                    }
                    $db_utf8_support = true;
                }
                if ($createdb_conn->Execute($query)) {
                    $db_creation_failed = false;
                }
                $createdb_conn->Close();
            }
        }
        // test the connection to the database
        if (@$conn->Connect($db_hostname, $db_username, $db_password, $db_name)) {
            $db_exist_status = true;
            if (!$db_utf8_support) {
                // Check if the database that we are going to use supports UTF-8
                $db_utf8_support = check_db_utf8_support($conn);
            }
        }
        $conn->Close();
    }
}
// Update vtiger charset to use
$vt_charset = $db_utf8_support ? "UTF-8" : "ISO-8859-1";
$error_msg = '';
$error_msg_info = '';
if (!$db_type_status || !$db_server_status) {
    $error_msg = 'Unable to connect to database Server. Invalid mySQL Connection Parameters specified';
    $error_msg_info = 'This may be due to the following reasons:<br>
			-  specified database user, password, hostname, database type, or port is invalid. <a href="http://www.vtiger.com/products/crm/help/5.1.0/vtiger_CRM_Database_Hostname.pdf" target="_blank">More Information</a><BR>
			-  specified database user does not have access to connect to the database server from the host';
} elseif ($db_type == 'mysql' && $mysql_server_version < '4.1') {