]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/index.php
Release 6.4.0beta1
[Github/sugarcrm.git] / modules / UpgradeWizard / index.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42  * Reserved. Contributor(s): ______________________________________..
43  * *******************************************************************************/
44
45 if(!is_admin($current_user)) {
46         sugar_die($app_strings['ERR_NOT_ADMIN']);
47 }
48
49 require_once('include/utils/db_utils.php');
50 require_once('include/utils/zip_utils.php');
51 require_once('modules/UpgradeWizard/uw_utils.php');
52 require_once('modules/Administration/UpgradeHistory.php');
53
54 $GLOBALS['top_message'] = '';
55
56 if(!isset($locale) || empty($locale)) {
57         $locale = new Localization();
58 }
59 global $sugar_config;
60 global $sugar_flavor;
61
62 ///////////////////////////////////////////////////////////////////////////////
63 ////    SYSTEM PREP
64 list($base_upgrade_dir, $base_tmp_upgrade_dir) = getUWDirs();
65 $subdirs = array('full', 'langpack', 'module', 'patch', 'theme');
66
67 global $sugar_flavor;
68
69 prepSystemForUpgrade();
70
71 $uwMain = '';
72 $steps = array();
73 $step = 0;
74 $showNext = '';
75 $showCancel = '';
76 $showBack = '';
77 $showRecheck = '';
78 $stepNext = '';
79 $stepCancel = '';
80 $stepBack = '';
81 $stepRecheck = '';
82 $showDone = '';
83 $showExit = '';
84 $disableNextForLicense='';
85
86 if(!isset($_SESSION['step']) || !is_array($_SESSION['step'])){
87         $_SESSION['step'] = array();
88 }
89
90 ////    END SYSTEM PREP
91 ///////////////////////////////////////////////////////////////////////////////
92
93 ///////////////////////////////////////////////////////////////////////////////
94 ////    LOGIC
95 $uh = new UpgradeHistory();
96 $smarty = new Sugar_Smarty();
97 set_upgrade_vars();
98 //Initialize the session variables. If upgrade_progress.php is already created
99 //look for session vars there and restore them
100 initialize_session_vars();
101
102 $deletedPackage =false;
103 $cancelUpgrade = false;
104 $backOrRecheckUpgrade = false;
105
106 // this flag set in pre_install.php->UWUpgrade();
107
108 //ADDING A SESSION VARIBALE FOR KEEPING TRACK OF TOTAL UPGRADE TIME.
109 if(!isset($_SESSION['totalUpgradeTime'])){
110   $_SESSION['totalUpgradeTime'] = 0;
111 }
112
113 if(!isset($mod_strings['LBL_UW_ACCEPT_THE_LICENSE']) || $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'] == null){
114         $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'] = 'Accept License';
115 }
116 if(!isset($mod_strings['LBL_UW_CONVERT_THE_LICENSE']) || $mod_strings['LBL_UW_CONVERT_THE_LICENSE'] == null){
117         $mod_strings['LBL_UW_CONVERT_THE_LICENSE'] = 'Convert License';
118 }
119
120 $license_title = $mod_strings['LBL_UW_ACCEPT_THE_LICENSE'];
121 if((isset($sugar_flavor) && $sugar_flavor != null) && ($sugar_flavor=='OS' || $sugar_flavor=='CE')){
122         $license_title = $mod_strings['LBL_UW_CONVERT_THE_LICENSE'];
123 }
124
125 if(isset($_REQUEST['delete_package']) && $_REQUEST['delete_package'] == 'true') {
126                 logThis('running delete old package');
127         $error = '';
128         if(!isset($_REQUEST['install_file']) || ($_REQUEST['install_file'] == "")) {
129                 logThis('ERROR: trying to delete non-existent file: ['.$_REQUEST['install_file'].']');
130             $error .= $mod_strings['ERR_UW_NO_FILE_UPLOADED'].'<br>';
131         }
132
133         // delete file in upgrades/patch
134         $delete_me = 'upload://upgrades/patch/'.basename(urldecode( $_REQUEST['install_file'] ));
135         if(is_file($delete_me) && !@unlink($delete_me)) {
136                 logThis('ERROR: could not delete: '.$delete_me);
137             $error .= $mod_strings['ERR_UW_FILE_NOT_DELETED'].$delete_me.'<br>';
138         }
139
140         // delete back up instance
141         $delete_dir = 'upload://upgrades/patch/'.remove_file_extension(urldecode($_REQUEST['install_file'])) . "-restore";
142         if(is_dir($delete_dir) && !@rmdir_recursive($delete_dir)) {
143                 logThis('ERROR: could not delete: '.$delete_dir);
144                 $error .= $mod_strings['ERR_UW_FILE_NOT_DELETED'].$delete_dir.'<br>';
145         }
146
147         if(!empty($error)) {
148                         $out = "<b><span class='error'>{$error}</span></b><br />";
149                         if(!empty($GLOBALS['top_message'])){
150                             $GLOBALS['top_message'] .= "<br />{$out}";
151                         }
152                         else{
153                             $GLOBALS['top_message'] = $out;
154                         }
155         }
156 }
157
158 //redirect to the new upgradewizard
159 if(isset($_SESSION['Upgraded451Wizard']) && $_SESSION['Upgraded451Wizard']==true){
160         if(!isset($_SESSION['Initial_451to500_Step'])){
161                         //redirect to the new upgradewizard
162                         $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
163                         //'<form name="redirect" action="' .$redirect_new_wizard. '" >';
164                         //echo "<meta http-equiv='refresh' content='0; url={$redirect_new_wizard}'>";
165                         $_SESSION['Initial_451to500_Step'] = true;
166                          //unset($_SESSION['step']);
167                         $_REQUEST['step'] = 0;
168          }
169                 $steps = array(
170                 'files' => array(
171                     'license_fiveO',
172                     'preflight',
173                     'commit',
174                     'end',
175                     'cancel',
176                 ),
177                 'desc' => array (
178                     $license_title,
179                     $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
180                     $mod_strings['LBL_UW_TITLE_COMMIT'],
181                     $mod_strings['LBL_UW_TITLE_END'],
182                     $mod_strings['LBL_UW_TITLE_CANCEL'],
183                 ),
184                 );
185 }
186 else{
187         if(isset($_SESSION['UpgradedUpgradeWizard']) && $_SESSION['UpgradedUpgradeWizard'] == true) {
188                 // Upgrading from 5.0 upwards and upload already performed.
189                 $steps = array(
190                         'files' => array(
191                             'start',
192                             'systemCheck',
193                             'preflight',
194                                 'commit',
195                             'end',
196                             'cancel',
197                     ),
198                     'desc' => array (
199                             $mod_strings['LBL_UW_TITLE_START'],
200                             $mod_strings['LBL_UW_TITLE_SYSTEM_CHECK'],
201                             $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
202                                         $mod_strings['LBL_UW_TITLE_COMMIT'],
203                             $mod_strings['LBL_UW_TITLE_END'],
204                             $mod_strings['LBL_UW_TITLE_CANCEL'],
205                     ),
206                 );
207         }
208         else{
209         /* BEGIN TEMP FIX:
210         This can be removed post 6.1.  As this is a new string that is introduced in 6.1, we can't
211         effectively load it into a pre 6.1 instance.  Running
212
213                 global $current_language;
214                 $lang = $current_language;
215                 if(empty($lang))
216                     $lang = $GLOBALS['sugar_config']['default_language'];
217                 require_once('include/SugarObjects/LanguageManager.php');
218                 LanguageManager::clearLanguageCache('UpgradeWizard',$lang);
219                 LanguageManager::loadModuleLanguage('UpgradeWizard',$lang,true);
220
221         causes strange theme issues with the Upgrade Wizard.
222         */
223         if (empty($mod_strings['LBL_UW_TITLE_LAYOUTS']))
224             $mod_strings['LBL_UW_TITLE_LAYOUTS'] = 'Layouts';
225         /* END TEMP FIX */
226
227         // Upgrading from 5.0 upwards and upload not performed yet.
228                 $steps = array(
229                         'files' => array(
230                             'start',
231                             'systemCheck',
232                             'upload',
233                             'preflight',
234                             'commit',
235                             'layouts',
236                             'end',
237                             'cancel',
238                     ),
239                     'desc' => array (
240                             $mod_strings['LBL_UW_TITLE_START'],
241                             $mod_strings['LBL_UW_TITLE_SYSTEM_CHECK'],
242                             $mod_strings['LBL_UPLOAD_UPGRADE'],
243                             $mod_strings['LBL_UW_TITLE_PREFLIGHT'],
244                             $mod_strings['LBL_UW_TITLE_COMMIT'],
245                             $mod_strings['LBL_UW_TITLE_LAYOUTS'],
246                             $mod_strings['LBL_UW_TITLE_END'],
247                             $mod_strings['LBL_UW_TITLE_CANCEL'],
248                     ),
249                 );
250
251         }
252 }
253
254 $upgradeStepFile = '';
255 if(isset($_REQUEST['step']) && $_REQUEST['step'] !=null){
256     if($_REQUEST['step'] == -1) {
257             $_REQUEST['step'] = count($steps['files']) - 1;
258     } elseif($_REQUEST['step'] >= count($steps['files'])) {
259             $_REQUEST['step'] = 0;
260     }
261    $upgradeStepFile = $steps['files'][$_REQUEST['step']];
262 } else {
263         //check if upgrade was run before. If so then resume from there
264         $previouUpgradeRun = get_upgrade_progress();
265         if($previouUpgradeRun != null){
266                 //echo 'Previous run '.$previouUpgradeRun.'</br>';
267                 $upgradeStepFile = $previouUpgradeRun;
268                 //reset REQUEST
269                 for($i=0;$i<sizeof($steps['files']);$i++){
270                         if($steps['files'][$i]== $previouUpgradeRun){
271                                 $_REQUEST['step']=$i;
272                                 break;
273                         }
274            }
275         }
276         else{
277                 // first time through - kill off old sessions
278             unset($_SESSION['step']);
279             $_REQUEST['step'] = 0;
280             $upgradeStepFile = $steps['files'][$_REQUEST['step']];
281         }
282 }
283
284 if($upgradeStepFile == 'license_fiveO'){
285         $disableNextForLicense = 'disabled = "disabled"';
286 }
287 if($upgradeStepFile == 'end'){
288     //if(isset($_SESSION['current_db_version']) && substr($_SESSION['current_db_version'],0,1) == 4){
289             ob_start();
290                  include('modules/ACL/install_actions.php');
291                  include('modules/Administration/RebuildRelationship.php');
292                  //also add the cache cleaning here.
293                 if(function_exists('deleteCache')){
294                         deleteCache();
295                 }
296                 ob_end_clean();
297        if(isset($_SESSION['current_db_version']) && substr($_SESSION['current_db_version'],0,1) == 4){
298                    //Remove footer from themes except default, love and link themes
299                     logThis('Start removing footer.php file from themes...');
300                         $deleteNot =array('themes/default/footer.php','themes/Love/footer.php','themes/Links/footer.php');
301                         removeFileFromPath('footer.php','themes', $deleteNot);
302                     logThis('End removing footer.php file from themes...');
303        }
304     //}
305 }
306
307 require('modules/UpgradeWizard/'.$upgradeStepFile.'.php');
308
309 $afterCurrentStep = $_REQUEST['step'] + 1;
310
311 ////    END LOGIC
312 ///////////////////////////////////////////////////////////////////////////////
313
314 ///////////////////////////////////////////////////////////////////////////////
315 ////    UPGRADE HISTORY
316 // display installed pieces and versions
317 $installeds = $uh->getAll();
318 $upgrades_installed = 0;
319
320 $uwHistory  = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="edit view"><tr><td>'.$mod_strings['LBL_UW_DESC_MODULES_INSTALLED']."<br>\n";
321 $uwHistory .= "<ul>\n";
322 $uwHistory .= "<table class=\"edit view\" cellspacing=5>\n";
323 $uwHistory .= <<<eoq
324         <tr>
325                 <td></td>
326                 <td align=left>
327                         <b>{$mod_strings['LBL_ML_NAME']}</b>
328                 </td>
329                 <td align=left>
330                         <b>{$mod_strings['LBL_ML_TYPE']}</b>
331                 </td>
332                 <td align=left>
333                         <b>{$mod_strings['LBL_ML_VERSION']}</b>
334                 </td>
335                 <td align=left>
336                         <b>{$mod_strings['LBL_ML_INSTALLED']}</b>
337                 </td>
338                 <td align=left>
339                         <b>{$mod_strings['LBL_ML_DESCRIPTION']}</b>
340                 </td>
341                 <td align=left>
342                         <b>{$mod_strings['LBL_ML_ACTION']}</b>
343                 </td>
344         </tr>
345 eoq;
346
347 foreach($installeds as $installed) {
348         $form_action = '';
349         $filename = from_html($installed->filename);
350         $date_entered = $installed->date_entered;
351         $type = $installed->type;
352         //rrs only display patches here
353         if($type == 'patch'){
354                 $version = $installed->version;
355                 $upgrades_installed++;
356                 $link = is_file($filename)? '   <input type="hidden" name="module" value="UpgradeWizard">
357                                         <input type="hidden" name="action" value="index">
358                                         <input type="hidden" name="step" value="'.$_REQUEST['step'].'">
359                                         <input type="hidden" name="delete_package" value="true">
360                                 <input type=hidden name="install_file" value="'.$filename.'" />
361                                 <input type=submit value="'.$mod_strings['LBL_BUTTON_DELETE'].'" />':'';
362
363                 $view = 'default';
364
365                 $target_manifest = remove_file_extension( $filename ) . "-manifest.php";
366
367                 // cn: bug 9174 - cleared out upgrade dirs, or corrupt entries in upgrade_history give us bad file paths
368                 if(is_file($target_manifest)) {
369                         require_once( "$target_manifest" );
370                         $name = empty($manifest['name']) ? $filename : $manifest['name'];
371                         $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description'];
372
373                         if(isset($manifest['icon']) && $manifest['icon'] != "") {
374                                 $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : "";
375                                 $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : "";
376                                 $manifest_icon = clean_path($manifest['icon']);
377                                 $icon = "<!--not_in_theme!--><img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir)+1) : $manifest_icon ) . "\">";
378                         } else {
379                                 $icon = getImageForType( $manifest['type'] );
380                         }
381
382                         $uwHistory .= "<form action=\"index.php\" method=\"post\">\n".
383                                 "<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".
384                                 "</form>\n";
385                 }
386         }
387 }
388
389
390 if($upgrades_installed == 0) {
391         $uwHistory .= "<td colspan='6'>";
392         $uwHistory .= $mod_strings['LBL_UW_NO_INSTALLED_UPGRADES'];
393         $uwHistory .= "</td></tr>";
394 }
395
396 $uwHistory .= "</table></td></tr>
397 </table>\n";
398 $uwHistory .= "</ul>\n";
399 ////    END UPGRADE HISTORY
400 ///////////////////////////////////////////////////////////////////////////////
401
402 ///////////////////////////////////////////////////////////////////////////////
403 ////    PAGE OUTPUT
404
405 if($upgradeStepFile=='preflight' || $upgradeStepFile=='commit' || $upgradeStepFile=='end'){
406 $UW_510RC_PACKAGE_MESSAGE=<<<eoq
407 <table cellpadding="3" cellspacing="0" border="0">
408         <tr>
409                 <th colspan="2" align="center">
410                         <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>
411                 </th>
412         </tr>
413 </table>
414 eoq;
415 }
416 $js=<<<eoq
417 <script type="text/javascript" language="Javascript">
418         function toggleNwFiles(target) {
419                 var div = document.getElementById(target);
420
421                 if(div.style.display == "none") {
422                         div.style.display = "";
423                 } else {
424                         div.style.display = "none";
425                 }
426         }
427
428
429
430 function handlePreflight(step) {
431                 if(step == 'preflight') {
432                         if(document.getElementById('select_schema_change') != null){
433                                 document.getElementById('schema').value = document.getElementById('select_schema_change').value;
434                         }
435                         if(document.getElementById('diffs') != null) {
436                                 /* preset the hidden var for defaults */
437                                 checkSqlStatus(false);
438
439                                 theForm = document.getElementById('diffs');
440                                 var serial = '';
441                                 for(i=0; i<theForm.elements.length; i++) {
442                                                 if(theForm.elements[i].type == 'checkbox' && theForm.elements[i].checked == false) {
443                                                 // we only want "DON'T OVERWRITE" files
444                                                 if(serial != '') {
445                                                         serial += "::";
446                                                 }
447                                                 serial += theForm.elements[i].value;
448                                         }
449                                 }                               document.getElementById('overwrite_files_serial').value = serial;
450
451                                 if(document.getElementById('addTask').checked == true) {
452                                         document.getElementById('addTaskReminder').value = 'remind';
453                                 }
454                                 if(document.getElementById('addEmail').checked == true) {
455                                         document.getElementById('addEmailReminder').value = 'remind';
456                                 }
457                         }
458                 }
459
460                 var merge_necessary = true;
461                 if(step == 'layouts')
462                    merge_necessary = getSelectedModulesForLayoutMerge();
463
464                 if(!merge_necessary){
465                         document.getElementById('step').value = '{$afterCurrentStep}';
466                 }
467
468                 return;
469         }
470
471 function handleUploadCheck(step, u_allow) {
472         if(step == 'upload' && !u_allow) {
473                 document.getElementById('top_message').innerHTML = '<span class="error"><b>{$mod_strings['LBL_UW_FROZEN']}</b></span>';
474         }
475
476         return;
477 }
478
479
480 function getSelectedModulesForLayoutMerge()
481 {
482         var found_one = false;
483     var results = new Array();
484     var table = document.getElementById('layoutSelection');
485     var moduleCheckboxes = table.getElementsByTagName('input');
486     for (var i = 0; i < moduleCheckboxes.length; i++)
487     {
488         var singleCheckbox = moduleCheckboxes[i];
489         if( typeof(singleCheckbox.type) != 'undefined' && singleCheckbox.type == 'checkbox'
490             && singleCheckbox.name.substring(0,2) == 'lm' && singleCheckbox.checked )
491         {
492             found_one = true;
493             results.push(singleCheckbox.name.substring(3)); //remove the 'lm_' key
494         }
495     }
496
497     var selectedModules = results.join('^,^');
498
499     var selectedModulesElement = document.createElement('input');
500     selectedModulesElement.setAttribute('type', 'hidden');
501     selectedModulesElement.setAttribute('name', 'layoutSelectedModules');
502     selectedModulesElement.setAttribute('value', selectedModules);
503
504     var upgradeForms = document.getElementsByName('UpgradeWizardForm');
505     upgradeForms[0].appendChild(selectedModulesElement);
506     return found_one;
507 }
508 </script>
509 eoq;
510
511 $smarty->assign('UW_MAIN', $uwMain);
512 $smarty->assign('UW_JS', $js);
513 $smarty->assign('CHECKLIST', getChecklist($steps, $step));
514 $smarty->assign('UW_TITLE', getClassicModuleTitle($mod_strings['LBL_UW_TITLE'], array($mod_strings['LBL_UW_TITLE'],$steps['desc'][$_REQUEST['step']]), false));
515 $smarty->assign('MOD', $mod_strings);
516 $smarty->assign('APP', $app_strings);
517 $smarty->assign('GRIDLINE', $current_user->getPreference('gridline'));
518 $smarty->assign('showNext', $showNext);
519 $smarty->assign('showCancel', $showCancel);
520 $smarty->assign('showBack', $showBack);
521 $smarty->assign('showRecheck', $showRecheck);
522 $smarty->assign('showDone', $showDone);
523 $smarty->assign('showExit', $showExit);
524 $smarty->assign('STEP_NEXT', $stepNext);
525 $smarty->assign('STEP_CANCEL', $stepCancel);
526 $smarty->assign('STEP_BACK', $stepBack);
527 $smarty->assign('STEP_RECHECK', $stepRecheck);
528 $smarty->assign('step', $steps['files'][$_REQUEST['step']]);
529 $smarty->assign('UW_HISTORY', $uwHistory);
530 $smarty->assign('disableNextForLicense',$disableNextForLicense);
531 $u_allow='true';
532 if(isset($stop) && $stop == true) {
533         $frozen = (isset($frozen)) ? "<br />".$frozen : '';
534         $smarty->assign('frozen', $frozen);
535         if($step == 'upload')
536             $u_allow = 'false';
537 }
538 $smarty->assign('u_allow', $u_allow);
539 if(!empty($GLOBALS['top_message'])){
540         $smarty->assign('top_message', $GLOBALS['top_message']);
541 }
542
543 if ($sugar_config['sugar_version'] < '5.5') {
544         $smarty->assign('includeContainerCSS', true);
545 } else {
546         $smarty->assign('includeContainerCSS', false);
547 } // else
548 $smarty->display('modules/UpgradeWizard/uw_main.tpl');
549 ////    END PAGE OUTPUT
550 ///////////////////////////////////////////////////////////////////////////////
551
552 ?>