]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/commit.php
Release 6.1.4
[Github/sugarcrm.git] / modules / UpgradeWizard / commit.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry)
3         die('Not A Valid Entry Point');
4 /*********************************************************************************
5  * SugarCRM is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 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');
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                 $base_upgrade_dir               = $sugar_config['upload_dir'] . "/upgrades";
103                 $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";
104                 $unzip_dir = '';
105                 //also come up with mechanism to read from upgrade-progress file
106                 if(!isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !is_file($_SESSION['install_file'])) {
107                         if (file_exists(clean_path($base_tmp_upgrade_dir)) && $handle = opendir(clean_path($base_tmp_upgrade_dir))) {
108                                 while (false !== ($file = readdir($handle))) {
109                                 if($file !="." && $file !="..") {
110                                          //echo $base_tmp_upgrade_dir."/".$file.'</br>';
111                                          if(is_file($base_tmp_upgrade_dir."/".$file."/manifest.php")){
112                                                 require_once($base_tmp_upgrade_dir."/".$file."/manifest.php");
113                                                 $package_name= $manifest['copy_files']['from_dir'];
114                                                 //echo file_exists($base_tmp_upgrade_dir."/".$file."/".$package_name).'</br>';
115                                                 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")){
116                                                         //echo 'Yeah this the directory '. $base_tmp_upgrade_dir."/".$file;
117                                                         $unzip_dir = $base_tmp_upgrade_dir."/".$file;
118                                                         if(file_exists($sugar_config['upload_dir'].'/upgrades/patch/'.$package_name.'.zip')){
119                                                                 $_SESSION['install_file'] = $sugar_config['upload_dir'].'/upgrades/patch/'.$package_name.'.zip';
120                                                                 break;
121                                                         }
122                                                 }
123                                           }
124                                 }
125                         }
126                         }
127                 }
128         if(!isset($_SESSION['install_file']) || empty($_SESSION['install_file'])){
129                 unlinkTempFiles();
130                 resetUwSession();
131                 echo 'Upload File not found so redirecting to Upgrade Start ';
132                 $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
133                 echo '<form name="redirect" action="' .$redirect_new_wizard. '"  method="POST">';
134 $upgrade_directories_not_found =<<<eoq
135         <table cellpadding="3" cellspacing="0" border="0">
136                 <tr>
137                         <th colspan="2" align="left">
138                                 <span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
139                         </th>
140                 </tr>
141         </table>
142 eoq;
143 $uwMain = $upgrade_directories_not_found;
144                                 return '';
145         }
146                 $install_file                   = urldecode( $_SESSION['install_file'] );
147                 $show_files                             = true;
148                 if(empty($unzip_dir)){
149                         $unzip_dir                              = mk_temp_dir( $base_tmp_upgrade_dir );
150                 }
151                 $zip_from_dir                   = ".";
152                 $zip_to_dir                             = ".";
153                 $zip_force_copy                 = array();
154
155                 if(!$unzip_dir){
156                         logThis('Could not create a temporary directory using mk_temp_dir( $base_tmp_upgrade_dir )');
157                         die($mod_strings['ERR_UW_NO_CREATE_TMP_DIR']);
158                 }
159
160                 //double check whether unzipped .
161                 if(file_exists($unzip_dir ."/scripts") && file_exists($unzip_dir."/manifest.php")){
162                 //already unzipped
163                 }
164                 else{
165                         unzip( $install_file, $unzip_dir );
166                 }
167
168                 // assumption -- already validated manifest.php at time of upload
169                 require_once( "$unzip_dir/manifest.php" );
170
171                 if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){
172                     $zip_from_dir   = $manifest['copy_files']['from_dir'];
173                 }
174                 if( isset( $manifest['copy_files']['to_dir'] ) && $manifest['copy_files']['to_dir'] != "" ){
175                     $zip_to_dir     = $manifest['copy_files']['to_dir'];
176                 }
177                 if( isset( $manifest['copy_files']['force_copy'] ) && $manifest['copy_files']['force_copy'] != "" ){
178                     $zip_force_copy     = $manifest['copy_files']['force_copy'];
179                 }
180                 if( isset( $manifest['version'] ) ){
181                     $version    = $manifest['version'];
182                 }
183                 if( !is_writable( "config.php" ) ){
184                         return $mod_strings['ERR_UW_CONFIG'];
185                 }
186
187                 $_SESSION['unzip_dir'] = clean_path($unzip_dir);
188                 $_SESSION['zip_from_dir'] = clean_path($zip_from_dir);
189                 logThis('unzip done.');
190         } else {
191                 $unzip_dir = $_SESSION['unzip_dir'];
192                 $zip_from_dir = $_SESSION['zip_from_dir'];
193         }
194
195     //check if $_SESSION['unzip_dir'] and $_SESSION['zip_from_dir'] exist
196         if(!isset($_SESSION['unzip_dir']) || !file_exists($_SESSION['unzip_dir'])
197                 || !isset($_SESSION['install_file']) || empty($_SESSION['install_file']) || !file_exists($_SESSION['install_file'])){
198                     //redirect to start
199             unlinkTempFiles();
200                 resetUwSession();
201                 echo 'Upload File not found so redirecting to Upgrade Start ';
202                 $redirect_new_wizard = $sugar_config['site_url' ].'/index.php?module=UpgradeWizard&action=index';
203                 echo '<form name="redirect" action="' .$redirect_new_wizard. '"  method="POST">';
204 $upgrade_directories_not_found =<<<eoq
205         <table cellpadding="3" cellspacing="0" border="0">
206                 <tr>
207                         <th colspan="2" align="left">
208                                 <span class='error'><b>'Upload file missing or has been deleted. Refresh the page to go back to UpgradeWizard start'</b></span>
209                         </th>
210                 </tr>
211         </table>
212 eoq;
213 $uwMain = $upgrade_directories_not_found;
214                                 return '';
215         }
216         $install_file           = urldecode($_SESSION['install_file']);
217         $file_action            = "";
218         $uh_status                      = "";
219         $errors                         = array();
220         $out                            = '';
221         $backupFilesExist       = false;
222         $rest_dir                       = clean_path(remove_file_extension($install_file) . "-restore");
223
224         ///////////////////////////////////////////////////////////////////////////////
225         ////    MAKE BACKUPS OF TARGET FILES
226         if(!didThisStepRunBefore('commit','commitMakeBackupFiles')){
227                 set_upgrade_progress('commit','in_progress','commitMakeBackupFiles','in_progress');
228                 $errors = commitMakeBackupFiles($rest_dir, $install_file, $unzip_dir, $zip_from_dir, array());
229                 set_upgrade_progress('commit','in_progress','commitMakeBackupFiles','done');
230         }
231         ////    END MAKE BACKUPS OF TARGET FILES
232         ///////////////////////////////////////////////////////////////////////////////
233
234
235         ///////////////////////////////////////////////////////////////////////////////
236         ////    HANDLE PREINSTALL SCRIPTS
237         if(empty($errors)) {
238                 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
239                 if(is_file($file)) {
240                         $out .= "{$mod_strings['LBL_UW_INCLUDING']}: {$file} <br>\n";
241                         include($file);
242                         if(!didThisStepRunBefore('commit','pre_install')){
243                                 logThis('Running pre_install()...');
244                                 set_upgrade_progress('commit','in_progress','pre_install','in_progress');
245                                 pre_install();
246                                 set_upgrade_progress('commit','in_progress','pre_install','done');
247                                 logThis('pre_install() done.');
248                         }
249                 }
250         }
251
252         ////    HANDLE PREINSTALL SCRIPTS
253         ///////////////////////////////////////////////////////////////////////////////
254         //Clean smarty from cache
255         if(is_dir($GLOBALS['sugar_config']['cache_dir'].'smarty')){
256                 $allModFiles = array();
257                 $allModFiles = findAllFiles($GLOBALS['sugar_config']['cache_dir'].'smarty',$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');
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          //COPY ALL FILES FROM UPLOADED UPGRADE PACKAGE
283
284          if(!didThisStepRunBefore('commit','commitCopyNewFiles')){
285                                 set_upgrade_progress('commit','in_progress','commitCopyNewFiles','in_progress');
286                                 $split = commitCopyNewFiles($unzip_dir, $zip_from_dir);
287                                 $copiedFiles = $split['copiedFiles'];
288                                 $skippedFiles = $split['skippedFiles'];
289                                 set_upgrade_progress('commit','in_progress','commitCopyNewFiles','done');
290          }
291                  //END COPY NEW FILES INTO TARGET INSTANCE
292     ///////////////////////////////////////////////////////////////////////////////
293         ////    HANDLE POSTINSTALL SCRIPTS
294         logThis('Starting post_install()...');
295     if (!function_exists("inDeveloperMode")) {
296         //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
297         function inDeveloperMode()
298         {
299             return isset($GLOBALS['sugar_config']['developerMode']) && $GLOBALS['sugar_config']['developerMode'];
300         }
301     }
302         if(empty($errors)) {
303                 if(!didThisStepRunBefore('commit','post_install')){
304                         $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
305                         if(is_file($file)) {
306                                 //set_upgrade_progress('commit','in_progress','post_install','in_progress');
307                                 $progArray['post_install']='in_progress';
308                                 post_install_progress($progArray,'set');
309                                 include($file);
310                                 post_install();
311                                 //set process to done
312                                 $progArray['post_install']='done';
313                                 //set_upgrade_progress('commit','in_progress','post_install','done');
314                                 post_install_progress($progArray,'set');
315                         }
316                 }
317
318            require("sugar_version.php");
319
320        if($_SESSION['current_db_version'] != $_SESSION['target_db_version']){
321                         logThis('Performing UWrebuild()...');
322                         UWrebuild();
323
324                     global $sugar_version;
325                     $origVersion = substr(preg_replace("/[^0-9]/", "", $_SESSION['current_db_version']),0,3);
326
327                     if($origVersion < '600') {
328                                 _logThis('Check to hide iFrames and Feeds modules', $path);
329                                 hide_iframes_and_feeds_modules();
330                         }
331                         logThis('UWrebuild() done.');
332        }
333
334                 //set the logger before rebuilding config
335                 if(!isset($sugar_config['logger'])){
336                         $sugar_config['logger'] =array (
337                                 'level'=>'fatal',
338                             'file' =>
339                               array (
340                                       'ext' => '.log',
341                                       'name' => 'sugarcrm',
342                                       'dateFormat' => '%c',
343                                       'maxSize' => '10MB',
344                                       'maxLogs' => 10,
345                                       'suffix' => '%m_%Y',
346                                   ),
347                         );
348                 }
349
350         // Set the default max tabs to 7
351         $sugar_config['default_max_tabs'] = '7';
352
353                 if(!rebuildConfigFile($sugar_config, $sugar_version)) {
354                         logThis('*** ERROR: could not write config.php! - upgrade will fail!');
355                         $errors[] = $mod_strings['ERR_UW_CONFIG_WRITE'];
356                 }
357         }
358         logThis('post_install() done.');
359         //// END POSTINSTALL SCRIPTS
360         ///////////////////////////////////////////////////////////////////////////////
361 if($_SESSION['current_db_version'] == $_SESSION['target_db_version']){
362
363         $_SESSION['license_seats_needed'] = '';
364         //Clean modules from cache
365     if(is_dir($GLOBALS['sugar_config']['cache_dir'].'modules')){
366         $allModFiles = array();
367         $allModFiles = findAllFiles($GLOBALS['sugar_config']['cache_dir'].'modules',$allModFiles);
368        foreach($allModFiles as $file){
369                 //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
370                 if(file_exists($file)){
371                                 unlink($file);
372                 }
373        }
374     }
375     //Clean jsLanguage from cache
376     if(is_dir($GLOBALS['sugar_config']['cache_dir'].'jsLanguage')){
377         $allModFiles = array();
378         $allModFiles = findAllFiles($GLOBALS['sugar_config']['cache_dir'].'jsLanguage',$allModFiles);
379        foreach($allModFiles as $file){
380                 //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
381                 if(file_exists($file)){
382                                 unlink($file);
383                 }
384        }
385     }
386 }
387 //cleanup cache modules
388 if(substr($sugar_version,0,1) == 5){
389                 //Clean modules from cache
390     if(is_dir($GLOBALS['sugar_config']['cache_dir'].'modules')){
391         $allModFiles = array();
392         $allModFiles = findAllFiles($GLOBALS['sugar_config']['cache_dir'].'modules',$allModFiles);
393        foreach($allModFiles as $file){
394                 //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
395                 if(file_exists($file)){
396                                 unlink($file);
397                 }
398        }
399     }
400 }
401 //Look for chance folder and delete it if found. Bug 23595
402 if(function_exists('deleteChance')){
403         @deleteChance();
404 }
405
406 //also add the cache cleaning here.
407 if(function_exists('deleteCache')){
408         @deleteCache();
409 }
410 //add tabs
411 $from_dir = clean_path(remove_file_extension($install_file) . "-restore");
412 addNewSystemTabsFromUpgrade($from_dir);
413
414 //run fix on dropdown lists that may have been incorrectly named
415 //fix_dropdown_list();
416
417         ///////////////////////////////////////////////////////////////////////////////
418         ////    REGISTER UPGRADE
419
420         logThis('Registering upgrade with UpgradeHistory');
421         if(!didThisStepRunBefore('commit','upgradeHistory')){
422                 set_upgrade_progress('commit','in_progress','upgradeHistory','in_progress');
423                 if(empty($errors)) {
424                         $file_action = "copied";
425                         // if error was encountered, script should have died before now
426                         $new_upgrade = new UpgradeHistory();
427                         $new_upgrade->filename = $install_file;
428                         $new_upgrade->md5sum = md5_file($install_file);
429                         $new_upgrade->type = 'patch';
430                         $new_upgrade->version = $sugar_version;
431                         $new_upgrade->status = "installed";
432                         $new_upgrade->manifest =(!empty($_SESSION['install_manifest']) ? $_SESSION['install_manifest'] : '');
433                         $new_upgrade->save();
434                 }
435                 set_upgrade_progress('commit','in_progress','upgradeHistory','done');
436         }
437         ////    REGISTER UPGRADE
438         ///////////////////////////////////////////////////////////////////////////////
439 }else{
440     $backupFilesExist = false;
441     $copiedFiles = array();
442     $skippedFiles = array();
443 }
444
445 // flag to prvent double-commits via refresh
446 $_SESSION['committed'] = true;
447
448 ///////////////////////////////////////////////////////////////////////////////
449 ////    FINISH AND OUTPUT
450 if(empty($errors)) {
451         $stop = false;
452 }
453
454 $backupDesc = '';
455 if($backupFilesExist) {
456         $backupDesc .= "<b>{$mod_strings['LBL_UW_BACKUP_FILES_EXIST_TITLE']}</b><br />";
457         $backupDesc .= $mod_strings['LBL_UW_BACKUP_FILES_EXIST'] . ': ' . $rest_dir;
458 }
459
460 $customized_mods_Desc = '';
461 $old_schema= '';
462 $old_schema_opt = '';
463 $skipped_queries = '';
464 if($_SESSION['current_db_version'] != $_SESSION['target_db_version']){
465     global $sugar_version;
466     $origVersion = substr(preg_replace("/[^0-9]/", "", $_SESSION['current_db_version']),0,3);
467         $destVersion = substr(preg_replace("/[^0-9]/", "", $_SESSION['target_db_version']),0,3);
468
469         //old schema to be dropped
470         $old_schema_contents = '';
471         if(file_exists($_SESSION['unzip_dir'].'/scripts/drop_'.$origVersion.'_schema_after_upgrade_'.$destVersion.'.php')){
472                 require_once($_SESSION['unzip_dir'].'/scripts/drop_'.$origVersion.'_schema_after_upgrade_'.$destVersion.'.php');
473                 ob_start();
474                         $old_schema_contents=@drop_preUpgardeSchema(true);
475                 ob_end_clean();
476         }
477         if($old_schema_contents != null && strlen($old_schema_contents) >0){
478                 $old_schema  = "<p><a href='javascript:void(0); toggleNwFiles(\"old_schemashow\");'>{$mod_strings['LBL_UW_SHOW_OLD_SCHEMA_TO_DROP']}</a>";
479                 $old_schema .= "<div id='old_schemashow' style='display:none;'>";
480                 $old_schema .= "<textarea readonly cols='80' rows='10'>{$old_schema_contents}</textarea>";
481                 $old_schema .= "</div></p>";
482
483                 $old_schema_opt="<b>{$mod_strings['LBL_UW_DROP_SCHEMA_METHOD']}</b>
484                                                 <select name=\"schema_drop\" id=\"select_schema_drop\" onchange=\"checkSchemaDropStatus();\">
485                                                         <option value=\"manual\">{$mod_strings['LBL_UW_DROP_SCHEMA_MANUAL']}</option>
486                                                         <option value=\"sugar\">{$mod_strings['LBL_UW_DROP_SCHEMA_UPGRADE_WIZARD']}</option>
487                                                 </select>
488                                         ";
489         }
490
491         //also add the cache cleaning here.
492         if(function_exists('deleteCache')){
493                 @deleteCache();
494         }
495 }
496
497 $copiedDesc = '';
498 if(count($copiedFiles) > 0) {
499         $copiedDesc .= "<b>{$mod_strings['LBL_UW_COPIED_FILES_TITLE']}</b><br />";
500         $copiedDesc .= "<a href='javascript:void(0); toggleNwFiles(\"copiedFiles\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
501         $copiedDesc .= "<div id='copiedFiles' style='display:none;'>";
502
503         foreach($copiedFiles as $file) {
504                 $copiedDesc .= $file . "<br />";
505         }
506         $copiedDesc .= "</div>";
507 }
508
509 $skippedDesc = '';
510 if(count($skippedFiles) > 0) {
511         $skippedDesc .= "<b>{$mod_strings['LBL_UW_SKIPPED_FILES_TITLE']}</b><br />";
512         $skippedDesc .= "<a href='javascript:void(0); toggleNwFiles(\"skippedFiles\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
513         $skippedDesc .= "<div id='skippedFiles' style='display:none;'>";
514
515         foreach($skippedFiles as $file) {
516                 $skippedDesc .= $file . "<br />";
517         }
518         $skippedDesc .= "</div>";
519 }
520
521 $rebuildResult = "<b>{$mod_strings['LBL_UW_REBUILD_TITLE']}</b><br />";
522 $rebuildResult .= "<a href='javascript:void(0); toggleRebuild();'>{$mod_strings['LBL_UW_SHOW']}</a> <div id='rebuildResult'></div>";
523
524 $rebuildResult = '';
525
526 //moving unlink files to last
527 //unlinkTempFiles();
528
529
530 $skipped_queries_Desc='';
531 if(isset($_SESSION['sqlSkippedQueries']) && $_SESSION['sqlSkippedQueries'] != null && is_array($_SESSION['sqlSkippedQueries']) && sizeof($_SESSION['sqlSkippedQueries'])>0){
532         $skipped_queries_Desc .= "<b>{$mod_strings['LBL_UW_SKIPPED_QUERIES_ALREADY_EXIST']}</b><br />";
533         $skipped_queries_Desc .= "<a href='javascript:void(0); toggleNwFiles(\"skippedQueries\");'>{$mod_strings['LBL_UW_SHOW']}</a>";
534         $skipped_queries_Desc .= "<div id='skippedQueries' style='display:none;'>";
535         if($_SESSION['sqlSkippedQueries'] != null){
536              $skipped_queries_Desc .= $mod_strings['LBL_UW_SKIPPED_QUERIES_ALREADY_EXIST']. "<br />";
537              foreach($_SESSION['sqlSkippedQueries'] as $skippedQ) {
538                         $skipped_queries_Desc .= $skippedQ . "<br />";
539                  }
540         }
541  }
542 $delete_chance='';
543 if(isset($_SESSION['chance']) && $_SESSION['chance'] != null){
544         $delete_chance .= "<b>Remove the folder: {$_SESSION['chance']}</b><br />";
545  }
546 if(empty($mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'])){
547                 $mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'] = 'Upgrade may take some time';
548 }
549
550 ///////////////////////////////////////////////////////////////////////////////
551 ////    HANDLE REMINDERS
552 commitHandleReminders($skippedFiles);
553 ////    HANDLE REMINDERS
554 ///////////////////////////////////////////////////////////////////////////////
555
556
557 logThis("Resetting error_reporting() to system level.");
558 error_reporting($standardErrorLevel);
559
560 ///////////////////////////////////////////////////////////////////////////////
561 ////    OUTPUT
562 $uwMain =<<<eoq
563 <script type="text/javascript" language="javascript">
564         function toggleRebuild() {
565                 var target = document.getElementById('rebuildResult');
566
567                 if(target.innerHTML == '') {
568                         target.innerHTML = rebuildResult; // found in UWrebuild()
569                 } else {
570                         target.innerHTML = '';
571                 }
572         }
573 </script>
574 <table cellpadding="3" cellspacing="0" border="0">
575         <tr>
576                 <td>
577                         &nbsp;
578                 </td>
579         </tr>
580         <tr>
581                 <td align="left">
582                         <p>
583                         {$delete_chance}
584                         </p>
585                         <p>
586                         {$backupDesc}
587                         </p>
588                         <p>
589                         {$customized_mods_Desc}
590                         </p>
591                         <p>
592                         {$copiedDesc}
593                         </p>
594                         <p>
595                         {$skippedDesc}
596                         </p>
597                         <p>
598                         {$skipped_queries_Desc}
599                         </p>
600                         <p>
601                         {$rebuildResult}
602                         </p>
603                 </td>
604         </tr>
605         <tr><td>
606                 <p>
607                 {$old_schema}
608                 </p>
609         </td></tr>
610         <tr><td>
611                 {$old_schema_opt}
612         </td></tr>
613 </table>
614 <div id="upgradeDiv" style="display:none">
615     <table cellspacing="0" cellpadding="0" border="0">
616         <tr><td>
617            <p><img src='modules/UpgradeWizard/processing.gif'> <br></p>
618         </td></tr>
619      </table>
620  </div>
621  <script>
622 function checkSchemaDropStatus() {
623         if(document.getElementById('select_schema_drop') != null){
624                 var schemaSelect = document.getElementById('select_schema_drop');
625                 var schemaDropMethod = document.getElementById('schema_drop');
626                 if(schemaSelect.options[schemaSelect.selectedIndex].value == 'manual') {
627                         schemaDropMethod.value = 'manual';
628                 } else {
629                         schemaDropMethod.value = 'sugar';
630                 }
631    }
632 }
633  checkSchemaDropStatus();
634  </script>
635 eoq;
636
637 //set the upgrade progress status.
638 set_upgrade_progress('commit','done','commit','done');
639 $showBack = false;
640 $showCancel = false;
641 $showRecheck = false;
642 $showNext =($stop) ? false : true;
643
644 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_UW_COMMIT_DESC']}</b>";
645 $stepBack = $_REQUEST['step'] - 1;
646 //Skip ahead to the end page as no layouts need to be merged.
647 $skipLayouts = true;
648 foreach($_SESSION['sugarMergeRunResults'] as $mergeModule => $mergeModuleFileList){
649     if(!empty($mergeModuleFileList)){
650         $skipLayouts = false;
651     }
652 }
653 $stepNext = $skipLayouts ? $_REQUEST['step'] + 2 : $_REQUEST['step'] + 1; 
654 $stepCancel = -1;
655 $stepRecheck = $_REQUEST['step'];
656
657 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] =($stop) ? 'failed' : 'success';
658
659 // clear out the theme cache
660 // clear out the theme cache
661 if(!class_exists('SugarThemeRegistry')){
662     require_once('include/SugarTheme/SugarTheme.php');
663 }
664 SugarThemeRegistry::buildRegistry();
665 SugarThemeRegistry::clearAllCaches();
666
667 // re-minify the JS source files
668 $_REQUEST['root_directory'] = getcwd();
669 $_REQUEST['js_rebuild_concat'] = 'rebuild';
670 require_once('jssource/minify.php');