From 5029d013e3cfeb162fb427ffc33fa6386d8932a9 Mon Sep 17 00:00:00 2001
From: satish <satish.dvnk@vtiger.com>
Date: Tue, 16 May 2017 09:54:02 +0530
Subject: [PATCH] Added hook to stop migration if non ported extension found

---
 languages/en_us/Migration.php                 |   4 +-
 layouts/v7/modules/Install/Header.tpl         |  16 +-
 layouts/v7/modules/Install/Step1.tpl          |   2 +-
 .../v7/modules/Migration/MigrationStep1.tpl   |  60 +++++-
 .../v7/modules/Migration/MigrationStep2.tpl   |  65 +++++-
 .../v7/modules/Migration/resources/Index.js   |  26 +++
 migrate/index.php                             | 193 ++++++++++--------
 modules/Migration/actions/Extract.php         |  49 +++++
 modules/Migration/views/Index.php             |  14 +-
 9 files changed, 305 insertions(+), 124 deletions(-)
 create mode 100644 layouts/v7/modules/Migration/resources/Index.js
 create mode 100644 modules/Migration/actions/Extract.php

diff --git a/languages/en_us/Migration.php b/languages/en_us/Migration.php
index 8448f9a36..963b0baa0 100644
--- a/languages/en_us/Migration.php
+++ b/languages/en_us/Migration.php
@@ -14,11 +14,11 @@ $languageStrings = array(
 	'LBL_PRIDE_BEING_ASSOCIATED' => 'We take pride in being associated with you.',
 	'LBL_TALK_TO_US_AT_FORUMS' => 'Have any questions? Find help on Vtiger <a href="http://forums.vtiger.com" target="_blank"> Discussions </a><br>',
 	'LBL_DISCUSS_WITH_US_AT_BLOGS' => 'To know more about Vtiger follow us our <a href="http://blogs.vtiger.com" target="_blank">Blog</a>',
-	'LBL_CRM_DOCUMENTATION' => 'Vtiger6 Help - <a href="http://wiki.vtiger.com/vtiger6" target="_blank">Documentaion</a> , <a href="http://www.youtube.com/vtiger" target="_blank">Videos</a> <BR>',
+	'LBL_CRM_DOCUMENTATION' => 'Vtiger7 Help - <a href="http://wiki.vtiger.com/vtiger7" target="_blank">Documentaion</a> , <a href="http://www.youtube.com/vtiger" target="_blank">Videos</a> <BR>',
 	'LBL_THANKS' => 'Thanks for using <b>vtiger CRM</b>',
 	'LBL_WE_AIM_TO_BE_BEST' => 'We aim to be - simply the best',
 	'LBL_SPACE_FOR_YOU' => 'Come on over, there is space for you too!',
-	'LBL_MIGRATION_COMPLETED_SUCCESSFULLY' => 'Your vtiger6 migration completed successfully.',
+	'LBL_MIGRATION_COMPLETED_SUCCESSFULLY' => 'Your vtiger7 migration completed successfully.',
 	'LBL_RELEASE_NOTES' => 'To know what is new in this version, please read <a href="#" target="_blank">Release Notes</a> <br>',
 	'LBL_WAIT' => 'Please wait ...',
 	'LBL_INPROGRESS' => 'Migration Inprogress',
diff --git a/layouts/v7/modules/Install/Header.tpl b/layouts/v7/modules/Install/Header.tpl
index 7015904bc..b5cb1ac4f 100644
--- a/layouts/v7/modules/Install/Header.tpl
+++ b/layouts/v7/modules/Install/Header.tpl
@@ -16,13 +16,13 @@
 			<meta name="viewport" content="width=device-width, initial-scale=1.0" />
 			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/todc/css/bootstrap.min.css'>
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/todc/css/todc-bootstrap.min.css'>
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/font-awesome/css/font-awesome.min.css'>
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/jquery/select2/select2.css'>
-			<link type='text/css' rel='stylesheet' href='libraries/bootstrap/js/eternicode-bootstrap-datepicker/css/datepicker3.css'>
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/jquery/jquery-ui-1.11.3.custom/jquery-ui.css'>
-			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/vt-icons/style.css'>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/todc/css/bootstrap.min.css'/>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/todc/css/todc-bootstrap.min.css'/>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/font-awesome/css/font-awesome.min.css'/>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/jquery/select2/select2.css'/>
+			<link type='text/css' rel='stylesheet' href='libraries/bootstrap/js/eternicode-bootstrap-datepicker/css/datepicker3.css'/>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/jquery/jquery-ui-1.11.3.custom/jquery-ui.css'/>
+			<link type='text/css' rel='stylesheet' href='layouts/v7/lib/vt-icons/style.css'/>
 
 			{if strpos($V7_THEME_PATH,".less")!== false}
 				<link type="text/css" rel="stylesheet/less" href="{vresource_url($V7_THEME_PATH)}" media="screen" />
@@ -54,7 +54,7 @@
 			</script>
 		</head>
 		 {assign var=CURRENT_USER_MODEL value=Users_Record_Model::getCurrentUserModel()}
-		<body data-skinpath="{Vtiger_Theme::getBaseThemePath()}" data-language="{$LANGUAGE}" data-user-decimalseparator="{$CURRENT_USER_MODEL->get('currency_decimal_separator')}" data-user-dateformat="{$CURRENT_USER_MODEL->get('date_format')}"
+		<body style="font-size: 13px !important;" data-skinpath="{Vtiger_Theme::getBaseThemePath()}" data-language="{$LANGUAGE}" data-user-decimalseparator="{$CURRENT_USER_MODEL->get('currency_decimal_separator')}" data-user-dateformat="{$CURRENT_USER_MODEL->get('date_format')}"
 			data-user-groupingseparator="{$CURRENT_USER_MODEL->get('currency_grouping_separator')}" data-user-numberofdecimals="{$CURRENT_USER_MODEL->get('no_of_currency_decimals')}">
 			<div id="page">
 				<div id="pjaxContainer" class="hide noprint"></div>
diff --git a/layouts/v7/modules/Install/Step1.tpl b/layouts/v7/modules/Install/Step1.tpl
index 473be4216..852f2a7c5 100644
--- a/layouts/v7/modules/Install/Step1.tpl
+++ b/layouts/v7/modules/Install/Step1.tpl
@@ -7,7 +7,7 @@
 * All Rights Reserved.
 ************************************************************************************}
 
