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