]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/commit.php
Release 6.5.9
[Github/sugarcrm.git] / modules / UpgradeWizard / commit.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry)
3         die('Not A Valid Entry Point');
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39 /*********************************************************************************
40
41  * Description:
42  * Portions created by SugarCRM are Copyright(C) SugarCRM, Inc. All Rights
43  * Reserved. Contributor(s): ______________________________________..
44  * *******************************************************************************/
45 require_once('include/SugarLogger/SugarLogger.php');
46
47 $trackerManager = TrackerManager::getInstance();
48 $trackerManager->pause();
49 $trackerManager->unsetMonitors();
50
51 $_SESSION['upgrade_complete'] = '';
52 $_REQUEST['upgradeWizard'] = true;
53
54
55 logThis('[At commit.php]');
56 $stop = true; // flag to show "next"
57
58 //refreshing mod_strings
59
60 global $mod_strings;
61 $curr_lang = 'en_us';
62 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null)){
63         $curr_lang = $GLOBALS['current_language'];
64 }
65 return_module_language($curr_lang, 'UpgradeWizard', true);
66
67
68 $standardErrorLevel = error_reporting();
69 logThis("Setting error_reporting() to E_ERROR while running upgrade");
70 error_reporting(E_ERROR);
71
72 set_time_limit(0);
73 /*
74  * [unzip_dir] => /Users/curisu/www/head/cache/upload//upgrades/temp/QSugp3
75  * [zip_from_dir]  => SugarEnt-Upgrade-4.0.1-to-4.2.1
76  * rest_dir: /Users/curisu/www/head/cache/upload/SugarEnt-Upgrade-4.0.1-to-4.2.1-restore
77  */
78
79 // flag upgradeSql script run method
80 $_SESSION['schema_change'] = $_REQUEST['schema_change'];
81 if(didThisStepRunBefore('commit')){
82         $_SESSION['committed'] = true;
83 }
84 else{
85         set_upgrade_progress('commit','in_progress','commit','in_progress');
86 }
87 //Initialize session errors array
88 if(!isset($_SESSION['sqlSkippedQueries']) && !is_array($_SESSION['sqlSkippedQueries'])){
89         $_SESSION['sqlSkippedQueries'] = array();
90 }
91 // prevent "REFRESH" double commits
92 if(!isset($_SESSION['committed'])) {
93         //$_SESSION['committed'] = true; // flag to prevent refresh double-commit
94         //set the flag at the end though
95         unset($_SESSION['rebuild_relationships']);
96         unset($_SESSION['rebuild_extensions']);
97     //put checks for follwing files
98
99         if(!isset($_SESSION['unzip_dir']) || empty($_SESSION['unzip_dir'])) {
100                 logThis('unzipping files in upgrade archive...');
101                 $errors                                 = array();
102                 list($base_upgrade_dir, $base_tmp_upgrade_dir) = getUWDirs();
103                 $unzip_dir = '';
104                 //also come up with mechanism to read from upgrade-progress file
105                 if(!isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !is_file($_SESSION['install_file'])) {
106                         if (file_exists(clean_path($base_tmp_upgrade_dir)) && $handle = opendir(clean_path($base_tmp_upgrade_dir))) {
107                                 while (false !== ($file = readdir($handle))) {
108                                 if($file !="." && $file !="..") {
109                                          //echo $base_tmp_upgrade_dir."/".$file.'</br>';
110                                          if(is_file($base_tmp_upgrade_dir."/".$file."/manifest.php")){
111                                                 require_once($base_tmp_upgrade_dir."/".$file."/manifest.php");
112                                                 $package_name= $manifest['copy_files']['from_dir'];
113                                                 //echo file_exists($base_tmp_upgrade_dir."/".$file."/".$package_name).'</br>';
114                                                 if(file_exists($base_tmp_upgrade_dir."/".$file."/".$package_name) && file_exists($base_tmp_upgrade_dir."/".$file."/scripts") && file_exists($base_tmp_upgrade_dir."/".$file."/manifest.php")){
115                                                         //echo 'Yeah this the directory '. $base_tmp_upgrade_dir."/".$file;
116                                                         $unzip_dir = $base_tmp_upgrade_dir."/".$file;
117                                                         if(file_exists("$base_upgrade_dir/patch/".$package_name.'.zip')){
118                                                                 $_SESSION['install_file'] = $package_name.'.zip';
119                                                                 break;
120                                                         }
121                                                 }
122                                           }
123                                 }
124                         }
125                         }
126                 }
127         if(!isset($_SESSION['install_file']) || empty($_SESSION['install_file'])){
128                 unlinkUWTempFiles();
129                 resetUwSession();
130                 echo 'Upload File not found so redirecting to Upgrade Start ';
131                 $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
132                 echo '<form name="redirect" action="' .$redirect_new_wizard. '"  method="POST">';
133             $upgrade_directories_not_found =<<<eoq
134         <table cellpadding="3" cellspacing="0" border="0">
135                 <tr>
136                         <th colspan="2" align="left">
137                                 <span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
138                         </th>
139                 </tr>
140         </table>
141 eoq;
142             $uwMain = $upgrade_directories_not_found;
143                         return '';
144         }
145                 $install_file                   = "$base_upgrade_dir/patch/".basename(urldecode( $_SESSION['install_file'] ));
146                 $show_files                             = true;
147                 if(empty($unzip_dir)){
148                         $unzip_dir                              = mk_temp_dir( $base_tmp_upgrade_dir );
149                 }
150                 $zip_from_dir                   = ".";
151                 $zip_to_dir                             = ".";
152                 $zip_force_copy                 = array();
153
154                 if(!$unzip_dir){
155                         logThis('Could not create a temporary directory using mk_temp_dir( $base_tmp_upgrade_dir )');
156                         die($mod_strings['ERR_UW_NO_CREATE_TMP_DIR']);
157                 }
158
159                 //double check whether unzipped .
160                 if(file_exists($unzip_dir ."/scripts") && file_exists($unzip_dir."/manifest.php")){
161                 //already unzipped
162                 }
163                 else{
164                         unzip( $install_file, $unzip_dir );
165                 }
166
167                 // assumption -- already validated manifest.php at time of upload
168                 require_once( "$unzip_dir/manifest.php" );
169
170                 if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){
171                     $zip_from_dir   = $manifest['copy_files']['from_dir'];
172                 }
173                 if( isset( $manifest['copy_files']['to_dir'] ) && $manifest['copy_files']['to_dir'] != "" ){
174                     $zip_to_dir     = $manifest['copy_files']['to_dir'];
175                 }
176                 if( isset( $manifest['copy_files']['force_copy'] ) && $manifest['copy_files']['force_copy'] != "" ){
177                     $zip_force_copy     = $manifest['copy_files']['force_copy'];
178                 }
179                 if( isset( $manifest['version'] ) ){
180                     $version    = $manifest['version'];
181                 }
182                 if( !is_writable( "config.php" ) ){
183                         return $mod_strings['ERR_UW_CONFIG'];
184                 }
185
186                 $_SESSION['unzip_dir'] = clean_path($unzip_dir);
187                 $_SESSION['zip_from_dir'] = clean_path($zip_from_dir);
188                 logThis('unzip done.');
189         } else {
190                 $unzip_dir = $_SESSION['unzip_dir'];
191                 $zip_from_dir = $_SESSION['zip_from_dir'];
192         }
193
194     //check if $_SESSION['unzip_dir'] and $_SESSION['zip_from_dir'] exist
195         if(!isset($_SESSION['unzip_dir']) || !file_exists($_SESSION['unzip_dir'])
196                 || !isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !file_exists($_SESSION['install_file'])){
197                     //redirect to start
198             unlinkUWTempFiles();
199                 resetUwSession();
200                 echo 'Upload File not found so redirecting to Upgrade Start ';
201                 $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
202                 echo '<form name="redirect" action="' .$redirect_new_wizard. '"  method="POST">';
203         $upgrade_directories_not_found =<<<eoq
204         <table cellpadding="3" cellspacing="0" border="0">
205                 <tr>
206                         <th colspan="2" align="left">
207                                 <span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
208                         </th>
209                 </tr>
210         </table>
211 eoq;
212         $uwMain = $upgrade_directories_not_found;
213                 return '';
214         }
215         $install_file           = "$base_upgrade_dir/patch/".basename(urldecode( $_SESSION['install_file'] ));
216         $file_action            = "";
217         $uh_status                      = "";
218         $errors                         = array();
219         $out                            = '';
220         $backupFilesExist       = false;
221         $rest_dir                       = remove_file_extension($install_file) . "-restore";
222
223         ///////////////////////////////////////////////////////////////////////////////
224         ////    MAKE BACKUPS OF TARGET FILES
225         if(!didThisStepRunBefore('commit','commitMakeBackupFiles')){
226                 set_upgrade_progress('commit','in_progress','commitMakeBackupFiles','in_progress');
227                 $errors = commitMakeBackupFiles($rest_dir, $install_file, $unzip_dir, $zip_from_dir, array());
228                 set_upgrade_progress('commit','in_progress','commitMakeBackupFiles','done');
229         }
230         ////    END MAKE BACKUPS OF TARGET FILES
231         ///////////////////////////////////////////////////////////////////////////////
232
233
234         ///////////////////////////////////////////////////////////////////////////////
235         ////    HANDLE PREINSTALL SCRIPTS
236         if(empty($errors)) {
237                 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
238                 if(is_file($file)) {
239                         $out .= "{$mod_strings['LBL_UW_INCLUDING']}: {$file} <br>\n";
240                         include($file);
241                         if(!didThisStepRunBefore('commit','pre_install')){
242                                 logThis('Running pre_install()...');
243                                 set_upgrade_progress('commit','in_progress','pre_install','in_progress');
244                                 pre_install();
245                                 set_upgrade_progress('commit','in_progress','pre_install','done');
246                                 logThis('pre_install() done.');
247                         }
248                 }
249         }
250
251         ////    HANDLE PREINSTALL SCRIPTS
252         ///////////////////////////////////////////////////////////////////////////////
253         //Clean smarty from cache
254             $cachedir = sugar_cached('smarty');
255             if(is_dir($cachedir)){
256                 $allModFiles = array();
257                 $allModFiles = findAllFiles($cachedir,$allModFiles);
258            foreach($allModFiles as $file){
259                         //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
260                         if(file_exists($file)){
261                                         unlink($file);
262                         }
263            }
264         }
265
266
267                 //Also add the three-way merge here. The idea is after the 451 html files have
268                 //been converted run the 3-way merge. If 500 then just run the 3-way merge
269         $ce_to_pro_ent = isset($manifest['name']) && ($manifest['name'] == 'SugarCE to SugarPro' || $manifest['name'] == 'SugarCE to SugarEnt' || $manifest['name'] == 'SugarCE to SugarCorp' || $manifest['name'] == 'SugarCE to SugarUlt');
270
271                 if(file_exists('modules/UpgradeWizard/SugarMerge/SugarMerge.php')){
272                     require_once('modules/UpgradeWizard/SugarMerge/SugarMerge.php');
273                     if(isset($_SESSION['unzip_dir']) && isset($_SESSION['zip_from_dir']) && !isset($_SESSION['sugarMergeRunResults'])){
274                         $merger = new SugarMerge($_SESSION['unzip_dir'].'/'.$_SESSION['zip_from_dir']);
275                         //Perform the actual merge and store which modules were merged.  We will rolllback the files if the
276                         //user determines that they did not want to upgade a particular module.
277                         $_SESSION['sugarMergeRunResults'] = $merger->mergeAll(TRUE,TRUE,TRUE);
278                         logThis('Commit step finished SugarMerge run with the following results:' . print_r($_SESSION['sugarMergeRunResults'], true));
279                     }
280                 }
281
282         //Bug #47110
283         if(file_exists("include/Expressions/Actions/SetValueAction.php")){
284             require_once("include/Expressions/Actions/SetValueAction.php");
285         }
286
287          //COPY ALL FILES FROM UPLOADED UPGRADE PACKAGE
288          if(!didThisStepRunBefore('commit','commitCopyNewFiles')){
289                                 set_upgrade_progress('commit','in_progress','commitCopyNewFiles','in_progress');
290                                 $split = commitCopyNewFiles($unzip_dir, $zip_from_dir);
291                                 $copiedFiles = $split['copiedFiles'];
292                                 $skippedFiles = $split['skippedFiles'];
293                                 set_upgrade_progress('commit','in_progress','commitCopyNewFiles','done');
294          }
295                  //END COPY NEW FILES INTO TARGET INSTANCE
296     ///////////////////////////////////////////////////////////////////////////////
297         ////    HANDLE POSTINSTALL SCRIPTS
298         logThis('Starting post_install()...');
299     if (!function_exists("inDeveloperMode")) {
300         //this function was introduced from tokyo in the file include/utils.php, so when upgrading from 5.1x and 5.2x we should declare the this function
301         function inDeveloperMode()
302         {
303             return isset($GLOBALS['sugar_config']['developerMode']) && $GLOBALS['sugar_config']['developerMode'];
304         }
305     }
306         if(empty($errors)) {
307                 if(!didThisStepRunBefore('commit','post_install')){
308                         $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
309                         if(is_file($file)) {
310                                 //set_upgrade_progress('commit','in_progress','post_install','in_progress');
311                                 $progArray['post_install']='in_progress';
312                                 post_install_progress($progArray,'set');
313                                 include($file);
314                                 post_install();
315                                 //set process to done
316                                 $progArray['post_install']='done';
317                                 //set_upgrade_progress('commit','in_progress','post_install','done');
318                                 post_install_progress($progArray,'set');
319                         }
320                 }
321
322            require("sugar_version.php");
323
324        if (version_compare($_SESSION['current_db_version'], $_SESSION['target_db_version'], '!='))
325        {
326                         logThis('Performing UWrebuild()...');
327                         UWrebuild();
328                         logThis('UWrebuild() done.');
329        }
330
331                 //set the logger before rebuilding config
332                 if(!isset($sugar_config['logger'])){
333                         $sugar_config['logger'] =array (
334                                 'level'=>'fatal',
335                             'file' =>
336                               array (
337                                       'ext' => '.log',
338                                       'name' => 'sugarcrm',
339                                       'dateFormat' => '%c',
340                                       'maxSize' => '10MB',
341                                       'maxLogs' => 10,
342                                       'suffix' => '', // bug51583, change default suffix to blank for backwards comptability
343                                   ),
344                         );
345                 }
346
347         // Set the default max tabs to 7
348         $sugar_config['default_max_tabs'] = '7';
349
350                 if(!rebuildConfigFile($sugar_config, $sugar_version)) {
351                         logThis('*** ERROR: could not write config.php! - upgrade will fail!');
352                         $errors[] = $mod_strings['ERR_UW_CONFIG_WRITE'];
353                 }
354         }
355         logThis('post_install() done.');
356         //// END POSTINSTALL SCRIPTS
357         ///////////////////////////////////////////////////////////////////////////////
358
359 logThis('check if current_db_version in $_SESSION equals target_db_version in $_SESSION');
360 if (version_compare($_SESSION['current_db_version'], $_SESSION['target_db_version'], '='))
361 {
362         logThis('current_db_version in $_SESSION and target_db_version in $_SESSION are equal');
363         $_SESSION['license_seats_needed'] = '';
364         //Clean modules from cache
365         $cachedir = sugar_cached("modules");
366     if(is_dir($cachedir)){
367                 logThis("clear $cachedir files");
368         $allModFiles = array();
369         $allModFiles = findAllFiles($cachedir,$allModFiles);
370        foreach($allModFiles as $file){
371                 //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
372                 if(file_exists($file))
373                 {
374                         logThis('unlink ' . $file);
375                                 unlink($file);
376                 }
377        }
378     }
379     //Clean jsLanguage from cache
380     $cachedir = sugar_cached("jsLanguage");
381     if(is_dir($cachedir)){
382                 logThis("clear $cachedir files");
383         $allModFiles = array();
384         $allModFiles = findAllFiles($cachedir,$allModFiles);
385        foreach($allModFiles as $file){
386                 //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
387                 if(file_exists($file))
388                 {
389                         logThis('unlink ' . $file);
390                                 unlink($file);
391                 }
392        }
393     }
394
395 }
396 logThis('finished check to see if current_db_version in $_SESSION equals target_db_version in $_SESSION');
397
398 //Look for chance folder and delete it if found. Bug 23595
399 if(function_exists('deleteChance'))
400 {
401         logThis('running deleteChance() function');
402         @deleteChance();
403 }
404
405 //also add the cache cleaning here.
406 if(function_exists('deleteCache'))
407 {
408         logThis('running deleteCache() function');
409         @deleteCache();
410 }
411
412 //add tabs
413 $from_dir = remove_file_extension($install_file) . "-restore";
414 logThis('call addNewSystemTabsFromUpgrade(' . $from_dir . ')');
415 addNewSystemTabsFromUpgrade($from_dir);
416 logThis('finished addNewSystemTabsFromUpgrade');
417
418 //run fix on dropdown lists that may have been incorrectly named
419 //fix_dropdown_list();
420
421         ///////////////////////////////////////////////////////////////////////////////
422         ////    REGISTER UPGRADE
423
424         logThis('Registering upgrade with UpgradeHistory');
425         if(!didThisStepRunBefore('commit','upgradeHistory')){
426                 set_upgrade_progress('commit','in_progress','upgradeHistory','in_progress');
427                 if(empty($errors)) {
428                         $file_action = "copied";
429                         // if error was encountered, script should have died before now
430                         $new_upgrade = new UpgradeHistory();
431                         $new_upgrade->filename = $install_file;
432                         $new_upgrade->md5sum = md5_file($install_file);
433                         $new_upgrade->type = 'patch';
434                         $new_upgrade->version = $sugar_version;
435                         $new_upgrade->status = "installed";
436                         $new_upgrade->manifest =(!empty($_SESSION['install_manifest']) ? $_SESSION['install_manifest'] : '');
437                         $new_upgrade->save();
438                 }
439                 set_upgrade_progress('commit','in_progress','upgradeHistory','done');
440         }
441         ////    REGISTER UPGRADE
442         ///////////////////////////////////////////////////////////////////////////////
443 }else{
444     $backupFilesExist = false;
445     $copiedFiles = array();
446     $skippedFiles = array();
447 }
448
449 // flag to prvent double-commits via refresh
450 $_SESSION['committed'] = true;
451
452 ///////////////////////////////////////////////////////////////////////////////
453 ////    FINISH AND OUTPUT
454 if(empty($errors)) {
455         $stop = false;
456 }
457
458 $backupDesc = '';
459 if($backupFilesExist) {
460         $backupDesc .= "<b>{$mod_strings['LBL_UW_BACKUP_FILES_EXIST_TITLE']}</b><br />";
461         $backupDesc .= $mod_strings['LBL_UW_BACKUP_FILES_EXIST'] . ': ' . $rest_dir;
462 }
463
464 $customized_mods_Desc = '';
465 $old_schema= '';
466 $old_schema_opt = '';
467 $skipped_queries = '';
468 if (version_compare($_SESSION['current_db_version'], $_SESSION['target_db_version'], '!='))
469 {
470     global $sugar_version;
471
472     $origVersion = implodeVersion($_SESSION['current_db_version']);
473     $destVersion = implodeVersion($_SESSION['target_db_version']);
474
475         //old schema to be dropped
476         $old_schema_contents = '';
477         if(file_exists($_SESSION['unzip_dir'].'/scripts/drop_'.$origVersion.'_schema_after_upgrade_'.$destVersion.'.php')){
478                 require_once($_SESSION['unzip_dir'].'/scripts/drop_'.$origVersion.'_schema_after_upgrade_'.$destVersion.'.php');
479                 ob_start();
480                         $old_schema_contents=@drop_preUpgardeSchema(true);
481                 ob_end_clean();
482         }
483         if($old_schema_contents != null && strlen($old_schema_contents) >0){
484                 $old_schema  = "<p><a href='javascript:void(0); toggleNwFiles(\"old_schemashow\");'>{$mod_strings['LBL_UW_SHOW_OLD_SCHEMA_TO_DROP']}</a>";
485                 $old_schema .= "<div id='old_schemashow' style='display:none;'>";
486                 $old_schema .= "<textarea readonly cols='80' rows='10'>{$old_schema_contents}</textarea>";
487                 $old_schema .= "</div></p>";
488
489                 $old_schema_opt="<b>{$mod_strings['LBL_UW_DROP_SCHEMA_METHOD']}</b>
490                                                 <select name=\"schema_drop\" id=\"select_schema_drop\" onchange=\"checkSchemaDropStatus();\">
491                                                         <option value=\"manual\">{$mod_strings['LBL_UW_DROP_SCHEMA_MANUAL']}</option>
492                                                         <option value=\"sugar\">{$mod_strings['LBL_UW_DROP_SCHEMA_UPGRADE_WIZARD']}</option>
493                                                 </select>
494                                         ";
495         }
496
497         //also add the cache cleaning here.
498         if(function_exists('deleteCache')){
499                 @deleteCache();
500         }
501 }
502
503 $copiedDesc = '';
504 if(count($copiedFiles) > 0) {
505         $copiedDesc .= "<b>{$mod_strings['LBL_UW_COPIED_FILES_TITLE']}</b><br />";
506         $copiedDesc .= "<a href='javascript:void(0); toggleNwFiles(\"copiedFiles\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
507         $copiedDesc .= "<div id='copiedFiles' style='display:none;'>";
508
509         foreach($copiedFiles as $file) {
510                 $copiedDesc .= $file . "<br />";
511         }
512         $copiedDesc .= "</div>";
513 }
514
515 $skippedDesc = '';
516 if(count($skippedFiles) > 0) {
517         $skippedDesc .= "<b>{$mod_strings['LBL_UW_SKIPPED_FILES_TITLE']}</b><br />";
518         $skippedDesc .= "<a href='javascript:void(0); toggleNwFiles(\"skippedFiles\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
519         $skippedDesc .= "<div id='skippedFiles' style='display:none;'>";
520
521         foreach($skippedFiles as $file) {
522                 $skippedDesc .= $file . "<br />";
523         }
524         $skippedDesc .= "</div>";
525 }
526
527 $rebuildResult = "<b>{$mod_strings['LBL_UW_REBUILD_TITLE']}</b><br />";
528 $rebuildResult .= "<a href='javascript:void(0); toggleRebuild();'>{$mod_strings['LBL_UW_SHOW']}</a> <div id='rebuildResult'></div>";
529
530 $rebuildResult = '';
531
532 $skipped_queries_Desc='';
533 if(isset($_SESSION['sqlSkippedQueries']) && $_SESSION['sqlSkippedQueries'] != null && is_array($_SESSION['sqlSkippedQueries']) && sizeof($_SESSION['sqlSkippedQueries'])>0){
534         $skipped_queries_Desc .= "<b>{$mod_strings['LBL_UW_SKIPPED_QUERIES_ALREADY_EXIST']}</b><br />";
535         $skipped_queries_Desc .= "<a href='javascript:void(0); toggleNwFiles(\"skippedQueries\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
536         $skipped_queries_Desc .= "<div id='skippedQueries' style='display:none;'>";
537         if($_SESSION['sqlSkippedQueries'] != null){
538              $skipped_queries_Desc .= $mod_strings['LBL_UW_SKIPPED_QUERIES_ALREADY_EXIST']. "<br />";
539              foreach($_SESSION['sqlSkippedQueries'] as $skippedQ) {
540                         $skipped_queries_Desc .= $skippedQ . "<br />";
541                  }
542         }
543  }
544 $delete_chance='';
545 if(isset($_SESSION['chance']) && $_SESSION['chance'] != null){
546         $delete_chance .= "<b>Remove the folder: {$_SESSION['chance']}</b><br />";
547  }
548 if(empty($mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'])){
549                 $mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'] = 'Upgrade may take some time';
550 }
551
552 ///////////////////////////////////////////////////////////////////////////////
553 ////    HANDLE REMINDERS
554 commitHandleReminders($skippedFiles);
555 ////    HANDLE REMINDERS
556 ///////////////////////////////////////////////////////////////////////////////
557
558
559 logThis("Resetting error_reporting() to system level.");
560 error_reporting($standardErrorLevel);
561
562 ///////////////////////////////////////////////////////////////////////////////
563 ////    OUTPUT
564 $uwMain =<<<eoq
565 <script type="text/javascript" language="javascript">
566         function toggleRebuild() {
567                 var target = document.getElementById('rebuildResult');
568
569                 if(target.innerHTML == '') {
570                         target.innerHTML = rebuildResult; // found in UWrebuild()
571                 } else {
572                         target.innerHTML = '';
573                 }
574         }
575 </script>
576 <table cellpadding="3" cellspacing="0" border="0">
577         <tr>
578                 <td>
579                         &nbsp;
580                 </td>
581         </tr>
582         <tr>
583                 <td align="left">
584                         <p>
585                         {$delete_chance}
586                         </p>
587                         <p>
588                         {$backupDesc}
589                         </p>
590                         <p>
591                         {$customized_mods_Desc}
592                         </p>
593                         <p>
594                         {$copiedDesc}
595                         </p>
596                         <p>
597                         {$skippedDesc}
598                         </p>
599                         <p>
600                         {$skipped_queries_Desc}
601                         </p>
602                         <p>
603                         {$rebuildResult}
604                         </p>
605                 </td>
606         </tr>
607         <tr><td>
608                 <p>
609                 {$old_schema}
610                 </p>
611         </td></tr>
612         <tr><td>
613                 {$old_schema_opt}
614         </td></tr>
615 </table>
616 <div id="upgradeDiv" style="display:none">
617     <table cellspacing="0" cellpadding="0" border="0">
618         <tr><td>
619            <p><!--not_in_theme!--><img src='modules/UpgradeWizard/processing.gif' alt='Processing'> <br></p>
620         </td></tr>
621      </table>
622  </div>
623  <script>
624 function checkSchemaDropStatus() {
625         if(document.getElementById('select_schema_drop') != null){
626                 var schemaSelect = document.getElementById('select_schema_drop');
627                 var schemaDropMethod = document.getElementById('schema_drop');
628                 if(schemaSelect.options[schemaSelect.selectedIndex].value == 'manual') {
629                         schemaDropMethod.value = 'manual';
630                 } else {
631                         schemaDropMethod.value = 'sugar';
632                 }
633    }
634 }
635  checkSchemaDropStatus();
636  </script>
637 eoq;
638
639 //set the upgrade progress status.
640 set_upgrade_progress('commit','done','commit','done');
641 $showBack = false;
642 $showCancel = false;
643 $showRecheck = false;
644 $showNext =($stop) ? false : true;
645
646 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_UW_COMMIT_DESC']}</b>";
647 $stepBack = $_REQUEST['step'] - 1;
648 //Skip ahead to the end page as no layouts need to be merged.
649 $skipLayouts = true;
650 foreach($_SESSION['sugarMergeRunResults'] as $mergeModule => $mergeModuleFileList){
651     if(!empty($mergeModuleFileList)){
652         $skipLayouts = false;
653     }
654 }
655 $stepNext = $skipLayouts ? $_REQUEST['step'] + 2 : $_REQUEST['step'] + 1;
656 $stepCancel = -1;
657 $stepRecheck = $_REQUEST['step'];
658
659 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] =($stop) ? 'failed' : 'success';
660
661 // clear out the theme cache
662 if(!class_exists('SugarThemeRegistry')){
663     require_once('include/SugarTheme/SugarTheme.php');
664 }
665
666 $themeObject = SugarThemeRegistry::current();
667
668 $styleJSFilePath = sugar_cached($themeObject->getJSPath() . DIRECTORY_SEPARATOR .  'style-min.js');
669 if( file_exists($styleJSFilePath) )
670 {
671     logThis("Rebuilding style js file: $styleJSFilePath");
672     unlink($styleJSFilePath);
673     SugarThemeRegistry::current()->clearJSCache();
674     SugarThemeRegistry::current()->getJS();
675 }
676 SugarThemeRegistry::buildRegistry();
677 SugarThemeRegistry::clearAllCaches();
678
679
680 //Clean out the language files
681 logThis("Rebuilding language cache");
682 sugar_cache_reset_full();
683 LanguageManager::clearLanguageCache();
684
685 //pause tracking again so as to not call newly copied tracker code which may contain calls to new methods not currently loaded
686 $trackerManager = TrackerManager::getInstance();
687 $trackerManager->pause();
688 $trackerManager->unsetMonitors();
689
690 // re-minify the JS source files
691 $_REQUEST['root_directory'] = getcwd();
692 $_REQUEST['js_rebuild_concat'] = 'rebuild';
693 require_once('jssource/minify.php');
694
695 //The buld registry call above will reload the default theme for what was written to the config file during flav conversions
696 //which we don't want to happen until after this request as we have already started rendering with a specific theme.
697 $themeName = (string) $themeObject;
698 if($themeName != $GLOBALS['sugar_config']['default_theme'])
699     SugarThemeRegistry::set($themeName);
700
701