-<div class="row-fluid main-container">
+<div class="row main-container">
 	<div class="inner-container">
 		<div class="row">
 			<div class="col-sm-10">
diff --git a/layouts/v7/modules/Migration/MigrationStep1.tpl b/layouts/v7/modules/Migration/MigrationStep1.tpl
index 05e7598fa..1a7cc04f0 100644
--- a/layouts/v7/modules/Migration/MigrationStep1.tpl
+++ b/layouts/v7/modules/Migration/MigrationStep1.tpl
@@ -1,12 +1,52 @@
 {*+**********************************************************************************
- * The contents of this file are subject to the vtiger CRM Public License Version 1.1
- * ("License"); You may not use this file except in compliance with the License
- * The Original Code is: vtiger CRM Open Source
- * The Initial Developer of the Original Code is vtiger.
- * Portions created by vtiger are Copyright (C) vtiger.
- * All Rights Reserved.
- ************************************************************************************}
-{* modules/Migration/views/Index.php *}
+* The contents of this file are subject to the vtiger CRM Public License Version 1.1
+* ("License"); You may not use this file except in compliance with the License
+* The Original Code is: vtiger CRM Open Source
+* The Initial Developer of the Original Code is vtiger.
+* Portions created by vtiger are Copyright (C) vtiger.
+* All Rights Reserved.
+*************************************************************************************}
 
