]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/preflight.php
Release 6.5.9
[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-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 // 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     updateQuickCreateDefs();
146         upgradeSugarCache($_SESSION['install_file']);
147
148         if((count($errors) == 1)) { // only diffs
149                 logThis('file preflight check passed successfully.');
150                 $stop = false;
151                 $out  = $mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED']."<BR><BR><font color='red'>".$mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED3']."</font>";
152                 $stop = false;
153
154                 $disableEmail = (empty($current_user->email1)) ? 'DISABLED' : 'CHECKED';
155
156                 if(count($errors['manual']) > 0) {
157                         $preserveFiles = array();
158
159                 $diffs =<<<eoq
160                         <script type="text/javascript" language="Javascript">
161                                 function preflightToggleAll(cb) {
162                                         var checkAll = false;
163                                         var form = document.getElementById('diffs');
164
165                                         if(cb.checked == true) {
166                                                 checkAll = true;
167                                         }
168
169                                         for(i=0; i<form.elements.length; i++) {
170                                                 if(form.elements[i].type == 'checkbox') {
171                                                         form.elements[i].checked = checkAll;
172                                                 }
173                                         }
174                                         return;
175                                 }
176                         </script>
177
178                         <table cellpadding='0' cellspacing='0' border='0'>
179                                 <tr>
180                                         <td valign='top'>
181                                                 <input type='checkbox' name='addTask' id='addTask' CHECKED>
182                                         </td>
183                                         <td valign='top'>
184                                                 {$mod_strings['LBL_UW_PREFLIGHT_ADD_TASK']}
185                                         </td>
186                                 </tr>
187                                 <tr>
188                                         <td valign='top'>
189                                                 <input type='checkbox' name='addEmail' id='addEmail' $disableEmail>
190                                         </td>
191                                         <td valign='top'>
192                                                 {$mod_strings['LBL_UW_PREFLIGHT_EMAIL_REMINDER']}
193                                         </td>
194                                 </tr>
195                         </table>
196
197                         <form name='diffs' id='diffs'>
198                         <p><a href='javascript:void(0); toggleNwFiles("diffsHide");'>{$mod_strings['LBL_UW_SHOW_DIFFS']}</a></p>
199                         <div id='diffsHide' style='display:none'>
200                                 <table cellpadding='0' cellspacing='0' border='0'>
201                                         <tr>
202                                                 <td valign='top' colspan='2'>
203                                                         {$mod_strings['LBL_UW_PREFLIGHT_FILES_DESC']}
204                                                         <br />&nbsp;
205                                                 </td>
206                                         </tr>
207                                         <tr>
208                                                 <td valign='top' colspan='2'>
209                                                         <input type='checkbox' onchange='preflightToggleAll(this);'>&nbsp;<i><b>{$mod_strings['LBL_UW_PREFLIGHT_TOGGLE_ALL']}</b></i>
210                                                         <br />&nbsp;
211                                                 </td>
212                                         </tr>
213 eoq;
214                 foreach($errors['manual'] as $diff) {
215                         $diff = clean_path($diff);
216                         $_SESSION['files']['manual'][] = $diff;
217
218                         $checked = (isAutoOverwriteFile($diff)) ? 'CHECKED' : '';
219
220                         if(empty($checked)) {
221                                 $preserveFiles[] = $diff;
222                         }
223
224                         $diffs .= "<tr><td valign='top'>";
225                         $diffs .= "<input type='checkbox' name='diff_files[]' value='{$diff}' $checked>";
226                         $diffs .= "</td><td valign='top'>";
227                         $diffs .= str_replace(getcwd(), '.', $diff);
228                         $diffs .= "</td></tr>";
229                 }
230                 $diffs .= "</table>";
231                 $diffs .= "</div></p>";
232                 $diffs .= "</form>";
233
234                 // list preserved files (templates, etc.)
235                 $preserve = '';
236                 foreach($preserveFiles as $pf) {
237                         if(empty($preserve)) {
238                                 $preserve .= "<table cellpadding='0' cellspacing='0' border='0'><tr><td><b>";
239                                 $preserve .= $mod_strings['LBL_UW_PREFLIGHT_PRESERVE_FILES'];
240                                 $preserve .= "</b></td></tr>";
241                         }
242                         $preserve .= "<tr><td valign='top'><i>".str_replace(getcwd(), '.', $pf)."</i></td></tr>";
243                 }
244                 if(!empty($preserve)) {
245                         $preserve .= '</table><br>';
246                 }
247                 $diffs = $preserve.$diffs;
248         } else { // NO FILE DIFFS REQUIRED
249                 $diffs = $mod_strings['LBL_UW_PREFLIGHT_NO_DIFFS'];
250         }
251 } else {
252         logThis('*** ERROR: found too many preflight errors - displaying errors and stopping execution.');
253         $out = "<b>{$mod_strings['ERR_UW_PREFLIGHT_ERRORS']}:</b><hr />";
254         $out .= "<span class='error'>";
255
256         foreach($errors as $error) {
257                 if(is_array($error)) { // manual diff files
258                         continue;
259                 } else {
260                         $out .= "{$error}<br />";
261                 }
262         }
263         $out .= "</span><br />";
264 }
265
266 $diffs ='';
267
268 ///////////////////////////////////////////////////////////////////////////////
269 ////    SCHEMA SCRIPT HANDLING
270         logThis('starting schema preflight check...');
271         //Check the current and target versions and store them in session variables
272     if (empty($sugar_db_version))
273     {
274         include('sugar_version.php');
275     }
276         if(!isset($manifest['version']) || empty($manifest['version'])) {
277                 include($_SESSION['unzip_dir'].'/manifest.php');
278         }
279
280     $origVersion = implodeVersion($sugar_db_version, 3, '0');
281     $destVersion = implodeVersion($manifest['version'], 3, '0');
282
283         //save the versions as session variables
284     $_SESSION['current_db_version'] = $sugar_db_version;
285     $_SESSION['target_db_version']  = $manifest['version'];
286         $_SESSION['upgrade_from_flavor']  = $manifest['name'];
287         // aw: BUG 10161: check flavor conversion sql files
288         $sqlFile = ''; // cn: bug
289     if (version_compare($sugar_db_version, $manifest['version'], '='))
290     {
291             $type = $db->getScriptName();
292
293         switch($manifest['name'])
294         {
295             case 'SugarCE to SugarPro':
296                 $sqlFile = $origVersion . '_ce_to_pro_' . $type;
297                 break;
298             case 'SugarCE to SugarEnt':
299                 $sqlFile = $origVersion . '_ce_to_ent_' . $type;
300                 break;
301             case 'SugarCE to SugarCorp':
302                 $sqlFile = $origVersion . '_ce_to_corp_' . $db->dbType;
303                 break;
304             case 'SugarCE to SugarUlt':
305                 $sqlFile = $origVersion . '_ce_to_ult_' . $db->dbType;
306                 break;
307             case 'SugarPro to SugarEnt':
308                 $sqlFile = $origVersion . '_pro_to_ent_' . $type;
309                 break;
310             default:
311                 break;
312         }
313         } else {
314             $type = $db->dbType;
315         if($type == 'oci8') $type = 'oracle';
316         $sqlFile = $origVersion . '_to_' . $destVersion . '_' . $type;
317         }
318
319         $newTables = array();
320
321     $sqlScript = $_SESSION['unzip_dir'].'/scripts/'.$sqlFile.'.sql';
322
323         logThis('looking for schema script at: '.$sqlScript);
324         if(is_file($sqlScript)) {
325                 logThis('found schema upgrade script: '.$sqlScript);
326
327                 logThis('schema preflight using MySQL');
328                 if(function_exists('sugar_fopen')){
329                         $fp = sugar_fopen($sqlScript, 'r');
330                 }
331                 else{
332                         $fp = fopen($sqlScript, 'r');
333                 }
334                 $contents = stream_get_contents($fp);
335             $anyScriptChanges =$contents;
336
337                 fclose($fp);
338
339                 $customTables = getCustomTables();
340                 if ( !empty($customTables) ) {
341                         $_SESSION['alterCustomTableQueries'] = alterCustomTables($customTables);
342                 } else {
343                         $_SESSION['alterCustomTableQueries'] = false;
344                 }
345
346                 $schema  = "<p><a href='javascript:void(0); toggleNwFiles(\"schemashow\");'>{$mod_strings['LBL_UW_SHOW_SCHEMA']}</a>";
347                 $schema .= "<div id='schemashow' style='display:none;'>";
348                 $schema .= "<textarea readonly cols='80' rows='10'>{$contents}</textarea>";
349                 $schema .= "</div></p>";
350
351                 if(!empty($sqlErrors)) {
352                         $stop = true;
353                         $out = "<b class='error'>{$mod_strings['ERR_UW_PREFLIGHT_ERRORS']}:</b> ";
354                         $out .= "<a href='javascript:void(0);toggleNwFiles(\"sqlErrors\");'>{$mod_strings['LBL_UW_SHOW_SQL_ERRORS']}</a><div id='sqlErrors' style='display:none'>";
355                         foreach($sqlErrors as $sqlError) {
356                                 $out .= "<br><span class='error'>{$sqlError}</span>";
357                         }
358                         $out .= "</div><hr />";
359                 }
360 } else {
361         $customTableSchema = '';
362         logThis('no schema script found - all schema preflight skipped');
363 }
364         logThis('schema preflight done.');
365 ////    END SCHEMA SCRIPT HANDLING
366 ///////////////////////////////////////////////////////////////////////////////
367 //php 521 suggestion
368         $php_521 = '';
369         if(version_compare(phpversion(),'5.2.1') < 0){
370                 $php_521=$mod_strings['LBL_CURRENT_PHP_VERSION'].phpversion().$mod_strings['LBL_RECOMMENDED_PHP_VERSION'];
371         }
372         if(empty($mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'])){
373                 $mod_strings['LBL_UPGRADE_TAKES_TIME_HAVE_PATIENCE'] = 'Upgrade may take some time';
374         }
375
376 $style_for_out = empty($out)?'style=\'display:none\'':'';
377 $style_for_dif = empty($diffs)?'style=\'display:none\'':'';
378 $style_for_schemaChange = empty($schema)?'style=\'display:none\'':'';
379
380 $final =<<<eoq
381 <table cellpadding="3" cellspacing="0" border="0">
382     <tr {$style_for_out}>
383         <td colspan="2" align="left" valign="top">
384             <br>{$out}
385         </td>
386     </tr>
387     <tr {$style_for_dif}>
388         <td align="left" valign="top">
389             <b>{$mod_strings['LBL_UW_MANUAL_MERGE']}</b>
390         </td>
391         <td align="left" valign="top">
392             {$diffs}
393         </td>
394     </tr>
395     <tr>
396         <td colspan="3">&nbsp;</td>
397     </tr>
398     <tr {$style_for_schemaChange}>
399         <td align="left" valign="top">
400             <b>{$mod_strings['LBL_UW_SCHEMA_CHANGE']}</b>
401         </td>
402         <td align="left" valign="top">
403             {$schema}
404         </td>
405     </tr>
406     <tr {$style_for_schemaChange}>
407         <td>
408         </td>
409         <td valign="top">
410             <div>
411             <b>{$mod_strings['LBL_UW_DB_METHOD']}</b><br />
412             <select name="schema_change" id="select_schema_change" onchange="checkSqlStatus(false);">
413                 <option value="sugar">{$mod_strings['LBL_UW_DB_CHOICE1']}</option>
414                 <option value="manual">{$mod_strings['LBL_UW_DB_CHOICE2']}</option>
415             </select>
416             </div>
417             <div id='show_sql_run' style='display:none'>
418                 <input type='checkbox' name='sql_run' id='sql_run' onmousedown='checkSqlStatus(true);'> {$mod_strings['LBL_UW_SQL_RUN']}
419             </div>
420         </td>
421     </tr>
422 </table>
423
424 eoq;
425
426 $form5 =<<<eoq5
427 <br>
428 <div id="upgradeDiv" style="display:none">
429     <table cellspacing="0" cellpadding="0" border="0">
430         <tr><td>
431            <p><!--not_in_theme!--><img src='modules/UpgradeWizard/processing.gif' alt='Processing'></p>
432         </td></tr>
433      </table>
434  </div>
435
436 eoq5;
437
438         $uwMain = $final.$form5;
439
440         //set the upgrade progress status.
441         set_upgrade_progress('preflight','done');
442 }
443 else{
444         $stop = true;
445         if(empty($mod_strings['LBL_INCOMPATIBLE_PHP_VERSION'])){
446                 $mod_strings['LBL_INCOMPATIBLE_PHP_VERSION'] = 'Php version 5.2.1 or above is required.';
447         }
448
449 $php_verison_warning =<<<eoq
450         <table cellpadding="3" cellspacing="0" border="0">
451                 <tr>
452                         <th colspan="2" align="left">
453                                 <span class='error'><b>{$mod_strings['LBL_INCOMPATIBLE_PHP_VERSION']}</b></span>
454                         </th>
455                 </tr>
456         </table>
457 eoq;
458         $php_warnings = $php_verison_warning;
459 }
460 //Add the backward compatibility check as well.
461
462 //Php Backward compatibility checks
463 if(ini_get("zend.ze1_compatibility_mode")) {
464         $stop = true;
465         if(empty($mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'])){
466                 $mod_strings['LBL_BACKWARD_COMPATIBILITY_ON'] = 'Php Backward Compatibility mode is turned on. Set zend.ze1_compatibility_mode to Off for proceeding further';
467         }
468
469 $php_compatibility_warning =<<<eoq
470         <table cellpadding="3" cellspacing="0" border="0">
471                 <tr>
472                         <th colspan="2" align="left">
473                                 <span class='error'><b>{$mod_strings['LBL_BACKWARD_COMPATIBILITY_ON']}</b></span>
474                         </th>
475                 </tr>
476         </table>
477 eoq;
478 $php_warnings .= $php_compatibility_warning;
479 }
480 if($php_warnings != null){
481         $uwMain = $php_warnings;
482 }
483
484 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_UW_PREFLIGHT_TESTS_PASSED2']}</b>";
485 $showBack               = false;
486 $showCancel             = true;
487 $showRecheck    = true;
488 $showNext               = ($stop) ? false : true;
489
490 $stepBack               = $_REQUEST['step'] - 1;
491 $stepNext               = $_REQUEST['step'] + 1;
492 $stepCancel             = -1;
493 $stepRecheck    = $_REQUEST['step'];
494
495 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = ($stop) ? 'failed' : 'success';