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