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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
40 require_once('modules/Administration/UpgradeWizardCommon.php');
41 require_once('modules/Configurator/Configurator.php');
42 function UWrebuild() {
45 $log->info('Deleting Relationship Cache. Relationships will automatically refresh.');
48 <div id='rrresult'></div>
52 /*@if (@_jscript_version >= 5)
53 // JScript gives us Conditional compilation, we can cope with old IE versions.
54 // and security blocked creation of the objects.
56 xmlhttp = new ActiveXObject(\"Msxml2.XMLHTTP\");
59 xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
65 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
67 xmlhttp = new XMLHttpRequest();
72 if (!xmlhttp && window.createRequest) {
74 xmlhttp = window.createRequest();
79 xmlhttp.onreadystatechange = function() {
80 if(xmlhttp.readyState == 4) {
81 document.getElementById('rrresult').innerHTML = xmlhttp.responseText;
84 xmlhttp.open('GET', 'index.php?module=Administration&action=RebuildRelationship&to_pdf=true', true);
88 $log->info('Rebuilding everything.');
89 require_once('ModuleInstall/ModuleInstaller.php');
90 $mi = new ModuleInstaller();
92 $query = "DELETE FROM versions WHERE name='Rebuild Extensions'";
96 // insert a new database row to show the rebuild extensions is done
98 $gmdate = TimeDate::getInstance()->nowDb();
99 $date_entered = db_convert("'$gmdate'", 'datetime');
100 $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) '
101 . "VALUES ('$id', '0', $date_entered, $date_entered, '1', '1', 'Rebuild Extensions', '4.0.0', '4.0.0')";
106 unset($_SESSION['rebuild_relationships']);
107 unset($_SESSION['rebuild_extensions']);
112 if( !isset($_REQUEST['mode']) || ($_REQUEST['mode'] == "") ){
113 die($mod_strings['ERR_UW_NO_MODE']);
115 $mode = $_REQUEST['mode'];
118 if( !isset($_REQUEST['version']) ){
119 die($mod_strings['ERR_UW_NO_MODE']);
121 $version = $_REQUEST['version'];
123 if( !isset($_REQUEST['copy_count']) || ($_REQUEST['copy_count'] == "") ){
124 die($mod_strings['ERR_UW_NO_FILES']);
127 if( empty($_REQUEST['unzip_dir']) || $_REQUEST['unzip_dir'] == "." || $_REQUEST['unzip_dir'] == ".."){
128 die($mod_strings['ERR_UW_NO_TEMP_DIR']);
130 $unzip_dir = $base_tmp_upgrade_dir. "/". basename($_REQUEST['unzip_dir']);
132 if(empty($_REQUEST['install_file'])){
133 die($mod_strings['ERR_UW_NO_INSTALL_FILE']);
136 $install_file = hashToFile($_REQUEST['install_file'] );
137 $install_type = getInstallType( $install_file );
139 //from here on out, the install_file is used as the file path to copy or rename the physical file, so let's remove the stream wrapper if it's set
140 //and replace it with the proper upload location
141 if(strpos($install_file,'upload://') === 0){
142 //get the upload location if it's set, or default to 'upload'
143 $upload_dir = empty($GLOBALS['sugar_config']['upload_dir']) ? 'upload' : rtrim($GLOBALS['sugar_config']['upload_dir'], '/\\');
145 //replace the wrapper in the file name with the directory
146 $install_file = str_replace('upload:/',$upload_dir,$install_file);
147 $_REQUEST['install_file'] = $install_file;
151 if(isset($_REQUEST['id_name'])){
152 $id_name = $_REQUEST['id_name'];
155 if(isset($_REQUEST['s_manifest'])){
156 $s_manifest = $_REQUEST['s_manifest'];
158 $previous_version = '';
159 if(isset($_REQUEST['previous_version'])){
160 $previous_version = $_REQUEST['previous_version'];
163 if(isset($_REQUEST['previous_id'])){
164 $previous_id = $_REQUEST['previous_id'];
166 if( $install_type != "module" ){
167 if( !isset($_REQUEST['zip_from_dir']) || ($_REQUEST['zip_from_dir'] == "") ){
171 $zip_from_dir = $_REQUEST['zip_from_dir'];
173 if( !isset($_REQUEST['zip_to_dir']) || ($_REQUEST['zip_to_dir'] == "") ){
177 $zip_to_dir = $_REQUEST['zip_to_dir'];
180 $remove_tables = 'true';
181 if(isset($_REQUEST['remove_tables'])){
182 $remove_tables = $_REQUEST['remove_tables'];
184 $overwrite_files = true;
185 if(isset($_REQUEST['radio_overwrite'])){
186 $overwrite_files = (($_REQUEST['radio_overwrite'] == 'do_not_overwrite') ? false : true);
191 $is_uninstallable = true;
195 if($install_type == 'module'){
196 $is_uninstallable = $_REQUEST['is_uninstallable'];
197 $name = $_REQUEST['name'];
198 $description = $_REQUEST['description'];
205 $rest_dir = remove_file_extension($install_file)."-restore";
207 $files_to_handle = array();
208 register_shutdown_function("rmdir_recursive", $unzip_dir);
210 if (((defined('MODULE_INSTALLER_PACKAGE_SCAN') && MODULE_INSTALLER_PACKAGE_SCAN)
211 || !empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])) && $install_type != 'patch') {
212 require_once('ModuleInstall/ModuleScanner.php');
213 $ms = new ModuleScanner();
214 $ms->scanPackage($unzip_dir);
215 if($ms->hasIssues()){
216 $ms->displayIssues();
222 // execute the PRE scripts
224 if($install_type == 'patch' || $install_type == 'module')
229 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
232 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
238 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_UNINSTALL_FILE');
241 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
252 // perform the action
255 for( $iii = 0; $iii < $_REQUEST['copy_count']; $iii++ ){
256 if( isset($_REQUEST["copy_" . $iii]) && ($_REQUEST["copy_" . $iii] != "") ){
257 $file_to_copy = $_REQUEST["copy_" . $iii];
258 $src_file = clean_path( "$unzip_dir/$zip_from_dir/$file_to_copy" );
260 $sugar_home_dir = getCwd();
261 $dest_file = clean_path( "$sugar_home_dir/$zip_to_dir/$file_to_copy" );
262 if($zip_to_dir != '.')
263 $rest_file = clean_path("$rest_dir/$zip_to_dir/$file_to_copy");
265 $rest_file = clean_path("$rest_dir/$file_to_copy");
269 mkdir_recursive( dirname( $dest_file ) );
271 if($install_type=="patch" && is_file($dest_file))
273 if(!is_dir(dirname( $rest_file )))
274 mkdir_recursive( dirname( $rest_file ) );
276 copy( $dest_file, $rest_file);
277 sugar_touch( $rest_file, filemtime($dest_file) );
280 if( !copy( $src_file, $dest_file ) ){
281 die( $mod_strings['ERR_UW_COPY_FAILED'].$src_file.$mod_strings['LBL_TO'].$dest_file);
283 $uh_status = "installed";
286 if($install_type=="patch" && is_file($rest_file))
288 copy( $rest_file, $dest_file);
289 sugar_touch( $dest_file, filemtime($rest_file) );
291 elseif(file_exists($dest_file) && !unlink($dest_file))
293 die($mod_strings['ERR_UW_REMOVE_FAILED'].$dest_file);
295 $uh_status = "uninstalled";
298 die("{$mod_strings['LBL_UW_OP_MODE']} '$mode' {$mod_strings['ERR_UW_NOT_RECOGNIZED']}." );
300 $files_to_handle[] = clean_path( "$zip_to_dir/$file_to_copy" );
304 switch( $install_type ){
306 if( !isset($_REQUEST['new_lang_name']) || ($_REQUEST['new_lang_name'] == "") ){
307 die($mod_strings['ERR_UW_NO_LANG']);
309 if( !isset($_REQUEST['new_lang_desc']) || ($_REQUEST['new_lang_desc'] == "") ){
310 die($mod_strings['ERR_UW_NO_LANG_DESC']);
313 if( $mode == "Install" || $mode=="Enable" ){
314 $sugar_config['languages'] = $sugar_config['languages'] + array( $_REQUEST['new_lang_name'] => $_REQUEST['new_lang_desc'] );
316 else if( $mode == "Uninstall" || $mode=="Disable" ){
317 $new_langs = array();
318 $old_langs = $sugar_config['languages'];
319 foreach( $old_langs as $key => $value ){
320 if( $key != $_REQUEST['new_lang_name'] ){
321 $new_langs += array( $key => $value );
324 $sugar_config['languages'] = $new_langs;
326 $default_sugar_instance_lang = 'en_us';
327 if($current_language == $_REQUEST['new_lang_name']){
328 $_SESSION['authenticated_user_language'] =$default_sugar_instance_lang;
329 $lang_changed_string = $mod_strings['LBL_CURRENT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
332 if($sugar_config['default_language'] == $_REQUEST['new_lang_name']){
333 $cfg = new Configurator();
334 $cfg->config['languages'] = $new_langs;
335 $cfg->config['default_language'] = $default_sugar_instance_lang;
336 $cfg->handleOverride();
337 $lang_changed_string .= $mod_strings['LBL_DEFAULT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
340 ksort( $sugar_config );
341 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){
342 die($mod_strings['ERR_UW_CONFIG_FAILED']);
346 require_once( "ModuleInstall/ModuleInstaller.php" );
347 $mi = new ModuleInstaller();
350 //here we can determine if this is an upgrade or a new version
351 if(!empty($previous_version)){
352 $mi->install( "$unzip_dir", true, $previous_version);
354 $mi->install( "$unzip_dir" );
357 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
360 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
366 if($remove_tables == 'false')
367 $GLOBALS['mi_remove_tables'] = false;
369 $GLOBALS['mi_remove_tables'] = true;
370 $mi->uninstall( "$unzip_dir" );
373 if(!$overwrite_files)
374 $GLOBALS['mi_overwrite_files'] = false;
376 $GLOBALS['mi_overwrite_files'] = true;
377 $mi->disable( "$unzip_dir" );
380 if(!$overwrite_files)
381 $GLOBALS['mi_overwrite_files'] = false;
383 $GLOBALS['mi_overwrite_files'] = true;
384 $mi->enable( "$unzip_dir" );
389 $current_user->incrementETag("mainMenuETag");
392 // purposely flow into "case: patch"
397 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
400 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
408 $file = "$unzip_dir/" . constant('SUGARCRM_POST_UNINSTALL_FILE');
410 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
415 if(is_dir($rest_dir))
417 rmdir_recursive($rest_dir);
426 require( "sugar_version.php" );
427 $sugar_config['sugar_version'] = $sugar_version;
428 ksort( $sugar_config );
430 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) )
432 die($mod_strings['ERR_UW_UPDATE_CONFIG']);
441 $file_action = "copied";
442 // if error was encountered, script should have died before now
443 $new_upgrade = new UpgradeHistory();
444 //determine if this module has already been installed given the unique_key to
445 //identify the module
446 // $new_upgrade->checkForExisting($unique_key);
447 if(!empty($previous_id)){
448 $new_upgrade->id = $previous_id;
449 $uh = new UpgradeHistory();
450 $uh->retrieve($previous_id);
451 if(is_file($uh->filename)) {
452 unlink($uh->filename);
455 $new_upgrade->filename = $install_file;
456 $new_upgrade->md5sum = md5_file( $install_file );
457 $new_upgrade->type = $install_type;
458 $new_upgrade->version = $version;
459 $new_upgrade->status = "installed";
460 $new_upgrade->name = $name;
461 $new_upgrade->description = $description;
462 $new_upgrade->id_name = $id_name;
463 $new_upgrade->manifest = $s_manifest;
464 $new_upgrade->save();
466 //Check if we need to show a page for the user to finalize their install with.
467 if (is_file("$unzip_dir/manifest.php"))
469 include("$unzip_dir/manifest.php");
470 if (!empty($manifest['post_install_url']))
472 $url_conf = $manifest['post_install_url'];
473 if (is_string($url_conf))
474 $url_conf = array('url' => $url_conf);
475 if (isset($url_conf['type']) && $url_conf['type'] == 'popup')
477 echo '<script type="text/javascript">window.open("' . $url_conf['url']
478 . '","' . (empty($url_conf['name']) ? 'sugar_popup' : $url_conf['name']) . '","'
479 . 'height=' . (empty($url_conf['height']) ? '500' : $url_conf['height']) . ','
480 . 'width=' . (empty($url_conf['width']) ? '800' : $url_conf['width']) . '");</script>';
483 echo '<iframe src="' . $url_conf['url'] . '" '
484 . 'width="' . (empty($url_conf['width']) ? '100%' : $url_conf['width']) . '" '
485 . 'height="' . (empty($url_conf['height']) ? '500px' : $url_conf['height']) . '"></iframe>';
491 $file_action = "removed";
492 $uh = new UpgradeHistory();
493 $the_md5 = md5_file( $install_file );
494 $md5_matches = $uh->findByMd5( $the_md5 );
495 if( sizeof( $md5_matches ) == 0 ){
496 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
498 foreach( $md5_matches as $md5_match ){
499 $md5_match->delete();
503 $file_action = "disabled";
504 $uh = new UpgradeHistory();
505 $the_md5 = md5_file( $install_file );
506 $md5_matches = $uh->findByMd5( $the_md5 );
507 if( sizeof( $md5_matches ) == 0 ){
508 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
510 foreach( $md5_matches as $md5_match ){
511 $md5_match->enabled = 0;
516 $file_action = "enabled";
517 $uh = new UpgradeHistory();
518 $the_md5 = md5_file( $install_file );
519 $md5_matches = $uh->findByMd5( $the_md5 );
520 if( sizeof( $md5_matches ) == 0 ){
521 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
523 foreach( $md5_matches as $md5_match ){
524 $md5_match->enabled = 1;
530 // present list to user
532 <form action="<?php print( $form_action ); ?>" method="post">
537 print( getUITextForType($install_type) . " ". getUITextForMode($mode) . " ". $mod_strings['LBL_UW_SUCCESSFULLY']);
540 print( "<input type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_MOD_LOADER']}\" /><br>" );
543 if(isset($lang_changed_string))
544 print($lang_changed_string);
545 if ($install_type != "module" && $install_type != "langpack"){
546 if( sizeof( $files_to_handle ) > 0 ){
547 echo '<div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;" onclick=\'this.style.display="none"; toggleDisplay("more");\' id="all_text">' . SugarThemeRegistry::current()->getImage('advanced_search', '', null, null, ".gif", $mod_strings['LBL_ADVANCED_SEARCH']) . ' Show Details</div><div id=\'more\' style=\'display: none\'>
548 <div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;" onclick=\'document.getElementById("all_text").style.display=""; toggleDisplay("more");\'>' . SugarThemeRegistry::current()->getImage('basic_search', '', null, null, ".gif", $mod_strings['LBL_BASIC_SEARCH']) . ' Hide Details</div><br>';
549 print( "{$mod_strings['LBL_UW_FOLLOWING_FILES']} $file_action:<br>\n" );
550 print( "<ul id=\"subMenu\">\n" );
551 foreach( $files_to_handle as $file_to_copy ){
552 print( "<li>$file_to_copy<br>\n" );
557 else if( $mode != 'Disable' && $mode !='Enable' ){
558 print( "{$mod_strings['LBL_UW_NO_FILES_SELECTED']} $file_action.<br>\n" );
561 print($mod_strings['LBL_UW_UPGRADE_SUCCESSFUL']);
562 print( "<input class='button' type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_UW']}\" />\n" );
568 $GLOBALS['log']->info( "Upgrade Wizard patches" );