]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/UpgradeWizard_prepare.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Administration / UpgradeWizard_prepare.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
41
42 require_once('modules/Administration/UpgradeWizardCommon.php');
43
44
45 unset($_SESSION['rebuild_relationships']);
46 unset($_SESSION['rebuild_extensions']);
47 // process commands
48 if(empty($_REQUEST['install_file'])){
49     die( "File to install not specified." );
50 }
51 if( !isset($_REQUEST['mode']) || ($_REQUEST['mode'] == "") ){
52     die( "No mode specified." );
53 }
54
55 $unzip_dir      = mk_temp_dir( $base_tmp_upgrade_dir );
56 $install_file   = hashToFile($_REQUEST['install_file']);
57 $hidden_fields = "";
58 $new_lang_name = "";
59 $new_lang_desc = "";
60
61 $mode           = $_REQUEST['mode'];
62 $hidden_fields .= "<input type=hidden name=\"mode\" value=\"$mode\"/>";
63
64
65 $install_type   = getInstallType( $install_file );
66
67 $version        = "";
68 $previous_version = "";
69 $show_files     = true;
70
71 $zip_from_dir   = ".";
72 $zip_to_dir     = ".";
73 $zip_force_copy = array();
74 $license_file = $unzip_dir.'/LICENSE.txt';
75 $readme_file  = $unzip_dir.'/README.txt';
76 $require_license = false;
77 $found_readme = false;
78 $author = '';
79 $name = '';
80 $description = '';
81 $is_uninstallable = true;
82 $id_name = '';
83 $dependencies = array();
84 $remove_tables = 'true';
85
86 unzip( $install_file, $unzip_dir );
87 if($install_type == 'module' && $mode != 'Uninstall'){
88    if(file_exists($license_file)){
89         $require_license = true;
90    }
91 }
92
93 //Scan the unzip dir for unsafe files
94 if(!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan']) && $install_type != 'patch'){
95         require_once('ModuleInstall/ModuleScanner.php');
96         $ms = new ModuleScanner();
97         $ms->scanPackage($unzip_dir);
98         if($ms->hasIssues()){
99                 $ms->displayIssues();
100                 sugar_cleanup(true);
101         }
102 }
103
104 // assumption -- already validated manifest.php at time of upload
105 require_once( "$unzip_dir/manifest.php" );
106
107
108
109 if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){
110     $zip_from_dir   = $manifest['copy_files']['from_dir'];
111 }
112 if( isset( $manifest['copy_files']['to_dir'] ) && $manifest['copy_files']['to_dir'] != "" ){
113     $zip_to_dir     = $manifest['copy_files']['to_dir'];
114 }
115 if( isset( $manifest['copy_files']['force_copy'] ) && $manifest['copy_files']['force_copy'] != "" ){
116     $zip_force_copy     = $manifest['copy_files']['force_copy'];
117 }
118 if( isset( $manifest['version'] ) ){
119     $version    = $manifest['version'];
120 }
121 if( isset( $manifest['author'] ) ){
122     $author    = $manifest['author'];
123 }
124 if( isset( $manifest['name'] ) ){
125     $name    = $manifest['name'];
126 }
127 if( isset( $manifest['description'] ) ){
128     $description    = $manifest['description'];
129 }
130 if( isset( $manifest['is_uninstallable'] ) ){
131     $is_uninstallable    = $manifest['is_uninstallable'];
132 }
133 if(isset($installdefs) && isset( $installdefs['id'] ) ){
134     $id_name    = $installdefs['id'];
135 }
136 if( isset( $manifest['dependencies']) ){
137     $dependencies    = $manifest['dependencies'];
138 }
139 if( isset( $manifest['remove_tables']) ){
140     $remove_tables = $manifest['remove_tables'];
141 }
142
143 if($remove_tables != 'prompt'){
144         $hidden_fields .= "<input type=hidden name=\"remove_tables\" value='".$remove_tables."'>";
145 }
146 if(file_exists($readme_file) || !empty($manifest['readme'])){
147         $found_readme = true;
148    }
149 $uh = new UpgradeHistory();
150 //check dependencies first
151 if(!empty($dependencies)){
152         $not_found = $uh->checkDependencies($dependencies);
153         if(!empty($not_found) && count($not_found) > 0){
154                         die( $mod_strings['ERR_UW_NO_DEPENDENCY']."[".implode(',', $not_found)."]");
155         }//fi
156 }
157 switch( $install_type ){
158         case "full":
159         case "patch":
160                 if( !is_writable( "config.php" ) ){
161                         die( $mod_strings['ERR_UW_CONFIG'] );
162                 }
163                 break;
164         case "theme":
165                 break;
166         case "langpack":
167                 // find name of language pack: find single file in include/language/xx_xx.lang.php
168                 $d = dir( "$unzip_dir/$zip_from_dir/include/language" );
169                 while( $f = $d->read() ){
170                         if( $f == "." || $f == ".." ){
171                                 continue;
172                         }
173                         else if( preg_match("/(.*)\.lang\.php\$/", $f, $match) ){
174                                 $new_lang_name = $match[1];
175                         }
176                 }
177                 if( $new_lang_name == "" ){
178                         die( $mod_strings['ERR_UW_NO_LANGPACK'].$install_file );
179                 }
180                 $hidden_fields .= "<input type=hidden name=\"new_lang_name\" value=\"$new_lang_name\"/>";
181
182                 $new_lang_desc = getLanguagePackName( "$unzip_dir/$zip_from_dir/include/language/$new_lang_name.lang.php" );
183                 if( $new_lang_desc == "" ){
184                         die( $mod_strings['ERR_UW_NO_LANG_DESC_1']."include/language/$new_lang_name.lang.php".$mod_strings['ERR_UW_NO_LANG_DESC_2']."$install_file." );
185                 }
186                 $hidden_fields .= "<input type=hidden name=\"new_lang_desc\" value=\"$new_lang_desc\"/>";
187
188                 if( !is_writable( "config.php" ) ){
189                         die( $mod_strings['ERR_UW_CONFIG'] );
190                 }
191                 break;
192         case "module":
193                 $previous_install = array();
194                 if(!empty($id_name) & !empty($version))
195                 $previous_install = $uh->determineIfUpgrade($id_name, $version);
196                 $previous_version = (empty($previous_install['version'])) ? '' : $previous_install['version'];
197                 $previous_id = (empty($previous_install['id'])) ? '' : $previous_install['id'];
198                 $show_files = false;
199                 //rrs pull out unique_key
200                 $hidden_fields .= "<input type=hidden name=\"author\" value=\"$author\"/>";
201                 $hidden_fields .= "<input type=hidden name=\"name\" value=\"$name\"/>";
202                 $hidden_fields .= "<input type=hidden name=\"description\" value=\"$description\"/>";
203                 $hidden_fields .= "<input type=hidden name=\"is_uninstallable\" value=\"$is_uninstallable\"/>";
204                 $hidden_fields .= "<input type=hidden name=\"id_name\" value=\"$id_name\"/>";
205                 $hidden_fields .= "<input type=hidden name=\"previous_version\" value=\"$previous_version\"/>";
206                 $hidden_fields .= "<input type=hidden name=\"previous_id\" value=\"$previous_id\"/>";
207                 break;
208         default:
209                 die( $mod_strings['ERR_UW_WRONG_TYPE'].$install_type );
210 }
211
212
213 $new_files      = findAllFilesRelative( "$unzip_dir/$zip_from_dir", array() );
214 $hidden_fields .= "<input type=hidden name=\"version\" value=\"$version\"/>";
215 $serial_manifest = array();
216 $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
217 $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
218 $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
219 $hidden_fields .= "<input type=hidden name=\"s_manifest\" value='".base64_encode(serialize($serial_manifest))."'>";
220 // present list to user
221 ?>
222 <form action="<?php print( $form_action . "_commit" ); ?>" name="files" method="post"  onSubmit="return validateForm(<?php print($require_license); ?>);">
223 <?php
224 if(empty($new_studio_mod_files)) {
225         if(!empty($mode) && $mode == 'Uninstall')
226         echo $mod_strings['LBL_UW_UNINSTALL_READY'];
227         else if($mode == 'Disable')
228         echo $mod_strings['LBL_UW_DISABLE_READY'];
229         else if($mode == 'Enable')
230         echo $mod_strings['LBL_UW_ENABLE_READY'];
231         else
232         echo $mod_strings['LBL_UW_PATCH_READY'];
233 }
234 else {
235         echo $mod_strings['LBL_UW_PATCH_READY2'];
236         echo '<input type="checkbox" onclick="toggle_these(0, ' . count($new_studio_mod_files) . ', this)"> '.$mod_strings['LBL_UW_CHECK_ALL'];
237         foreach($new_studio_mod_files as $the_file) {
238                 $new_file   = clean_path( "$zip_to_dir/$the_file" );
239                 print( "<li><input id=\"copy_$count\" name=\"copy_$count\" type=\"checkbox\" value=\"" . $the_file . "\"> " . $new_file . "</li>");
240                 $count++;
241         }
242 }
243 echo '<br>';
244 if($require_license){
245     $contents = sugar_file_get_contents($license_file);
246         $readme_contents = '';
247         if($found_readme){
248                 if(file_exists($readme_file) && filesize($readme_file) > 0){
249                         $readme_contents = file_get_contents($readme_file);
250                 }elseif(!empty($manifest['readme'])){
251                         $readme_contents = $manifest['readme'];
252                 }
253         }
254         $license_final =<<<eoq2
255         <table width='100%'>
256         <tr>
257         <td colspan="3"><ul class="tablist">
258         <li id="license_li" class="active"><a id="license_link"  class="current" href="javascript:selectTabCSS('license');">{$mod_strings['LBL_LICENSE']}</a></li>
259         <li class="active" id="readme_li"><a id="readme_link" href="javascript:selectTabCSS('readme');">{$mod_strings['LBL_README']}</a></li>
260         </ul></td>
261         </tr>
262         </table>
263         <div id='license_div'>
264         <table>
265         <tr>
266         <td colspan="3">&nbsp;</td>
267         </tr>
268         <tr>
269         <td align="left" valign="top" colspan=2>
270         <b>{$mod_strings['LBL_MODULE_LICENSE']}</b>
271         </td>
272         </tr>
273         <tr>
274         <td align="left" valign="top" colspan=2>
275         <textarea cols="100" rows="8" readonly>{$contents}</textarea>
276         </td>
277
278         </tr>
279         <tr>
280         <td align="left" valign="top" colspan=2>
281         <input type='radio' id='radio_license_agreement_accept' name='radio_license_agreement' value='accept'>{$mod_strings['LBL_ACCEPT']}&nbsp;
282         <input type='radio' id='radio_license_agreement_reject' name='radio_license_agreement' value='reject' checked>{$mod_strings['LBL_DENY']}
283         </td>
284
285         </tr></table>
286         </div>
287         <div id='readme_div' style='display: none;'>
288         <table>
289         <tr>
290         <td colspan="3">&nbsp;</td>
291         </tr>
292         <tr>
293         <td align="left" valign="top" colspan=2>
294         <b>{$mod_strings['LBL_README']}</b>
295         </td>
296         </tr>
297         <tr>
298         <td align="left" valign="top" colspan=2>
299         <textarea cols="100" rows="8" readonly>{$readme_contents}</textarea>
300         </td>
301
302     </tr>
303 </table>
304 </div>
305
306 eoq2;
307         echo $license_final;
308         echo "<br>";
309 }
310
311 switch( $mode ){
312         case "Install":
313                 if( $install_type == "langpack") {
314                         print( $mod_strings['LBL_UW_LANGPACK_READY'] );
315                         echo '<br><br>';
316                 }
317                 break;
318         case "Uninstall":
319                 if( $install_type == "langpack" ){
320                         print( $mod_strings['LBL_UW_LANGPACK_READY_UNISTALL'] );
321                         echo '<br><br>';
322                 }
323                 else if($install_type != "module"){
324                         print( $mod_strings['LBL_UW_FILES_REMOVED'] );
325                 }
326                 break;
327         case "Disable":
328                 if( $install_type == "langpack" ){
329                         print( $mod_strings['LBL_UW_LANGPACK_READY_DISABLE'] );
330                         echo '<br><br>';
331                 }
332                 break;
333         case "Enable":
334                 if( $install_type == "langpack" ){
335                         print( $mod_strings['LBL_UW_LANGPACK_READY_ENABLE'] );
336                         echo '<br><br>';
337                 }
338                 break;
339 }
340
341
342 ?>
343 <input type=submit value="<?php echo $mod_strings['LBL_ML_COMMIT'];?>" class="button" />
344 <input type=button value="<?php echo $mod_strings['LBL_ML_CANCEL'];?>" class="button" onClick="location.href='index.php?module=Administration&action=UpgradeWizard&view=module';"/>
345
346 <?php
347
348 if($remove_tables == 'prompt' && $mode == 'Uninstall'){
349     print ("<br/><br/>");
350         print ("<input type='radio' id='remove_tables_true' name='remove_tables' value='true' checked>".$mod_strings['ML_LBL_REMOVE_TABLES']."&nbsp;");
351     print ("<input type='radio' id='remove_tables_false' name='remove_tables' value='false'>".$mod_strings['ML_LBL_DO_NOT_REMOVE_TABLES']."<br>");
352 }
353 $count = 0;
354
355 if( $show_files == true ){
356         $count = 0;
357
358         $new_studio_mod_files = array();
359         $new_sugar_mod_files = array();
360
361         $cache_html_files = findAllFilesRelative( "{$GLOBALS['sugar_config']['cache_dir']}layout", array());
362
363         foreach($new_files as $the_file) {
364                 if(substr(strtolower($the_file), -5, 5) == '.html' && in_array($the_file, $cache_html_files))
365                 array_push($new_studio_mod_files, $the_file);
366                 else
367                 array_push($new_sugar_mod_files, $the_file);
368         }
369
370         echo '<script>
371             function toggle_these(start, end, ca) {
372               while(start < end) {
373                 elem = eval("document.forms.files.copy_" + start);
374                 if(!ca.checked) elem.checked = false;
375                 else elem.checked = true;
376                 start++;
377               }
378             }
379                         </script>';
380
381
382
383         global $theme;
384
385         echo '<br/><br/>';
386
387     echo '<div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;'.(($mode == 'Enable' || $mode == 'Disable')?'display:none;':'').'" onclick=\'this.style.display="none"; toggleDisplay("more");\'id="all_text">
388         '.' <img src="'.SugarThemeRegistry::current()->getImageURL('advanced_search.gif').'">'.$mod_strings['LBL_UW_SHOW_DETAILS'].'</div><div id=\'more\' style=\'display: none\'>
389               <div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;" onclick=\'document.getElementById("all_text").style.display=""; toggleDisplay("more");\'>'
390          .' <img name="options" src="'.SugarThemeRegistry::current()->getImageURL('basic_search.gif').'">'.$mod_strings['LBL_UW_HIDE_DETAILS'].'</div><br>';
391     echo '<input type="checkbox" checked onclick="toggle_these(' . count($new_studio_mod_files) . ',' . count($new_files) . ', this)"> '.$mod_strings['LBL_UW_CHECK_ALL'];
392         echo '<ul>';
393         foreach( $new_sugar_mod_files as $the_file ){
394                 $highlight_start    = "";
395                 $highlight_end      = "";
396                 $checked            = "";
397                 $disabled           = "";
398                 $unzip_file = "$unzip_dir/$zip_from_dir/$the_file";
399                 $new_file   = clean_path( "$zip_to_dir/$the_file" );
400                 $forced_copy    = false;
401
402                 if( $mode == "Install" ){
403                         $checked = "checked";
404                         foreach( $zip_force_copy as $pattern ){
405                                 if( preg_match("#" . $pattern . "#", $unzip_file) ){
406                                         $disabled = "disabled=\"true\"";
407                                         $forced_copy = true;
408                                 }
409                         }
410                         if( !$forced_copy && is_file( $new_file ) && (md5_file( $unzip_file ) == md5_file( $new_file )) ){
411                                 $disabled = "disabled=\"true\"";
412                                 //$checked = "";
413                         }
414                         if( $checked != "" && $disabled != "" ){    // need to put a hidden field
415                                 print( "<input name=\"copy_$count\" type=\"hidden\" value=\"" . $the_file . "\">\n" );
416                         }
417                         print( "<li><input id=\"copy_$count\" name=\"copy_$count\" type=\"checkbox\" value=\"" . $the_file . "\" $checked $disabled > " . $highlight_start . $new_file . $highlight_end );
418                         if( $checked == "" && $disabled != "" ){    // need to explain this file hasn't changed
419                                 print( " (no changes)" );
420                         }
421                         print( "<br>\n" );
422                 }
423                 else if( $mode == "Uninstall" && file_exists( $new_file ) ){
424                         if( md5_file( $unzip_file ) == md5_file( $new_file ) ){
425                                 $checked = "checked=\"true\"";
426                         }
427                         else{
428                                 $highlight_start    = "<font color=red>";
429                                 $highlight_end      = "</font>";
430                         }
431                         print( "<li><input name=\"copy_$count\" type=\"checkbox\" value=\"" . $the_file . "\" $checked $disabled > " . $highlight_start . $new_file . $highlight_end . "<br>\n" );
432                 }
433                 $count++;
434         }
435         print( "</ul>\n" );
436 }
437 //    echo '</div>';
438 if($mode == "Disable" || $mode == "Enable"){
439         //check to see if any files have been modified
440         $modified_files = getDiffFiles($unzip_dir, $install_file, ($mode == 'Enable'), $previous_version);
441         if(count($modified_files) > 0){
442                 //we need to tell the user that some files have been modified since they last did an install
443                 echo '<script>' .
444                 'function handleFileChange(){';
445                 if(count($modified_files) > 0){
446                         echo 'if(document.getElementById("radio_overwrite_files") != null && document.getElementById("radio_do_not_overwrite_files") != null){
447                                         var overwrite = false;
448                                         if(document.getElementById("radio_overwrite_files").checked){
449                                          overwrite = true
450                                         }
451                                 }
452                                         return true;';
453                 }else{
454                         echo 'return true;';
455                 }
456                 echo '}</script>';
457                 print('<b>'.$mod_strings['ML_LBL_OVERWRITE_FILES'].'</b>');
458                 print('<table><td align="left" valign="top" colspan=2>');
459                 print("<input type='radio' id='radio_overwrite_files' name='radio_overwrite' value='overwrite'>{$mod_strings['LBL_OVERWRITE_FILES']}&nbsp;");
460                 print("<input type='radio' id='radio_do_not_overwrite_files' name='radio_overwrite' value='do_not_overwrite' checked>{$mod_strings['LBL_DO_OVERWRITE_FILES']}");
461                 print("</td></tr></table>");
462                 print('<ul>');
463                 foreach($modified_files as $modified_file){
464                         print('<li>'.$modified_file.'</li>');
465                 }
466                 print('</ul>');
467         }else{
468                 echo '<script>' .
469                 'function handleFileChange(){';
470                 echo 'return true;';
471                 echo '}</script>';
472         }
473 }else{
474         echo '<script>' .
475         'function handleFileChange(){';
476         echo 'return true;';
477         echo '}</script>';
478 }
479 echo '<script>' .
480                         'function validateForm(process){'.
481                                 'return (handleCommit(process) && handleFileChange());'.
482                         '}'.
483                 'function handleCommit(process){
484         if(process == 1) {
485             if(document.getElementById("radio_license_agreement_reject") != null && document.getElementById("radio_license_agreement_accept") != null){
486                 var accept = false;
487                 if(document.getElementById("radio_license_agreement_accept").checked){
488                     accept = true
489                 }
490                 if(!accept){
491                     //do not allow the form to submit
492                     alert("'.$mod_strings['ERR_UW_ACCEPT_LICENSE'].'");
493                     return false;
494                 }
495             }
496         }
497         return true;
498     }
499     var keys = [ "license","readme"];
500     function selectTabCSS(key){
501                 for( var i=0; i<keys.length;i++)
502                 {
503                         var liclass = "";
504                         var linkclass = "";
505
506                         if ( key == keys[i])
507                         {
508                         var liclass = "active";
509                         var linkclass = "current";
510                         document.getElementById(keys[i]+"_div").style.display = "block";
511                         }else{
512                         document.getElementById(keys[i]+"_div").style.display = "none";
513                         }
514                         document.getElementById(keys[i]+"_li").className = liclass;
515                         document.getElementById(keys[i]+"_link").className = linkclass;
516                 }
517                 tabPreviousKey = key;
518             }
519       </script>';
520
521     $fileHash = fileToHash($install_file );
522 ?>
523     <?php print( $hidden_fields ); ?>
524     <input type=hidden name="copy_count" value="<?php print( $count );?>"/>
525     <input type=hidden name="run" value="commit" />
526     <input type=hidden name="install_file"  value="<?php echo $fileHash; ?>" />
527     <input type=hidden name="unzip_dir"     value="<?php echo $unzip_dir; ?>" />
528     <input type=hidden name="zip_from_dir"  value="<?php echo $zip_from_dir; ?>" />
529     <input type=hidden name="zip_to_dir"    value="<?php echo $zip_to_dir; ?>" />
530 </form>
531
532 <?php
533     $GLOBALS['log']->info( "Upgrade Wizard patches" );
534 ?>