2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42 * Reserved. Contributor(s): ______________________________________..
43 * *******************************************************************************/
45 if(!is_admin($current_user)) {
46 sugar_die($app_strings['ERR_NOT_ADMIN']);
49 require_once('include/utils/db_utils.php');
51 require_once('include/utils/zip_utils.php');
53 require_once('modules/UpgradeWizard/uw_utils.php');
55 require_once('modules/Administration/UpgradeHistory.php');
57 $GLOBALS['top_message'] = '';
60 if(!isset($locale) || empty($locale)) {
62 $locale = new Localization();
67 ///////////////////////////////////////////////////////////////////////////////
69 $base_upgrade_dir = getcwd().'/'.$sugar_config['upload_dir'] . "upgrades";
70 $base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
71 $subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
75 prepSystemForUpgrade();
90 $disableNextForLicense='';
92 if(!isset($_SESSION['step']) || !is_array($_SESSION['step'])){
93 $_SESSION['step'] = array();
97 ///////////////////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////////////////
101 $uh = new UpgradeHistory();
102 $smarty = new Sugar_Smarty();
104 //Initialize the session variables. If upgrade_progress.php is already created
105 //look for session vars there and restore them
106 initialize_session_vars();
108 $deletedPackage =false;
109 $cancelUpgrade = false;
110 $backOrRecheckUpgrade = false;
112 // this flag set in pre_install.php->UWUpgrade();
114 //ADDING A SESSION VARIBALE FOR KEEPING TRACK OF TOTAL UPGRADE TIME.
115 if(!isset($_SESSION['totalUpgradeTime'])){
116 $_SESSION['totalUpgradeTime'] = 0;
119 if(!isset($mod_strings['LBL_UW_ACCEPT_THE_LICENSE']) || $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'] == null){
120 $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'] = 'Accept License';
122 if(!isset($mod_strings['LBL_UW_CONVERT_THE_LICENSE']) || $mod_strings['LBL_UW_CONVERT_THE_LICENSE'] == null){
123 $mod_strings['LBL_UW_CONVERT_THE_LICENSE'] = 'Convert License';
126 $license_title = $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'];
127 if((isset($sugar_flavor) && $sugar_flavor != null) && ($sugar_flavor=='OS' || $sugar_flavor=='CE')){
128 $license_title = $mod_strings['LBL_UW_CONVERT_THE_LICENSE'];
131 if(isset($_REQUEST['delete_package']) && $_REQUEST['delete_package'] == 'true') {
132 logThis('running delete old package');
134 if(!isset($_REQUEST['install_file']) || ($_REQUEST['install_file'] == "")) {
135 logThis('ERROR: trying to delete non-existent file: ['.$_REQUEST['install_file'].']');
136 $error .= $mod_strings['ERR_UW_NO_FILE_UPLOADED'].'<br>';
139 // delete file in upgrades/patch
140 $delete_me = urldecode( $_REQUEST['install_file'] );
141 if(is_file($delete_me) && !@unlink($delete_me)) {
142 logThis('ERROR: could not delete: '.$delete_me);
143 $error .= $mod_strings['ERR_UW_FILE_NOT_DELETED'].$delete_me.'<br>';
146 // delete back up instance
147 $delete_dir = clean_path(remove_file_extension(urldecode($_REQUEST['install_file'])) . "-restore");
148 if(is_dir($delete_dir) && !@rmdir_recursive($delete_dir)) {
149 logThis('ERROR: could not delete: '.$delete_dir);
150 $error .= $mod_strings['ERR_UW_FILE_NOT_DELETED'].$delete_dir.'<br>';
153 // delete file in cache/upload
154 $fileS = explode('/', $delete_me);
156 $fileName = (isset($fileS[$c-1]) && !empty($fileS[$c-1])) ? $fileS[$c-1] : $fileS[$c-2];
157 $deleteUpload = getcwd().'/'.$sugar_config['upload_dir'].$fileName;
158 logThis('Trying to delete '.$deleteUpload);
159 if(is_file($deleteUpload) && !@unlink($deleteUpload)) {
160 logThis('ERROR: could not delete: ['.$deleteUpload.']');
161 $error .= $mod_strings['ERR_UW_FILE_NOT_DELETED'].$sugar_config['upload_dir'].$fileName;
165 $out = "<b><span class='error'>{$error}</span></b><br />";
166 if(!empty($GLOBALS['top_message'])){
167 $GLOBALS['top_message'] .= "<br />{$out}";
170 $GLOBALS['top_message'] = $out;
175 //redirect to the new upgradewizard
176 if(isset($_SESSION['Upgraded451Wizard']) && $_SESSION['Upgraded451Wizard']==true){
177 if(!isset($_SESSION['Initial_451to500_Step'])){
178 //redirect to the new upgradewizard
179 $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
180 //'<form name="redirect" action="' .$redirect_new_wizard. '" >';
181 //echo "<meta http-equiv='refresh' content='0; url={$redirect_new_wizard}'>";
182 $_SESSION['Initial_451to500_Step'] = true;
183 //unset($_SESSION['step']);
184 $_REQUEST['step'] = 0;
196 $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
197 $mod_strings['LBL_UW_TITLE_COMMIT'],
198 $mod_strings['LBL_UW_TITLE_END'],
199 $mod_strings['LBL_UW_TITLE_CANCEL'],
204 if(isset($_SESSION['UpgradedUpgradeWizard']) && $_SESSION['UpgradedUpgradeWizard'] == true) {
205 // Upgrading from 5.0 upwards and upload already performed.
216 $mod_strings['LBL_UW_TITLE_START'],
217 $mod_strings['LBL_UW_TITLE_SYSTEM_CHECK'],
218 $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
219 $mod_strings['LBL_UW_TITLE_COMMIT'],
220 $mod_strings['LBL_UW_TITLE_END'],
221 $mod_strings['LBL_UW_TITLE_CANCEL'],
227 This can be removed post 6.1. As this is a new string that is introduced in 6.1, we can't
228 effectively load it into a pre 6.1 instance. Running
230 global $current_language;
231 $lang = $current_language;
233 $lang = $GLOBALS['sugar_config']['default_language'];
234 require_once('include/SugarObjects/LanguageManager.php');
235 LanguageManager::clearLanguageCache('UpgradeWizard',$lang);
236 LanguageManager::loadModuleLanguage('UpgradeWizard',$lang,true);
238 causes strange theme issues with the Upgrade Wizard.
240 if (empty($mod_strings['LBL_UW_TITLE_LAYOUTS']))
241 $mod_strings['LBL_UW_TITLE_LAYOUTS'] = 'Layouts';
244 // Upgrading from 5.0 upwards and upload not performed yet.
257 $mod_strings['LBL_UW_TITLE_START'],
258 $mod_strings['LBL_UW_TITLE_SYSTEM_CHECK'],
259 $mod_strings['LBL_UPLOAD_UPGRADE'],
260 $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
261 $mod_strings['LBL_UW_TITLE_COMMIT'],
262 $mod_strings['LBL_UW_TITLE_LAYOUTS'],
263 $mod_strings['LBL_UW_TITLE_END'],
264 $mod_strings['LBL_UW_TITLE_CANCEL'],
271 $upgradeStepFile = '';
272 if(isset($_REQUEST['step']) && $_REQUEST['step'] !=null){
273 if($_REQUEST['step'] == -1) {
274 $_REQUEST['step'] = count($steps['files']) - 1;
275 } elseif($_REQUEST['step'] >= count($steps['files'])) {
276 $_REQUEST['step'] = 0;
278 $upgradeStepFile = $steps['files'][$_REQUEST['step']];
280 //check if upgrade was run before. If so then resume from there
281 $previouUpgradeRun = get_upgrade_progress();
282 if($previouUpgradeRun != null){
283 //echo 'Previous run '.$previouUpgradeRun.'</br>';
284 $upgradeStepFile = $previouUpgradeRun;
286 for($i=0;$i<sizeof($steps['files']);$i++){
287 if($steps['files'][$i]== $previouUpgradeRun){
288 $_REQUEST['step']=$i;
294 // first time through - kill off old sessions
295 unset($_SESSION['step']);
296 $_REQUEST['step'] = 0;
297 $upgradeStepFile = $steps['files'][$_REQUEST['step']];
301 if($upgradeStepFile == 'license_fiveO'){
302 $disableNextForLicense = 'disabled = "disabled"';
304 if($upgradeStepFile == 'end'){
305 //if(isset($_SESSION['current_db_version']) && substr($_SESSION['current_db_version'],0,1) == 4){
307 include('modules/ACL/install_actions.php');
308 include('modules/Administration/RebuildRelationship.php');
309 //also add the cache cleaning here.
310 if(function_exists('deleteCache')){
314 if(isset($_SESSION['current_db_version']) && substr($_SESSION['current_db_version'],0,1) == 4){
315 //Remove footer from themes except default, love and link themes
316 logThis('Start removing footer.php file from themes...');
317 $deleteNot =array('themes/default/footer.php','themes/Love/footer.php','themes/Links/footer.php');
318 removeFileFromPath('footer.php','themes', $deleteNot);
319 logThis('End removing footer.php file from themes...');
324 require('modules/UpgradeWizard/'.$upgradeStepFile.'.php');
326 $afterCurrentStep = $_REQUEST['step'] + 1;
329 ///////////////////////////////////////////////////////////////////////////////
331 ///////////////////////////////////////////////////////////////////////////////
333 // display installed pieces and versions
334 $installeds = $uh->getAll();
335 $upgrades_installed = 0;
337 $uwHistory = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="edit view"><tr><td>'.$mod_strings['LBL_UW_DESC_MODULES_INSTALLED']."<br>\n";
338 $uwHistory .= "<ul>\n";
339 $uwHistory .= "<table class=\"edit view\" cellspacing=5>\n";
344 <b>{$mod_strings['LBL_ML_NAME']}</b>
347 <b>{$mod_strings['LBL_ML_TYPE']}</b>
350 <b>{$mod_strings['LBL_ML_VERSION']}</b>
353 <b>{$mod_strings['LBL_ML_INSTALLED']}</b>
356 <b>{$mod_strings['LBL_ML_DESCRIPTION']}</b>
359 <b>{$mod_strings['LBL_ML_ACTION']}</b>
364 foreach($installeds as $installed) {
366 $filename = from_html($installed->filename);
367 $date_entered = $installed->date_entered;
368 $type = $installed->type;
369 //rrs only display patches here
370 if($type == 'patch'){
371 $version = $installed->version;
372 $upgrades_installed++;
373 $link = is_file($filename)? ' <input type="hidden" name="module" value="UpgradeWizard">
374 <input type="hidden" name="action" value="index">
375 <input type="hidden" name="step" value="'.$_REQUEST['step'].'">
376 <input type="hidden" name="delete_package" value="true">
377 <input type=hidden name="install_file" value="'.$filename.'" />
378 <input type=submit value="'.$mod_strings['LBL_BUTTON_DELETE'].'" />':'';
382 $target_manifest = remove_file_extension( $filename ) . "-manifest.php";
384 // cn: bug 9174 - cleared out upgrade dirs, or corrupt entries in upgrade_history give us bad file paths
385 if(is_file($target_manifest)) {
386 require_once( "$target_manifest" );
387 $name = empty($manifest['name']) ? $filename : $manifest['name'];
388 $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
390 if(isset($manifest['icon']) && $manifest['icon'] != "") {
391 $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
392 $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
393 $manifest_icon = clean_path($manifest['icon']);
394 $icon = "<img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir)+1) : $manifest_icon ) . "\">";
396 $icon = getImageForType( $manifest['type'] );
399 $uwHistory .= "<form action=\"index.php\" method=\"post\">\n".
400 "<tr><td align=left>$icon</td><td align=left>$name</td><td align=left>$type</td><td align=left>$version</td><td align=left>$date_entered</td><td align=left>$description</td><td align=left>$link</td></tr>\n".
407 if($upgrades_installed == 0) {
408 $uwHistory .= "<td colspan='6'>";
409 $uwHistory .= $mod_strings['LBL_UW_NO_INSTALLED_UPGRADES'];
410 $uwHistory .= "</td></tr>";
413 $uwHistory .= "</table></td></tr>
415 $uwHistory .= "</ul>\n";
416 //// END UPGRADE HISTORY
417 ///////////////////////////////////////////////////////////////////////////////
419 ///////////////////////////////////////////////////////////////////////////////
422 if($upgradeStepFile=='preflight' || $upgradeStepFile=='commit' || $upgradeStepFile=='end'){
423 $UW_510RC_PACKAGE_MESSAGE=<<<eoq
424 <table cellpadding="3" cellspacing="0" border="0">
426 <th colspan="2" align="center">
427 <h1><span class='error'><b>We do not recommended upgrading your production system to 5.1.0 RC. We recommend upgrading a development system for testing purposes.</b></span></h1>
434 <script type="text/javascript" language="Javascript">
435 function toggleNwFiles(target) {
436 var div = document.getElementById(target);
438 if(div.style.display == "none") {
439 div.style.display = "";
441 div.style.display = "none";
447 function handlePreflight(step) {
448 if(step == 'preflight') {
449 if(document.getElementById('select_schema_change') != null){
450 document.getElementById('schema').value = document.getElementById('select_schema_change').value;
452 if(document.getElementById('diffs') != null) {
453 /* preset the hidden var for defaults */
454 checkSqlStatus(false);
456 theForm = document.getElementById('diffs');
458 for(i=0; i<theForm.elements.length; i++) {
459 if(theForm.elements[i].type == 'checkbox' && theForm.elements[i].checked == false) {
460 // we only want "DON'T OVERWRITE" files
464 serial += theForm.elements[i].value;
466 } document.getElementById('overwrite_files_serial').value = serial;
468 if(document.getElementById('addTask').checked == true) {
469 document.getElementById('addTaskReminder').value = 'remind';
471 if(document.getElementById('addEmail').checked == true) {
472 document.getElementById('addEmailReminder').value = 'remind';
477 var merge_necessary = true;
478 if(step == 'layouts')
479 merge_necessary = getSelectedModulesForLayoutMerge();
481 if(!merge_necessary){
482 document.getElementById('step').value = '{$afterCurrentStep}';
488 function handleUploadCheck(step, u_allow) {
489 if(step == 'upload' && !u_allow) {
490 document.getElementById('top_message').innerHTML = '<span class="error"><b>{$mod_strings['LBL_UW_FROZEN']}</b></span>';
497 function getSelectedModulesForLayoutMerge()
499 var found_one = false;
500 var results = new Array();
501 var table = document.getElementById('layoutSelection');
502 var moduleCheckboxes = table.getElementsByTagName('input');
503 for (var i = 0; i < moduleCheckboxes.length; i++)
505 var singleCheckbox = moduleCheckboxes[i];
506 if( typeof(singleCheckbox.type) != 'undefined' && singleCheckbox.type == 'checkbox'
507 && singleCheckbox.name.substring(0,2) == 'lm' && singleCheckbox.checked )
510 results.push(singleCheckbox.name.substring(3)); //remove the 'lm_' key
514 var selectedModules = results.join('^,^');
516 var selectedModulesElement = document.createElement('input');
517 selectedModulesElement.setAttribute('type', 'hidden');
518 selectedModulesElement.setAttribute('name', 'layoutSelectedModules');
519 selectedModulesElement.setAttribute('value', selectedModules);
521 var upgradeForms = document.getElementsByName('UpgradeWizardForm');
522 upgradeForms[0].appendChild(selectedModulesElement);
528 $smarty->assign('UW_MAIN', $uwMain);
529 $smarty->assign('UW_JS', $js);
530 $smarty->assign('CHECKLIST', getChecklist($steps, $step));
531 $smarty->assign('UW_TITLE', getClassicModuleTitle($mod_strings['LBL_UW_TITLE'], array($mod_strings['LBL_UW_TITLE'],$steps['desc'][$_REQUEST['step']]), false));
532 $smarty->assign('MOD', $mod_strings);
533 $smarty->assign('APP', $app_strings);
534 $smarty->assign('GRIDLINE', $current_user->getPreference('gridline'));
535 $smarty->assign('showNext', $showNext);
536 $smarty->assign('showCancel', $showCancel);
537 $smarty->assign('showBack', $showBack);
538 $smarty->assign('showRecheck', $showRecheck);
539 $smarty->assign('showDone', $showDone);
540 $smarty->assign('showExit', $showExit);
541 $smarty->assign('STEP_NEXT', $stepNext);
542 $smarty->assign('STEP_CANCEL', $stepCancel);
543 $smarty->assign('STEP_BACK', $stepBack);
544 $smarty->assign('STEP_RECHECK', $stepRecheck);
545 $smarty->assign('step', $steps['files'][$_REQUEST['step']]);
546 $smarty->assign('UW_HISTORY', $uwHistory);
547 $smarty->assign('disableNextForLicense',$disableNextForLicense);
549 if(isset($stop) && $stop == true) {
550 $frozen = (isset($frozen)) ? "<br />".$frozen : '';
551 $smarty->assign('frozen', $frozen);
552 if($step == 'upload')
555 $smarty->assign('u_allow', $u_allow);
556 if(!empty($GLOBALS['top_message'])){
557 $smarty->assign('top_message', $GLOBALS['top_message']);
560 if ($sugar_config['sugar_version'] < '5.5') {
561 $smarty->assign('includeContainerCSS', true);
563 $smarty->assign('includeContainerCSS', false);
565 $smarty->display('modules/UpgradeWizard/uw_main.tpl');
567 ///////////////////////////////////////////////////////////////////////////////