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.
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 if(isset($_REQUEST['id_name'])){
140 $id_name = $_REQUEST['id_name'];
143 if(isset($_REQUEST['s_manifest'])){
144 $s_manifest = $_REQUEST['s_manifest'];
146 $previous_version = '';
147 if(isset($_REQUEST['previous_version'])){
148 $previous_version = $_REQUEST['previous_version'];
151 if(isset($_REQUEST['previous_id'])){
152 $previous_id = $_REQUEST['previous_id'];
154 if( $install_type != "module" ){
155 if( !isset($_REQUEST['zip_from_dir']) || ($_REQUEST['zip_from_dir'] == "") ){
159 $zip_from_dir = $_REQUEST['zip_from_dir'];
161 if( !isset($_REQUEST['zip_to_dir']) || ($_REQUEST['zip_to_dir'] == "") ){
165 $zip_to_dir = $_REQUEST['zip_to_dir'];
168 $remove_tables = 'true';
169 if(isset($_REQUEST['remove_tables'])){
170 $remove_tables = $_REQUEST['remove_tables'];
172 $overwrite_files = true;
173 if(isset($_REQUEST['radio_overwrite'])){
174 $overwrite_files = (($_REQUEST['radio_overwrite'] == 'do_not_overwrite') ? false : true);
179 $is_uninstallable = true;
183 if($install_type == 'module'){
184 $is_uninstallable = $_REQUEST['is_uninstallable'];
185 $name = $_REQUEST['name'];
186 $description = $_REQUEST['description'];
193 $rest_dir = remove_file_extension($install_file)."-restore";
195 $files_to_handle = array();
197 if(!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan']) && $install_type != 'patch'){
198 require_once('ModuleInstall/ModuleScanner.php');
199 $ms = new ModuleScanner();
200 $ms->scanPackage($unzip_dir);
201 if($ms->hasIssues()){
202 $ms->displayIssues();
208 // execute the PRE scripts
210 if($install_type == 'patch' || $install_type == 'module')
215 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
218 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
224 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_UNINSTALL_FILE');
227 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
238 // perform the action
241 for( $iii = 0; $iii < $_REQUEST['copy_count']; $iii++ ){
242 if( isset($_REQUEST["copy_" . $iii]) && ($_REQUEST["copy_" . $iii] != "") ){
243 $file_to_copy = $_REQUEST["copy_" . $iii];
244 $src_file = clean_path( "$unzip_dir/$zip_from_dir/$file_to_copy" );
246 $sugar_home_dir = getCwd();
247 $dest_file = clean_path( "$sugar_home_dir/$zip_to_dir/$file_to_copy" );
248 if($zip_to_dir != '.')
249 $rest_file = clean_path("$rest_dir/$zip_to_dir/$file_to_copy");
251 $rest_file = clean_path("$rest_dir/$file_to_copy");
255 mkdir_recursive( dirname( $dest_file ) );
257 if($install_type=="patch" && is_file($dest_file))
259 if(!is_dir(dirname( $rest_file )))
260 mkdir_recursive( dirname( $rest_file ) );
262 copy( $dest_file, $rest_file);
263 sugar_touch( $rest_file, filemtime($dest_file) );
266 if( !copy( $src_file, $dest_file ) ){
267 die( $mod_strings['ERR_UW_COPY_FAILED'].$src_file.$mod_strings['LBL_TO'].$dest_file);
269 $uh_status = "installed";
272 if($install_type=="patch" && is_file($rest_file))
274 copy( $rest_file, $dest_file);
275 sugar_touch( $dest_file, filemtime($rest_file) );
277 elseif(file_exists($dest_file) && !unlink($dest_file))
279 die($mod_strings['ERR_UW_REMOVE_FAILED'].$dest_file);
281 $uh_status = "uninstalled";
284 die("{$mod_strings['LBL_UW_OP_MODE']} '$mode' {$mod_strings['ERR_UW_NOT_RECOGNIZED']}." );
286 $files_to_handle[] = clean_path( "$zip_to_dir/$file_to_copy" );
290 switch( $install_type ){
292 if( !isset($_REQUEST['new_lang_name']) || ($_REQUEST['new_lang_name'] == "") ){
293 die($mod_strings['ERR_UW_NO_LANG']);
295 if( !isset($_REQUEST['new_lang_desc']) || ($_REQUEST['new_lang_desc'] == "") ){
296 die($mod_strings['ERR_UW_NO_LANG_DESC']);
299 if( $mode == "Install" || $mode=="Enable" ){
300 $sugar_config['languages'] = $sugar_config['languages'] + array( $_REQUEST['new_lang_name'] => $_REQUEST['new_lang_desc'] );
302 else if( $mode == "Uninstall" || $mode=="Disable" ){
303 $new_langs = array();
304 $old_langs = $sugar_config['languages'];
305 foreach( $old_langs as $key => $value ){
306 if( $key != $_REQUEST['new_lang_name'] ){
307 $new_langs += array( $key => $value );
310 $sugar_config['languages'] = $new_langs;
312 $default_sugar_instance_lang = 'en_us';
313 if($current_language == $_REQUEST['new_lang_name']){
314 $_SESSION['authenticated_user_language'] =$default_sugar_instance_lang;
315 $lang_changed_string = $mod_strings['LBL_CURRENT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
318 if($sugar_config['default_language'] == $_REQUEST['new_lang_name']){
319 $cfg = new Configurator();
320 $cfg->config['languages'] = $new_langs;
321 $cfg->config['default_language'] = $default_sugar_instance_lang;
322 $cfg->handleOverride();
323 $lang_changed_string .= $mod_strings['LBL_DEFAULT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
326 ksort( $sugar_config );
327 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){
328 die($mod_strings['ERR_UW_CONFIG_FAILED']);
332 require_once( "ModuleInstall/ModuleInstaller.php" );
333 $mi = new ModuleInstaller();
336 //here we can determine if this is an upgrade or a new version
337 if(!empty($previous_version)){
338 $mi->install( "$unzip_dir", true, $previous_version);
340 $mi->install( "$unzip_dir" );
343 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
346 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
352 if($remove_tables == 'false')
353 $GLOBALS['mi_remove_tables'] = false;
355 $GLOBALS['mi_remove_tables'] = true;
356 $mi->uninstall( "$unzip_dir" );
359 if(!$overwrite_files)
360 $GLOBALS['mi_overwrite_files'] = false;
362 $GLOBALS['mi_overwrite_files'] = true;
363 $mi->disable( "$unzip_dir" );
366 if(!$overwrite_files)
367 $GLOBALS['mi_overwrite_files'] = false;
369 $GLOBALS['mi_overwrite_files'] = true;
370 $mi->enable( "$unzip_dir" );
377 // purposely flow into "case: patch"
382 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
385 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
393 $file = "$unzip_dir/" . constant('SUGARCRM_POST_UNINSTALL_FILE');
395 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
400 if(is_dir($rest_dir))
402 rmdir_recursive($rest_dir);
411 require( "sugar_version.php" );
412 $sugar_config['sugar_version'] = $sugar_version;
413 ksort( $sugar_config );
415 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) )
417 die($mod_strings['ERR_UW_UPDATE_CONFIG']);
426 $file_action = "copied";
427 // if error was encountered, script should have died before now
428 $new_upgrade = new UpgradeHistory();
429 //determine if this module has already been installed given the unique_key to
430 //identify the module
431 // $new_upgrade->checkForExisting($unique_key);
432 if(!empty($previous_id)){
433 $new_upgrade->id = $previous_id;
434 $uh = new UpgradeHistory();
435 $uh->retrieve($previous_id);
436 if(is_file($uh->filename)) {
437 unlink($uh->filename);
440 $new_upgrade->filename = $install_file;
441 $new_upgrade->md5sum = md5_file( $install_file );
442 $new_upgrade->type = $install_type;
443 $new_upgrade->version = $version;
444 $new_upgrade->status = "installed";
445 $new_upgrade->name = $name;
446 $new_upgrade->description = $description;
447 $new_upgrade->id_name = $id_name;
448 $new_upgrade->manifest = $s_manifest;
449 $new_upgrade->save();
451 //Check if we need to show a page for the user to finalize their install with.
452 if (is_file("$unzip_dir/manifest.php"))
454 include("$unzip_dir/manifest.php");
455 if (!empty($manifest['post_install_url']))
457 $url_conf = $manifest['post_install_url'];
458 if (is_string($url_conf))
459 $url_conf = array('url' => $url_conf);
460 if (isset($url_conf['type']) && $url_conf['type'] == 'popup')
462 echo '<script type="text/javascript">window.open("' . $url_conf['url']
463 . '","' . (empty($url_conf['name']) ? 'sugar_popup' : $url_conf['name']) . '","'
464 . 'height=' . (empty($url_conf['height']) ? '500' : $url_conf['height']) . ','
465 . 'width=' . (empty($url_conf['width']) ? '800' : $url_conf['width']) . '");</script>';
468 echo '<iframe src="' . $url_conf['url'] . '" '
469 . 'width="' . (empty($url_conf['width']) ? '100%' : $url_conf['width']) . '" '
470 . 'height="' . (empty($url_conf['height']) ? '500px' : $url_conf['height']) . '"></iframe>';
476 $file_action = "removed";
477 $uh = new UpgradeHistory();
478 $the_md5 = md5_file( $install_file );
479 $md5_matches = $uh->findByMd5( $the_md5 );
480 if( sizeof( $md5_matches ) == 0 ){
481 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
483 foreach( $md5_matches as $md5_match ){
484 $md5_match->delete();
488 $file_action = "disabled";
489 $uh = new UpgradeHistory();
490 $the_md5 = md5_file( $install_file );
491 $md5_matches = $uh->findByMd5( $the_md5 );
492 if( sizeof( $md5_matches ) == 0 ){
493 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
495 foreach( $md5_matches as $md5_match ){
496 $md5_match->enabled = 0;
501 $file_action = "enabled";
502 $uh = new UpgradeHistory();
503 $the_md5 = md5_file( $install_file );
504 $md5_matches = $uh->findByMd5( $the_md5 );
505 if( sizeof( $md5_matches ) == 0 ){
506 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
508 foreach( $md5_matches as $md5_match ){
509 $md5_match->enabled = 1;
515 // present list to user
517 <form action="<?php print( $form_action ); ?>" method="post">
522 print( getUITextForType($install_type) . " ". getUITextForMode($mode) . " ". $mod_strings['LBL_UW_SUCCESSFULLY']);
525 print( "<input type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_MOD_LOADER']}\" /><br>" );
528 if(isset($lang_changed_string))
529 print($lang_changed_string);
530 if ($install_type != "module" && $install_type != "langpack"){
531 if( sizeof( $files_to_handle ) > 0 ){
532 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\'>
533 <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>';
534 print( "{$mod_strings['LBL_UW_FOLLOWING_FILES']} $file_action:<br>\n" );
535 print( "<ul id=\"subMenu\">\n" );
536 foreach( $files_to_handle as $file_to_copy ){
537 print( "<li>$file_to_copy<br>\n" );
542 else if( $mode != 'Disable' && $mode !='Enable' ){
543 print( "{$mod_strings['LBL_UW_NO_FILES_SELECTED']} $file_action.<br>\n" );
546 print($mod_strings['LBL_UW_UPGRADE_SUCCESSFUL']);
547 print( "<input class='button' type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_UW']}\" />\n" );
553 $GLOBALS['log']->info( "Upgrade Wizard patches" );