Example #1
0
 function migrate($migrationInfo)
 {
     global $installationStrings;
     $completed = false;
     set_time_limit(0);
     //ADDED TO AVOID UNEXPECTED TIME OUT WHILE MIGRATING
     global $dbconfig;
     require $migrationInfo['root_directory'] . '/config.inc.php';
     $dbtype = $dbconfig['db_type'];
     $host = $dbconfig['db_server'] . $dbconfig['db_port'];
     $dbname = $dbconfig['db_name'];
     $username = $dbconfig['db_username'];
     $passwd = $dbconfig['db_password'];
     global $adb, $migrationlog;
     $adb = new PearDatabase($dbtype, $host, $dbname, $username, $passwd);
     $query = " ALTER DATABASE " . $adb->escapeDbName($dbname) . " DEFAULT CHARACTER SET utf8";
     $adb->query($query);
     $source_directory = $migrationInfo['source_directory'];
     if (file_exists($source_directory . 'user_privileges/CustomInvoiceNo.php')) {
         require_once $source_directory . 'user_privileges/CustomInvoiceNo.php';
     }
     $migrationlog =& LoggerManager::getLogger('MIGRATION');
     if (isset($migrationInfo['old_version'])) {
         $source_version = $migrationInfo['old_version'];
     }
     if (!isset($source_version) || empty($source_version)) {
         //If source version is not set then we cannot proceed
         echo "<br> " . $installationStrings['LBL_SOURCE_VERSION_NOT_SET'];
         exit;
     }
     $reach = 0;
     include $migrationInfo['root_directory'] . "/modules/Migration/versions.php";
     foreach ($versions as $version => $label) {
         if ($version == $source_version || $reach == 1) {
             $reach = 1;
             $temp[] = $version;
         }
     }
     $temp[] = $current_version;
     global $adb, $dbname;
     $_SESSION['adodb_current_object'] = $adb;
     @ini_set('zlib.output_compression', 0);
     @ini_set('output_buffering', 'off');
     ob_implicit_flush(true);
     echo '<table width="98%" border="1px" cellpadding="3" cellspacing="0" height="100%">';
     if (is_array($_SESSION['migration_info']['user_messages'])) {
         foreach ($_SESSION['migration_info']['user_messages'] as $infoMap) {
             echo "<tr><td>" . $infoMap['status'] . "</td><td>" . $infoMap['msg'] . "</td></tr>";
         }
     }
     echo "<tr><td colspan='2'><b>{$installationStrings['LBL_GOING_TO_APPLY_DB_CHANGES']}...</b></td></tr>";
     for ($patch_count = 0; $patch_count < count($temp); $patch_count++) {
         //Here we have to include all the files (all db differences for each release will be included)
         $filename = "modules/Migration/DBChanges/" . $temp[$patch_count] . "_to_" . $temp[$patch_count + 1] . ".php";
         $empty_tag = "<tr><td colspan='2'>&nbsp;</td></tr>";
         $start_tag = "<tr><td colspan='2'><b><font color='red'>&nbsp;";
         $end_tag = "</font></b></td></tr>";
         if (is_file($filename)) {
             echo $empty_tag . $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " " . $installationStrings['LBL_DATABASE_CHANGES'] . " -- " . $installationStrings['LBL_STARTS'] . "." . $end_tag;
             include $filename;
             //include the file which contains the corresponding db changes
             echo $start_tag . $temp[$patch_count] . " ==> " . $temp[$patch_count + 1] . " " . $installationStrings['LBL_DATABASE_CHANGES'] . " -- " . $installationStrings['LBL_ENDS'] . "." . $end_tag;
         }
     }
     /* Install Vtlib Compliant Modules */
     Common_Install_Wizard_Utils::installMandatoryModules();
     Migration_Utils::installOptionalModules($migrationInfo['selected_optional_modules'], $migrationInfo['source_directory'], $migrationInfo['root_directory']);
     Migration_utils::copyLanguageFiles($migrationInfo['source_directory'], $migrationInfo['root_directory']);
     //Here we have to update the version in table. so that when we do migration next time we will get the version
     $res = $adb->query('SELECT * FROM vtiger_version');
     global $vtiger_current_version;
     require $migrationInfo['root_directory'] . '/vtigerversion.php';
     if ($adb->num_rows($res)) {
         $res = ExecuteQuery("UPDATE vtiger_version SET old_version='{$versions[$source_version]}',current_version='{$vtiger_current_version}'");
         $completed = true;
     } else {
         ExecuteQuery("INSERT INTO vtiger_version (id, old_version, current_version) values (" . $adb->getUniqueID('vtiger_version') . ", '{$versions[$source_version]}', '{$vtiger_current_version}');");
         $completed = true;
     }
     echo '</table><br><br>';
     create_tab_data_file();
     create_parenttab_data_file();
     return $completed;
 }