-{* START YOUR IMPLEMENTATION FROM BELOW. Use {debug} for information *}
-<DIV>TEMPLATE: layout/modules/Migration/MigrationStep1.tpl</DIV>
+{strip}
+	{include file="Header.tpl"|vtemplate_path:'Install'}
+	<div class="container-fluid page-container">
+		<div class="row">
+			<div class="col-lg-6">
+				<div class="logo">
+					<img src="{'logo.png'|vimage_path}"/>
+				</div>
+			</div>
+			<div class="col-lg-6">
+				<div class="head pull-right">
+					<h3>{vtranslate('LBL_MIGRATION_WIZARD', $MODULE)}</h3>
+				</div>
+			</div>
+		</div>
+		<div class="row main-container">
+			<div class="col-lg-12 inner-container">
+				<div id="running" class="alignCenter">
+					<br><br><br><br><br>
+					<h4> {vtranslate('LBL_WAIT',$MODULE)} </h4><br>
+					<img src="{vimage_path('install_loading.gif')}"/>
+					<h5> {vtranslate('LBL_INPROGRESS',$MODULE)} </h5>
+				</div>
+				<div id="success" class="hide">
+					<div class="row">
+						<div class="col-lg-10">
+							<h4> {vtranslate('LBL_DATABASE_CHANGE_LOG',$MODULE)} </h4>
+						</div>
+					</div><hr>
+				</div>
+				<div id="showDetails" class="hide" style="max-height: 350px; overflow: auto; padding: 10px; border: 1px solid #ddd;"></div><br>
+				<div id="nextButton" class="button-container col-lg-12 hide">
+					<form action='index.php' method="POST">
+						<input type="hidden" name="module" id="module" value="Migration">
+						<input type="hidden" name="view" id="view" value="Index">
+						<input type="hidden" name="mode" value="step2">
+						<input type="submit" class="btn btn-default btn-primary pull-right" value="{vtranslate('Next', $MODULE)}"/>
+					</form>
+				</div>
+			</div>
+		</div>
+	</div>
+{/strip}
\ No newline at end of file
diff --git a/layouts/v7/modules/Migration/MigrationStep2.tpl b/layouts/v7/modules/Migration/MigrationStep2.tpl
index 56a558ece..515e5dd70 100644
--- a/layouts/v7/modules/Migration/MigrationStep2.tpl
+++ b/layouts/v7/modules/Migration/MigrationStep2.tpl
@@ -1,12 +1,57 @@
 {*+**********************************************************************************
- * The contents of this file are subject to the vtiger CRM Public License Version 1.1
- * ("License"); You may not use this file except in compliance with the License
- * The Original Code is: vtiger CRM Open Source
- * The Initial Developer of the Original Code is vtiger.
- * Portions created by vtiger are Copyright (C) vtiger.
- * All Rights Reserved.
- ************************************************************************************}
-{* modules/Migration/views/Index.php *}
+* The contents of this file are subject to the vtiger CRM Public License Version 1.1
+* ("License"); You may not use this file except in compliance with the License
+* The Original Code is: vtiger CRM Open Source
+* The Initial Developer of the Original Code is vtiger.
+* Portions created by vtiger are Copyright (C) vtiger.
+* All Rights Reserved.
+*************************************************************************************}
 
