]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/preflight.php
Release 6.2.0
[Github/sugarcrm.git] / modules / UpgradeWizard / preflight.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
42  * Reserved. Contributor(s): ______________________________________..
43  * *******************************************************************************/
44
45 // LEGACY for old versions - emulating upload.php
46 // aw: make this better for later versions.
47 //refreshing mod_strings
48 global $mod_strings;
49
50 $curr_lang = 'en_us';
51 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null)){
52     $curr_lang = $GLOBALS['current_language'];
53 }
54 $mod_strings = return_module_language($curr_lang, 'UpgradeWizard',true);
55
56 function check_php($sys_php_version = '')
57 {
58     $min_considered_php_version = '5.2.1';
59
60     $supported_php_versions = array (
61     '5.2.1', '5.2.2', '5.2.3', '5.2.4', '5.2.5', '5.2.6', '5.2.8', '5.3.0'
62     );
63     //Find out what Database the system is using.
64     global $sugar_config;
65     $dbType = '';
66     if (isset ($sugar_config['dbconfig']) && isset ($sugar_config['dbconfig']['db_type'])) {
67         $dbType = $sugar_config['dbconfig']['db_type'];
68     }
69
70     // invalid versions above the $min_considered_php_version,
71     // should be mutually exclusive with $supported_php_versions
72
73     // SugarCRM prohibits install on PHP 5.2.x on all platforms
74     $invalid_php_versions = array('5.2.7');
75
76     // default unsupported
77     $retval = 0;
78
79     // versions below $min_considered_php_version are invalid
80     if(1 == version_compare($sys_php_version, $min_considered_php_version, '<')) {
81         $retval = -1;
82     }
83
84     // supported version check overrides default unsupported
85     foreach($supported_php_versions as $ver) {
86         if(1 == version_compare($sys_php_version, $ver, 'eq') || strpos($sys_php_version,$ver) !== false) {
87             $retval = 1;
88             break;
89         }
90     }
91
92     // invalid version check overrides default unsupported
93     foreach($invalid_php_versions as $ver) {
94         if(1 == version_compare($sys_php_version, $ver, 'eq') || strpos($sys_php_version,$ver) !== false) {
95             $retval = -1;
96             break;
97         }
98     }
99
100     //allow a redhat distro to install, regardless of version.  We are assuming the redhat naming convention is followed
101     //and the php version contains 'rh' characters
102     if(strpos($sys_php_version, 'rh') !== false) {
103         $retval = 1;
104     }
105
106     return $retval;
107 }
108
109
110
111 $curr_lang = 'en_us';
112 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null)){
113         $curr_lang = $GLOBALS['current_language'];
114 }
115 return_module_language($curr_lang, 'UpgradeWizard');
116
117 logThis('at preflight.php');
118 //set the upgrade progress status.
119 set_upgrade_progress('preflight','in_progress');
120 $php_warnings = '';
121 if (version_compare(phpversion(),'5.2.0') >=0) {
122         $stop = true; // flag to show "next"
123         if(isset($_SESSION['files'])) {
124                 unset($_SESSION['files']);
125         }
126
127         $errors = preflightCheck();
128
129         $php_version = constant('PHP_VERSION');
130     if(check_php($php_version) == -1)
131     {
132         $phpVersion = "<b><span class=stop>{$mod_strings['ERR_CHECKSYS_PHP_INVALID_VER']} {$php_version} </span></b>";
133         $error_txt = '<span class="error">'.$phpVersion.'</span>';
134         if(count($errors) == 0)
135         $errors[] = '';
136         $errors[] = $error_txt;
137         logThis($error_txt);
138     }
139         $diffs = '';
140         $schema = '';
141         $anyScriptChanges = '';
142         $db =& DBManagerFactory::getInstance();
143
144         //Quickcreatedefs on the basis of editviewdefs
145     if(substr($sugar_version,0,1) >= 5){
146         updateQuickCreateDefs();
147         }
148         upgradeSugarCache($_SESSION['install_file']);
149
150         if((count($errors) == 1)) { // only diffs
151                 logThis('file preflight check passed successfully.');
152                 $stop = false;
153                 $out  = $mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED']."<BR><BR><font color='red'>".$mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED3']."</font>";
154                 $stop = false;
155
156                 $disableEmail = (empty($current_user->email1)) ? 'DISABLED' : 'CHECKED';
157
158                 if(count($errors['manual']) > 0) {
159                         $preserveFiles = array();
160
161                 $diffs =<<<eoq
162                         <script type="text/javascript" language="Javascript">
163                                 function preflightToggleAll(cb) {
164                                         var checkAll = false;
165                                         var form = document.getElementById('diffs');
166
167                                         if(cb.checked == true) {
168                                                 checkAll = true;
169                                         }
170
171                                         for(i=0; i<form.elements.length; i++) {
172                                                 if(form.elements[i].type == 'checkbox') {
173                                                         form.elements[i].checked = checkAll;
174                                                 }
175                                         }
176                                         return;
177                                 }
178                         </script>
179
180                         <table cellpadding='0' cellspacing='0' border='0'>
181                                 <tr>
182                                         <td valign='top'>
183                                                 <input type='checkbox' name='addTask' id='addTask' CHECKED>
184                                         </td>
185                                         <td valign='top'>
186                                                 {$mod_strings['LBL_UW_PREFLIGHT_ADD_TASK']}
187                                         </td>
188                                 </tr>
189                                 <tr>
190                                         <td valign='top'>
191                                                 <input type='checkbox' name='addEmail' id='addEmail' $disableEmail>
192                                         </td>
193                                         <td valign='top'>
194                                                 {$mod_strings['LBL_UW_PREFLIGHT_EMAIL_REMINDER']}
195                                         </td>
196                                 </tr>
197                         </table>
198
199                         <form name='diffs' id='diffs'>
200                         <p><a href='javascript:void(0); toggleNwFiles("diffsHide");'>{$mod_strings['LBL_UW_SHOW_DIFFS']}</a></p>
201                         <div id='diffsHide' style='display:none'>
202                                 <table cellpadding='0' cellspacing='0' border='0'>
203                                         <tr>
204                                                 <td valign='top' colspan='2'>
205                                                         {$mod_strings['LBL_UW_PREFLIGHT_FILES_DESC']}
206                                                         <br />&nbsp;
207                                                 </td>
208                                         </tr>
209                                         <tr>
210                                                 <td valign='top' colspan='2'>
211                                                         <input type='checkbox' onchange='preflightToggleAll(this);'>&nbsp;<i><b>{$mod_strings['LBL_UW_PREFLIGHT_TOGGLE_ALL']}</b></i>
212                                                         <br />&nbsp;
213                                                 </td>
214                                         </tr>
215 eoq;
216                 foreach($errors['manual'] as $diff) {
217                         $diff = clean_path($diff);
218                         $_SESSION['files']['manual'][] = $diff;
219
220                         $checked = (isAutoOverwriteFile($diff)) ? 'CHECKED' : '';
221
222                         if(empty($checked)) {
223                                 $preserveFiles[] = $diff;
224                         }
225
226                         $diffs .= "<tr><td valign='top'>";
227                         $diffs .= "<input type='checkbox' name='diff_files[]' value='{$diff}' $checked>";
228                         $diffs .= "</td><td valign='top'>";
229                         $diffs .= str_replace(getcwd(), '.', $diff);
230                         $diffs .= "</td></tr>";
231                 }
232                 $diffs .= "</table>";
233                 $diffs .= "</div></p>";
234                 $diffs .= "</form>";
235
236                 // list preserved files (templates, etc.)
237                 $preserve = '';
238                 foreach($preserveFiles as $pf) {
239                         if(empty($preserve)) {
240                                 $preserve .= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><b>";
241                                 $preserve .= $mod_strings['LBL_UW_PREFLIGHT_PRESERVE_FILES'];
242                                 $preserve .= "</b></td></tr>";
243                         }
244                         $preserve .= "<tr><td valign='top'><i>".str_replace(getcwd(), '.', $pf)."</i></td></tr>";
245                 }
246                 if(!empty($preserve)) {
247                         $preserve .= '</table><br>';
248                 }
249                 $diffs = $preserve.$diffs;
250         } else { // NO FILE DIFFS REQUIRED
251                 $diffs = $mod_strings['LBL_UW_PREFLIGHT_NO_DIFFS'];
252         }
253 } else {
254         logThis('*** ERROR: found too many preflight errors - displaying errors and stopping execution.');
255         $out = "<b>{$mod_strings['ERR_UW_PREFLIGHT_ERRORS']}:</b><hr />";
256         $out .= "<span class='error'>";
257
258         foreach($errors as $error) {
259                 if(is_array($error)) { // manual diff files
260                         continue;
261                 } else {
262                         $out .= "{$error}<br />";
263                 }
264         }
265         $out .= "</span><br />";
266 }
267
268 $diffs ='';
269
270 ///////////////////////////////////////////////////////////////////////////////
271 ////    SCHEMA SCRIPT HANDLING
272         logThis('starting schema preflight check...');
273         //Check the current and target versions and store them in session variables
274         if(!isset($sugar_db_version) || empty($sugar_db_version)) {
275                 include('./sugar_version.php');
276         }
277         if(!isset($manifest['version']) || empty($manifest['version'])) {
278                 include($_SESSION['unzip_dir'].'/manifest.php');
279         }
280         $current_version = substr(preg_replace("#[^0-9]#", "", $sugar_db_version),0,3);
281         $targetVersion =  substr(preg_replace("#[^0-9]#", "", $manifest['version']),0,3);
282
283         //save the versions as session variables
284         $_SESSION['current_db_version'] = $current_version;
285         $_SESSION['target_db_version']  = $targetVersion;
286         $_SESSION['upgrade_from_flavor']  = $manifest['name'];
287         // aw: BUG 10161: check flavor conversion sql files
288         $sqlFile = ''; // cn: bug
289         if($current_version == $targetVersion) {
290
291                 if(preg_match('/(.*?)([^0])$/', $current_version, $matches))
292                 {
293                         $current_version = $matches[1].'0';
294                 }
295
296                 switch($manifest['name']){
297                         case 'SugarCE to SugarPro':
298                                 $sqlFile = $current_version.'_ce_to_pro_'.$db->dbType;
299                                 break;
300                         case 'SugarCE to SugarEnt':
301                                 $sqlFile = $current_version.'_ce_to_ent_'.$db->dbType;
302                                 break;
303                         case 'SugarPro to SugarEnt':
304                                 $sqlFile = $current_version.'_pro_to_ent_'.$db->dbType;
305                                 break;
306                         default:
307                                 break;
308                 }
309         } else {
310                 $sqlFile = $current_version.'_to_'.$targetVersion.'_'.$db->dbType;
311         }
312
313         $newTables = array();
314
315         if($db->dbType == 'oci8') {
316         } else {
317                 $sqlScript = $_SESSION['unzip_dir'].'/scripts/'.$sqlFile.'.sql';
318         }
319
320         logThis('looking for schema script at: '.$sqlScript);
321         if(is_file($sqlScript)) {
322                 logThis('found schema upgrade script: '.$sqlScript);
323
324                 logThis('schema preflight using MySQL');
325                 if(function_exists('sugar_fopen')){
326                         $fp = sugar_fopen($sqlScript, 'r');
327                 }
328                 else{
329                         $fp = fopen($sqlScript, 'r');
330                 }
331                 $contents = stream_get_contents($fp);
332             $anyScriptChanges =$contents;
333
334                 // remove __uw_temp tables
335                 //testCleanUp($db->dbType);
336                 fclose($fp);
337
338                 $customTables = getCustomTables($db->dbType);
339                 if ( !empty($customTables) ) {
340                         $_SESSION['alterCustomTableQueries'] = alterCustomTables($db->dbType, $customTables);
341                 } else {
342                         $_SESSION['alterCustomTableQueries'] = false;
343                 }
344
345                 $schema  = "<p><a href='javascript:void(0); toggleNwFiles(\"schemashow\");'>{$mod_strings['LBL_UW_SHOW_SCHEMA']}</a>";
346                 $schema .= "<div id='schemashow' style='display:none;'>";
347                 $schema .= "<textarea readonly cols='80' rows='10'>{$contents}</textarea>";
348                 $schema .= "</div></p>";
349
350                 if(!empty($sqlErrors)) {
351                         $stop = true;
352                         $out = "<b class='error'>{$mod_strings['ERR_UW_PREFLIGHT_ERRORS']}:</b> ";
353                         $out .= "<a href='javascript:void(0);toggleNwFiles(\"sqlErrors\");'>{$mod_strings['LBL_UW_SHOW_SQL_ERRORS']}</a><div id='sqlErrors' style='display:none'>";
354                         foreach($sqlErrors as $sqlError) {
355                                 $out .= "<br><span class='error'>{$sqlError}</span>";
356                         }
357                         $out .= "</div><hr />";
358                 }
359 } else {
360         $customTableSchema = '';
361         logThis('no schema script found - all schema preflight skipped');
362 }
363         logThis('schema preflight done.');
364 ////    END SCHEMA SCRIPT HANDLING
365 ///////////////////////////////////////////////////////////////////////////////
366 //php 521 suggestion
367         $php_521 = '';
368         if(version_compare(phpversion(),'5.2.1') < 0){
369                 $php_521=$mod_strings['LBL_CURRENT_PHP_VERSION'].phpversion().$mod_strings['LBL_RECOMMENDED_PHP_VERSION'];
370         }
371         if(empty($mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'])){
372                 $mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'] = 'Upgrade may take some time';
373         }
374
375 $style_for_out = empty($out)?'style=\'display:none\'':'';
376 $style_for_dif = empty($diffs)?'style=\'display:none\'':'';
377 $style_for_schemaChange = empty($schema)?'style=\'display:none\'':'';
378
379 $final =<<<eoq
380 <table cellpadding="3" cellspacing="0" border="0">
381     <tr {$style_for_out}>
382         <td colspan="2" align="left" valign="top">
383             <br>{$out}
384         </td>
385     </tr>
386     <tr {$style_for_dif}>
387         <td align="left" valign="top">
388             <b>{$mod_strings['LBL_UW_MANUAL_MERGE']}</b>
389         </td>
390         <td align="left" valign="top">
391             {$diffs}
392         </td>
393     </tr>
394     <tr>
395         <td colspan="3">&nbsp;</td>
396     </tr>
397     <tr {$style_for_schemaChange}>
398         <td align="left" valign="top">
399             <b>{$mod_strings['LBL_UW_SCHEMA_CHANGE']}</b>
400         </td>
401         <td align="left" valign="top">
402             {$schema}
403         </td>
404     </tr>
405     <tr {$style_for_schemaChange}>
406         <td>
407         </td>
408         <td valign="top">
409             <div>
410             <b>{$mod_strings['LBL_UW_DB_METHOD']}</b><br />
411             <select name="schema_change" id="select_schema_change" onchange="checkSqlStatus(false);">
412                 <option value="sugar">{$mod_strings['LBL_UW_DB_CHOICE1']}</option>
413                 <option value="manual">{$mod_strings['LBL_UW_DB_CHOICE2']}</option>
414             </select>
415             </div>
416             <div id='show_sql_run' style='display:none'>
417                 <input type='checkbox' name='sql_run' id='sql_run' onmousedown='checkSqlStatus(true);'> {$mod_strings['LBL_UW_SQL_RUN']}
418             </div>
419         </td>
420     </tr>
421 </table>
422
423 eoq;
424
425 $form5 =<<<eoq5
426 <br>
427 <div id="upgradeDiv" style="display:none">
428     <table cellspacing="0" cellpadding="0" border="0">
429         <tr><td>
430            <p><img src='modules/UpgradeWizard/processing.gif'></p>
431         </td></tr>
432      </table>
433  </div>
434
435 eoq5;
436
437         $uwMain = $final.$form5;
438
439         //set the upgrade progress status.
440         set_upgrade_progress('preflight','done');
441 }
442 else{
443         $stop = true;
444         if(empty($mod_strings['LBL_INCOMPATIBLE_PHP_VERSION'])){
445                 $mod_strings['LBL_INCOMPATIBLE_PHP_VERSION'] = 'Php version 5.2.1 or above is required.';
446         }
447
448 $php_verison_warning =<<<eoq
449         <table cellpadding="3" cellspacing="0" border="0">
450                 <tr>
451                         <th colspan="2" align="left">
452                                 <span class='error'><b>{$mod_strings['LBL_INCOMPATIBLE_PHP_VERSION']}</b></span>
453                         </th>
454                 </tr>
455         </table>
456 eoq;
457         $php_warnings = $php_verison_warning;
458 }
459 //Add the backward compatibility check as well.
460
461 //Php Backward compatibility checks
462 if(ini_get("zend.ze1_compatibility_mode")) {
463         $stop = true;
464         if(empty($mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'])){
465                 $mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'] = 'Php Backward Compatibility mode is turned on. Set zend.ze1_compatibility_mode to Off for proceeding further';
466         }
467
468 $php_compatibility_warning =<<<eoq
469         <table cellpadding="3" cellspacing="0" border="0">
470                 <tr>
471                         <th colspan="2" align="left">
472                                 <span class='error'><b>{$mod_strings['LBL_BACKWARD_COMPATIBILITY_ON']}</b></span>
473                         </th>
474                 </tr>
475         </table>
476 eoq;
477 $php_warnings .= $php_compatibility_warning;
478 }
479 if($php_warnings != null){
480         $uwMain = $php_warnings;
481 }
482
483 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED2']}</b>";
484 $showBack               = false;
485 $showCancel             = true;
486 $showRecheck    = true;
487 $showNext               = ($stop) ? false : true;
488
489 $stepBack               = $_REQUEST['step'] - 1;
490 $stepNext               = $_REQUEST['step'] + 1;
491 $stepCancel             = -1;
492 $stepRecheck    = $_REQUEST['step'];
493
494 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';
495 ?>