if (isset($_REQUEST['user_pwd'])) {
    $_SESSION['migration_info']['user_pwd'] = $user_pwd = $_REQUEST['user_pwd'];
} else {
    $user_pwd = $_SESSION['migration_info']['user_pwd'];
}
if (isset($_REQUEST['old_version'])) {
    $_SESSION['migration_info']['old_version'] = $old_version = $_REQUEST['old_version'];
} else {
    $old_version = $_SESSION['migration_info']['old_version'];
}
if (isset($_REQUEST['new_dbname'])) {
    $_SESSION['migration_info']['new_dbname'] = $new_dbname = $_REQUEST['new_dbname'];
} else {
    $new_dbname = $_SESSION['migration_info']['new_dbname'];
}
$dbVerifyResult = Migration_Utils::verifyMigrationInfo($_SESSION['migration_info']);
$next = $dbVerifyResult['flag'];
$error_msg = $dbVerifyResult['error_msg'];
$error_msg_info = $dbVerifyResult['error_msg_info'];
$oldDbName = $dbVerifyResult['old_dbname'];
$configFileInfo = $dbVerifyResult['config_info'];
$dbType = $configFileInfo['db_type'];
$dbHostName = $configFileInfo['db_hostname'];
$newDbName = $configFileInfo['db_name'];
if ($next == true) {
    $_SESSION['authentication_key'] = md5(microtime());
    $_SESSION['config_file_info'] = $configFileInfo;
    require_once 'install/VerifyDBHealth.php';
    if ($_SESSION[$newDbName . '_' . $dbHostName . '_HealthApproved'] != true || $_SESSION['pre_migration'] != true) {
        header("Location:install.php?file=PreMigrationActions.php");
    } else {
	    if(typeof('Event') != 'undefined') {
	    	Event.observe(window, 'load', function() {
	    		VtigerJS_DialogBox.progress();
	    		document.getElementById('triggermigration_iframe').src = 'install.php?file=MigrationProcess.php&migration_start=true&auth_key='+auth_key;
	    	});
	    }
	    function Migration_Complete() {
	    	$('Mig_Close').style.display = 'block';
	    }
	    </script>
	    
	    <!-- Prefetch image to display later for Screen blocker -->
		<img style="display: none;" src="include/install/images/loading.gif">
	    <img src="themes/softed/images/layerPopupBg.gif" style="display: none;"/>
<?php 
} else {
    // Start the migration now
    echo '<body onload="window.parent.VtigerJS_DialogBox.hideprogress();">';
    require_once 'include/utils/utils.php';
    require_once 'include/logging.php';
    $migrationlog =& LoggerManager::getLogger('MIGRATION');
    if ($_SESSION['authentication_key'] == $_REQUEST['auth_key']) {
        $completed = Migration_Utils::migrate($_SESSION['migration_info']);
        if ($completed == true) {
            echo "<script type='text/javascript'>window.parent.Migration_Complete();</script>";
        }
    }
}
?>
	</body>
</html>	
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/
session_start();
$configFileUtils = new ConfigFile_Utils($_SESSION['config_file_info']);
if (!$configFileUtils->createConfigFile()) {
    die("<strong class='big'><font color='red'>{$installationStrings['ERR_CANNOT_WRITE_CONFIG_FILE']}</font></strong>");
}
require_once 'include/utils/utils.php';
// Required - Especially to create adb instance in global scope.
$mode = $_REQUEST['mode'];
if ($mode == 'migration') {
    $prev_file_name = 'SetMigrationConfig.php';
    $file_name = 'MigrationProcess.php';
    $optionalModules = Migration_Utils::getInstallableOptionalModules();
} else {
    $prev_file_name = 'SetInstallationConfig.php';
    $file_name = 'CreateTables.php';
    $optionalModules = Installation_Utils::getInstallableOptionalModules();
}
$selectedOptionalModuleNames = array();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?php 
echo $installationStrings['LBL_VTIGER_CRM_5'] . ' - ' . $installationStrings['LBL_CONFIG_WIZARD'] . ' - ' . $installationStrings['LBL_OPTIONAL_MODULES'];
?>
</title>