-{* START YOUR IMPLEMENTATION FROM BELOW. Use {debug} for information *}
-<DIV>TEMPLATE: layout/modules/Migration/MigrationStep2.tpl</DIV>
+{strip}
+	{include file="Header.tpl"|vtemplate_path:'Install'}
+	<div class="container-fluid page-container">
+		<div class="row">
+			<div class="col-lg-6">
+				<div class="logo">
+					<img src="{'logo.png'|vimage_path}" alt="Vtiger Logo"/>
+				</div>
+			</div>
+			<div class="col-lg-6">
+				<div class="head pull-right">
+					<h3> {vtranslate('LBL_MIGRATION_WIZARD', $MODULE)}</h3>
+				</div>
+			</div>
+		</div>
+		<div class="row main-container">
+			<div class="col-lg-12 inner-container">
+				<div class="row">
+					<div class="col-lg-10">
+						<h4> {vtranslate('LBL_MIGRATION_COMPLETED', $MODULE)} </h4> 
+					</div>
+				</div>
+				<hr>
+				<div class="row">
+					<div class="col-lg-5 welcome-image">
+						<img src="{vimage_path('migration_screen.png')}" alt="Vtiger Logo" style="width:80%;"/>
+					</div>
+					<div class="col-lg-1"></div>
+					<div class="col-lg-6">
+						<br>
+						<h5>{vtranslate('LBL_MIGRATION_COMPLETED_SUCCESSFULLY', $MODULE)}</h5><br>
+						{vtranslate('LBL_RELEASE_NOTES', $MODULE)}<br>
+						{vtranslate('LBL_CRM_DOCUMENTATION', $MODULE)}<br>
+						{vtranslate('LBL_TALK_TO_US_AT_FORUMS', $MODULE)}<br>
+						{vtranslate('LBL_DISCUSS_WITH_US_AT_BLOGS', $MODULE)}<br><br>
+						Connect with us &nbsp;&nbsp;
+						<a href="https://www.facebook.com/vtiger" target="_blank"><img src="{vimage_path('facebook.png')}"></a>&nbsp;&nbsp;
+						<a href="https://twitter.com/vtigercrm" target="_blank"><img src="{vimage_path('twitter.png')}"></a>&nbsp;&nbsp;
+						<a href="//www.vtiger.com/products/crm/privacy_policy.html" target="_blank"><img src="{vimage_path('linkedin.png')}"></a>
+					</div>
+				</div>
+				<div class="button-container col-lg-12">
+					<input type="button" onclick="window.location.href='index.php'" class="btn btn-default btn-primary pull-right" value="{vtranslate('Finish', $MODULE)}" style="margin-left: 0px;"/>
+				</div>
+			</div>
+		</div>
+	</div>
+{/strip}
\ No newline at end of file
diff --git a/layouts/v7/modules/Migration/resources/Index.js b/layouts/v7/modules/Migration/resources/Index.js
new file mode 100644
index 000000000..2b8cc8c0f
--- /dev/null
+++ b/layouts/v7/modules/Migration/resources/Index.js
@@ -0,0 +1,26 @@
+/*+**********************************************************************************
+ * The contents of this file are subject to the vtiger CRM Public License Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * The Original Code is: vtiger CRM Open Source
+ * The Initial Developer of the Original Code is vtiger.
+ * Portions created by vtiger are Copyright (C) vtiger.
+ * All Rights Reserved.
+ ************************************************************************************/
+
+Vtiger.Class('Migration_Index_Js', {
+
+	startMigrationEvent: function () {
+		var migrateUrl = 'index.php?module=Migration&view=Index&mode=applyDBChanges';
+		app.request.post({url:migrateUrl}).then(function (err, data) {
+			jQuery('#running').addClass('hide').removeClass('show');
+			jQuery('#success').addClass('show').removeClass('hide');
+			jQuery('#nextButton').addClass('show').removeClass('hide');
+			jQuery('#showDetails').addClass('show').removeClass('hide').html(data);
+		});
+	},
+
+	registerEvents: function () {
+		this.startMigrationEvent();
+	}
+
+});
diff --git a/migrate/index.php b/migrate/index.php
index 377d3e41c..42185e8bf 100644
--- a/migrate/index.php
+++ b/migrate/index.php
@@ -1,111 +1,124 @@
 <?php
-/*+**********************************************************************************
+/* +**********************************************************************************
  * The contents of this file are subject to the vtiger CRM Public License Version 1.1
  * ("License"); You may not use this file except in compliance with the License
- * The Original Code is:  vtiger CRM Open Source
+ * The Original Code is: vtiger CRM Open Source
  * The Initial Developer of the Original Code is vtiger.
  * Portions created by vtiger are Copyright (C) vtiger.
  * All Rights Reserved.
- ************************************************************************************/
+ * ***********************************************************************************/
+
 chdir (dirname(__FILE__) . '/..');
 include_once 'vtigerversion.php';
 include_once 'data/CRMEntity.php';
+include_once 'includes/main/WebUI.php';
 
-@session_start();
-
-if(isset($_REQUEST['username']) && isset($_REQUEST['password'])){
-	global $root_directory, $log;
-	$userName = $_REQUEST['username'];
-	$password = $_REQUEST['password'];
-
-	$user = CRMEntity::getInstance('Users');
-	$user->column_fields['user_name'] = $userName;
-	if ($user->doLogin($password)) {
-		$zip = new ZipArchive();
-		$fileName = 'vtiger6.zip';
-		if ($zip->open($fileName)) {
-			for ($i = 0; $i < $zip->numFiles; $i++) {
-				$log->fatal('Filename: ' . $zip->getNameIndex($i) . '<br />');
-			}
-			if ($zip->extractTo($root_directory)) {
-				$zip->close();
-				
-				$userid = $user->retrieve_user_id($userName);
-				$_SESSION['authenticated_user_id'] = $userid;
-
-				header('Location: ../index.php?module=Migration&view=Index&mode=step1');
-			} else {
-				$errorMessage = '<p>ERROR EXTRACTING MIGRATION ZIP FILE!</p>';
-				header('Location: index.php?error='.$errorMessage);
+$errorMessage = $_REQUEST['error'];
+if (!$errorMessage) {
+	$extensionStoreInstance = Settings_ExtensionStore_Extension_Model::getInstance();
+	$vtigerStandardModules = array( 'Accounts', 'Assets', 'Calendar', 'Campaigns', 'Contacts', 'CustomerPortal',
+									'Dashboard', 'Documents', 'Emails', 'EmailTemplates', 'Events', 'ExtensionStore',
+									'Faq', 'Google', 'HelpDesk', 'Home', 'Import', 'Invoice', 'Leads', 'MailManager', 'Mobile', 'ModComments', 'ModTracker',
+									'PBXManager', 'Portal', 'Potentials', 'PriceBooks', 'Products', 'Project', 'ProjectMilestone', 'ProjectTask', 'PurchaseOrder',
+									'Quotes', 'RecycleBin', 'Reports', 'Rss', 'SalesOrder', 'ServiceContracts', 'Services', 'SMSNotifier', 'Users', 'Vendors',
+									'Webforms', 'Webmails', 'WSAPP');
+	$nonPortedExtns = array();
+	$db = PearDatabase::getInstance();
+	$result = $db->pquery('SELECT name FROM vtiger_tab WHERE trim(name) NOT IN ('.generateQuestionMarks($vtigerStandardModules).')', $vtigerStandardModules);
+	while($row = $db->fetch_row($result)) {
+		$module = $row['name'];//label
+		if ($module) {
+			$moduleModelsList = $extensionStoreInstance->findListings($module, 'Extension');
+			if ($moduleModelsList) {
+				foreach ($moduleModelsList as $moduleId => $moduleModel) {
+					$vtigerVersion = $moduleModel->get('vtigerVersion');
+					$vtigerMaxVersion = $moduleModel->get('vtigerMaxVersion');
+					if (($vtigerVersion && strpos($vtigerVersion, '7.') === false)
+							&& ($vtigerMaxVersion && strpos($vtigerMaxVersion, '7.') === false)) {
+						$nonPortedExtns[] = $module;
+					}
+				}
 			}
-		} else {
-			$errorMessage = 'ERROR READING MIGRATION ZIP FILE!';
-			header('Location: index.php?error='.$errorMessage);
 		}
-	} else {
-		$errorMessage = 'INVALID CREDENTIALS';
-		header('Location: index.php?error='.$errorMessage);
+	}
+	if ($nonPortedExtns) {
+		$portingMessage = 'Following extensions seem to have failed upgrade check with Vtiger7.<br><ul>';
+		foreach ($nonPortedExtns as $module) {
+			$portingMessage .= "<li>$module</li>";
+		}
+		$portingMessage .= '</ul>';
 	}
 }
 ?>
+
 <html>
-    <head>
+	<head>
 		<title>Vtiger CRM Setup</title>
 		<meta name="viewport" content="width=device-width, initial-scale=1.0">
 		<script type="text/javascript" src="resources/js/jquery-min.js"></script>
-		<link href="resources/bootstrap/css/bootstrap.min.css" rel="stylesheet">
+		<link href="../layouts/v7/lib/todc/css/bootstrap.min.css" rel="stylesheet">
+		<link href="../layouts/v7/lib/todc/css/todc-bootstrap.min.css" rel="stylesheet">
 		<link href="resources/css/mkCheckbox.css" rel="stylesheet">
 		<link href="resources/css/style.css" rel="stylesheet">
-    </head>
-    <body>
+	</head>
+	<body style="font-size: 14px !important;">
 		<div class="container-fluid page-container">
-			<div class="row-fluid">
-				<div class="span6">
+			<div class="row">
+				<div class="col-lg-6">
 					<div class="logo">
 						<img src="resources/images/vt1.png" alt="Vtiger Logo"/>
 					</div>
 				</div>
-				<div class="span6">
+				<div class="col-lg-6">
 					<div class="head pull-right">
 						<h3>Migration Wizard</h3>
 					</div>
 				</div>
 			</div>
-			<div class="row-fluid main-container">
-				<div class="span12 inner-container">
-					<div class="row-fluid">
-						<div class="span10">
-							<h4 class=""> Welcome </h4>
+			<div class="row main-container">
+				<div class="col-lg-12 inner-container">
+					<div class="row">
+						<div class="col-lg-10">
+							<h4 class="">Welcome</h4>
 						</div>
-						<div class="span2">
-							<a href="https://wiki.vtiger.com/vtiger6/" target="_blank" class="pull-right">
+						<div class="col-lg-2">
+							<a href="https://wiki.vtiger.com/vtiger7/" target="_blank" class="pull-right">
 								<img src="resources/images/help40.png" alt="Help-Icon"/>
 							</a>
 						</div>
 					</div>
 					<hr>
-					<div class="row-fluid">
-						<div class="span4 welcome-image">
-							<img src="resources/images/migration_screen.png" alt="Vtiger Logo"/>
+					<div class="row">
+						<div class="col-lg-4 welcome-image">
+							<img src="resources/images/migration_screen.png" alt="Vtiger Logo" style="width: 100%;"/>
 						</div>
-						<div class="span8">
-							<?php $currentVersion = explode('.', $vtiger_current_version);
-							if($currentVersion[0] >= 6 && $currentVersion[1] >= 0){?>
-							<div>
-								<h3> Welcome to Vtiger Migration </h3>
-								<?php
-								if(isset($_REQUEST['error'])) {
-									echo '<span><font color="red"><b>'.filter_var($_REQUEST['error'], FILTER_SANITIZE_STRING).'</b></font></span><br><br>';
-								}?>
-								<p>We have detected that you have <strong>Vtiger <?php echo $vtiger_current_version?> </strong>installation. <br> <br> </p>
+						<?php
+							$currentVersion = explode('.', $vtiger_current_version);
+							 if ($portingMessage) { ?>
+								<div class="col-lg-8">
+									<h3><font color="red">WARNING : Cannot continue with Migration</font></h3><br>
+									<p><?php echo $portingMessage;?></p>
+								</div>
+							</div>
+							<div class="button-container col-lg-12">
+								<input type="button" onclick="window.location.href='index.php'" class="btn btn-large btn-primary pull-right" value="Finish"/>
+						<?php } else if($currentVersion[0] >= 6 && $currentVersion[1] >= 0) { ?>
+							<div class="col-lg-8">
+								<h3> Welcome to Vtiger Migration</h3>
+								<?php if(isset($errorMessage)) {
+									echo '<span><font color="red"><b>'.filter_var($errorMessage, FILTER_SANITIZE_STRING).'</b></font></span><br><br>';
+								} ?>
+								<p>We have detected that you have <strong>Vtiger <?php echo $vtiger_current_version ?></strong> installation.<br><br></p>
 								<p>
-									<strong> Warning: </strong>Please note that it is not possible to revert back to <?php echo $vtiger_current_version?> after the upgrade to vtiger 6 <br>
-									So, it is important to take a backup of the <?php echo $vtiger_current_version?> installation, including the source files
-									and database.</p><br>
-								<form action="index.php" method="POST">
-									<div><input type="checkbox" id="checkBox1" name="checkBox1"/> <div class="chkbox"></div> I have taken the backup of database <a href="http://community.vtiger.com/help/vtigercrm/administrators/backup.html" target="_blank" >(how to?)</a> </div><br>
-									<div><input type="checkbox" id="checkBox2" name="checkBox2"/> <div class="chkbox"></div> I have taken the backup of source folder <a href="http://community.vtiger.com/help/vtigercrm/administrators/backup.html" target="_blank" >(how to?)</a></div><br>
-									<br><div>
+									<strong>Warning: </strong>
+									Please note that it is not possible to revert back to <?php echo $vtiger_current_version ?>&nbsp; after the upgrade to vtiger 6 <br>
+									So, it is important to take a backup of the <?php echo $vtiger_current_version ?> installation, including the source files and database.
+								</p><br>
+								<form action="../index.php?module=Migration&action=Extract&mode=reset" method="POST">
+									<div><input type="checkbox" id="checkBox1" name="checkBox1"/><div class="chkbox"></div> I have taken the backup of database <a href="http://community.vtiger.com/help/vtigercrm/administrators/backup.html" target="_blank" >(how to?)</a></div><br>
+									<div><input type="checkbox" id="checkBox2" name="checkBox2"/><div class="chkbox"></div> I have taken the backup of source folder <a href="http://community.vtiger.com/help/vtigercrm/administrators/backup.html" target="_blank" >(how to?)</a></div><br>
+									<br>
+									<div>
 										<span id="error"></span>
 										User Name <span class="no">&nbsp;</span>
 										<input type="text" value="" name="username" id="username" />&nbsp;&nbsp;
@@ -118,29 +131,31 @@ if(isset($_REQUEST['username']) && isset($_REQUEST['password'])){
 									</div>
 								</form>
 							</div>
-							<?php } else if($currentVersion[0] < 6){?>
-							<div><br><br><br><br><br>
-								<h3><font color='red'>WARNING : Cannot continue with Migration </font></h3>
-								<p>
-									We detected that this installation is running <strong>Vtiger CRM </strong><?php if($vtiger_current_version < 6 ) { echo '<b>'.$vtiger_current_version.'</b>'; } ?>.
+						<?php } else if($currentVersion[0] < 6) { ?>
+							<div class="col-lg-8">
+								<h3><font color="red">WARNING : Cannot continue with Migration</font></h3><br>
+								<p>We detected that this installation is running <strong>Vtiger CRM</strong>
+										<?php
+											if($vtiger_current_version < 6 ) {
+												echo '<b>'.$vtiger_current_version.'</b>';
+											}
+										?>.
 									Please upgrade to <strong>5.4.0</strong> first before continuing with this wizard.
 								</p>
-								<br><br><br><br>
-								<div class="button-container">
-										<input type="button" onclick="window.location.href='index.php'" class="btn btn-large btn-primary" value="Finish"/>
-								</div>
 							</div>
-							<?php } else {?><br><br><br><br>
-								<h3><font color='red'>WARNING : Cannot continue with Migration </font></h3>
-								<p>
-									<strong>We detected that this source is upgraded latest version.</strong>
-								</p>
-								<br><br><br><br>
-								<div class="button-container">
-										<input type="button" onclick="window.location.href='index.php'" class="btn btn-large btn-primary" value="Finish"/>
+							<div class="button-container col-lg-12">
+								<input type="button" onclick="window.location.href='index.php'" class="btn btn-large btn-primary pull-right" value="Finish"/>
+						<?php } else { ?>
+								<div class="col-lg-8">	
+									<h3><font color="red">WARNING : Cannot continue with Migration</font></h3>
+									<br>
+									<p>
+										We detected that this source is upgraded latest version.
+									</p>
 								</div>
-							<?php }?>
-						</div>
+								<div class="button-container col-lg-12">
+									<input type="button" onclick="window.location.href='index.php'" class="btn btn-large btn-primary pull-right" value="Finish"/>
+						<?php } ?>
 					</div>
 				</div>
 			</div>
@@ -159,6 +174,6 @@ if(isset($_REQUEST['username']) && isset($_REQUEST['password'])){
 					});
 				});
 			</script>
-    </body>
+	</body>
 </html>
 
diff --git a/modules/Migration/actions/Extract.php b/modules/Migration/actions/Extract.php
new file mode 100644
index 000000000..74b0ec681
--- /dev/null
+++ b/modules/Migration/actions/Extract.php
@@ -0,0 +1,49 @@
+<?php
+/*+**********************************************************************************
+ * The contents of this file are subject to the vtiger CRM Public License Version 1.1
+ * ("License"); You may not use this file except in compliance with the License
+ * The Original Code is: vtiger CRM Open Source
+ * The Initial Developer of the Original Code is vtiger.
+ * Portions created by vtiger are Copyright (C) vtiger.
+ * All Rights Reserved.
+ ************************************************************************************/
+
+class Migration_Extract_Action extends Vtiger_Action_Controller {
+
+	public function process(Vtiger_Request $request) {
+		global $root_directory, $log;
+		@session_start();
+		$userName = $request->get('username');
+		$password = $request->get('password');
+
+		$user = CRMEntity::getInstance('Users');
+		$user->column_fields['user_name'] = $userName;
+		if ($user->doLogin($password)) {
+			$zip = new ZipArchive();
+			$fileName = 'vtiger7.zip';
+			if ($zip->open($fileName)) {
+				for ($i = 0; $i < $zip->numFiles; $i++) {
+					$log->fatal('Filename: '.$zip->getNameIndex($i).'<br />');
+				}
+				if ($zip->extractTo($root_directory)) {
+					$zip->close();
+
+					$userid = $user->retrieve_user_id($userName);
+					$_SESSION['authenticated_user_id'] = $userid;
+
+					header('Location: index.php?module=Migration&view=Index&mode=step1');
+				} else {
+					$errorMessage = 'ERROR EXTRACTING MIGRATION ZIP FILE!';
+					header('Location: migrate/index.php?error='.$errorMessage);
+				}
+			} else {
+				$errorMessage = 'ERROR READING MIGRATION ZIP FILE!';
+				header('Location: migrate/index.php?error='.$errorMessage);
+			}
+		} else {
+			$errorMessage = 'INVALID CREDENTIALS';
+			header('Location: migrate/index.php?error='.$errorMessage);
+		}
+	}
+
+}
diff --git a/modules/Migration/views/Index.php b/modules/Migration/views/Index.php
index 504e81efe..95943fae3 100644
--- a/modules/Migration/views/Index.php
+++ b/modules/Migration/views/Index.php
@@ -22,9 +22,9 @@ class Migration_Index_View extends Vtiger_Basic_View {
 	}
 
 	public function process(Vtiger_Request $request) {
-                // Override error reporting to production mode
-                version_compare(PHP_VERSION, '5.5.0') <= 0 ? error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED) : error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); 
-            
+		// Override error reporting to production mode
+		version_compare(PHP_VERSION, '5.5.0') <= 0 ? error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED) : error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); 
+
 		$mode = $request->getMode();
 		if(!empty($mode)) {
 			$this->invokeExposedMethod($mode, $request);
@@ -52,6 +52,12 @@ class Migration_Index_View extends Vtiger_Basic_View {
 		parent::preProcess($request, false);
 	}
 
+	public function postProcess(Vtiger_Request $request) {
+		$viewer = $this->getViewer($request);
+		$moduleName = $request->getModule();
+		$viewer->view('InstallPostProcess.tpl', 'Install');
+	}
+
 	public function getHeaderCss(Vtiger_Request $request) {
 		$headerCssInstances = array();
 		$cssFileNames = array(
@@ -66,7 +72,7 @@ class Migration_Index_View extends Vtiger_Basic_View {
 	}
 
 	public function getHeaderScripts(Vtiger_Request $request) {
-		$headerScriptInstances = array();
+		$headerScriptInstances = parent::getHeaderScripts($request);
 		$moduleName = $request->getModule();
 
 		$jsFileNames = array(
-- 
GitLab