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.
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();
209 if(!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan']) && $install_type != 'patch'){
210 require_once('ModuleInstall/ModuleScanner.php');
211 $ms = new ModuleScanner();
212 $ms->scanPackage($unzip_dir);
213 if($ms->hasIssues()){
214 $ms->displayIssues();
220 // execute the PRE scripts
222 if($install_type == 'patch' || $install_type == 'module')
227 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
230 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
236 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_UNINSTALL_FILE');
239 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
250 // perform the action
253 for( $iii = 0; $iii < $_REQUEST['copy_count']; $iii++ ){
254 if( isset($_REQUEST["copy_" . $iii]) && ($_REQUEST["copy_" . $iii] != "") ){
255 $file_to_copy = $_REQUEST["copy_" . $iii];
256 $src_file = clean_path( "$unzip_dir/$zip_from_dir/$file_to_copy" );
258 $sugar_home_dir = getCwd();
259 $dest_file = clean_path( "$sugar_home_dir/$zip_to_dir/$file_to_copy" );
260 if($zip_to_dir != '.')
261 $rest_file = clean_path("$rest_dir/$zip_to_dir/$file_to_copy");
263 $rest_file = clean_path("$rest_dir/$file_to_copy");
267 mkdir_recursive( dirname( $dest_file ) );
269 if($install_type=="patch" && is_file($dest_file))
271 if(!is_dir(dirname( $rest_file )))
272 mkdir_recursive( dirname( $rest_file ) );
274 copy( $dest_file, $rest_file);
275 sugar_touch( $rest_file, filemtime($dest_file) );
278 if( !copy( $src_file, $dest_file ) ){
279 die( $mod_strings['ERR_UW_COPY_FAILED'].$src_file.$mod_strings['LBL_TO'].$dest_file);
281 $uh_status = "installed";
284 if($install_type=="patch" && is_file($rest_file))
286 copy( $rest_file, $dest_file);
287 sugar_touch( $dest_file, filemtime($rest_file) );
289 elseif(file_exists($dest_file) && !unlink($dest_file))
291 die($mod_strings['ERR_UW_REMOVE_FAILED'].$dest_file);
293 $uh_status = "uninstalled";
296 die("{$mod_strings['LBL_UW_OP_MODE']} '$mode' {$mod_strings['ERR_UW_NOT_RECOGNIZED']}." );
298 $files_to_handle[] = clean_path( "$zip_to_dir/$file_to_copy" );
302 switch( $install_type ){
304 if( !isset($_REQUEST['new_lang_name']) || ($_REQUEST['new_lang_name'] == "") ){
305 die($mod_strings['ERR_UW_NO_LANG']);
307 if( !isset($_REQUEST['new_lang_desc']) || ($_REQUEST['new_lang_desc'] == "") ){
308 die($mod_strings['ERR_UW_NO_LANG_DESC']);
311 if( $mode == "Install" || $mode=="Enable" ){
312 $sugar_config['languages'] = $sugar_config['languages'] + array( $_REQUEST['new_lang_name'] => $_REQUEST['new_lang_desc'] );
314 else if( $mode == "Uninstall" || $mode=="Disable" ){
315 $new_langs = array();
316 $old_langs = $sugar_config['languages'];
317 foreach( $old_langs as $key => $value ){
318 if( $key != $_REQUEST['new_lang_name'] ){
319 $new_langs += array( $key => $value );
322 $sugar_config['languages'] = $new_langs;
324 $default_sugar_instance_lang = 'en_us';
325 if($current_language == $_REQUEST['new_lang_name']){
326 $_SESSION['authenticated_user_language'] =$default_sugar_instance_lang;
327 $lang_changed_string = $mod_strings['LBL_CURRENT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
330 if($sugar_config['default_language'] == $_REQUEST['new_lang_name']){
331 $cfg = new Configurator();
332 $cfg->config['languages'] = $new_langs;
333 $cfg->config['default_language'] = $default_sugar_instance_lang;
334 $cfg->handleOverride();
335 $lang_changed_string .= $mod_strings['LBL_DEFAULT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
338 ksort( $sugar_config );
339 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){
340 die($mod_strings['ERR_UW_CONFIG_FAILED']);
344 require_once( "ModuleInstall/ModuleInstaller.php" );
345 $mi = new ModuleInstaller();
348 //here we can determine if this is an upgrade or a new version
349 if(!empty($previous_version)){
350 $mi->install( "$unzip_dir", true, $previous_version);
352 $mi->install( "$unzip_dir" );
355 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
358 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
364 if($remove_tables == 'false')
365 $GLOBALS['mi_remove_tables'] = false;
367 $GLOBALS['mi_remove_tables'] = true;
368 $mi->uninstall( "$unzip_dir" );
371 if(!$overwrite_files)
372 $GLOBALS['mi_overwrite_files'] = false;
374 $GLOBALS['mi_overwrite_files'] = true;
375 $mi->disable( "$unzip_dir" );
378 if(!$overwrite_files)
379 $GLOBALS['mi_overwrite_files'] = false;
381 $GLOBALS['mi_overwrite_files'] = true;
382 $mi->enable( "$unzip_dir" );
389 // purposely flow into "case: patch"
394 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
397 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
405 $file = "$unzip_dir/" . constant('SUGARCRM_POST_UNINSTALL_FILE');
407 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
412 if(is_dir($rest_dir))
414 rmdir_recursive($rest_dir);
423 require( "sugar_version.php" );
424 $sugar_config['sugar_version'] = $sugar_version;
425 ksort( $sugar_config );
427 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) )
429 die($mod_strings['ERR_UW_UPDATE_CONFIG']);
438 $file_action = "copied";
439 // if error was encountered, script should have died before now
440 $new_upgrade = new UpgradeHistory();
441 //determine if this module has already been installed given the unique_key to
442 //identify the module
443 // $new_upgrade->checkForExisting($unique_key);
444 if(!empty($previous_id)){
445 $new_upgrade->id = $previous_id;
446 $uh = new UpgradeHistory();
447 $uh->retrieve($previous_id);
448 if(is_file($uh->filename)) {
449 unlink($uh->filename);
452 $new_upgrade->filename = $install_file;
453 $new_upgrade->md5sum = md5_file( $install_file );
454 $new_upgrade->type = $install_type;
455 $new_upgrade->version = $version;
456 $new_upgrade->status = "installed";
457 $new_upgrade->name = $name;
458 $new_upgrade->description = $description;
459 $new_upgrade->id_name = $id_name;
460 $new_upgrade->manifest = $s_manifest;
461 $new_upgrade->save();
463 //Check if we need to show a page for the user to finalize their install with.
464 if (is_file("$unzip_dir/manifest.php"))
466 include("$unzip_dir/manifest.php");
467 if (!empty($manifest['post_install_url']))
469 $url_conf = $manifest['post_install_url'];
470 if (is_string($url_conf))
471 $url_conf = array('url' => $url_conf);
472 if (isset($url_conf['type']) && $url_conf['type'] == 'popup')
474 echo '<script type="text/javascript">window.open("' . $url_conf['url']
475 . '","' . (empty($url_conf['name']) ? 'sugar_popup' : $url_conf['name']) . '","'
476 . 'height=' . (empty($url_conf['height']) ? '500' : $url_conf['height']) . ','
477 . 'width=' . (empty($url_conf['width']) ? '800' : $url_conf['width']) . '");</script>';
480 echo '<iframe src="' . $url_conf['url'] . '" '
481 . 'width="' . (empty($url_conf['width']) ? '100%' : $url_conf['width']) . '" '
482 . 'height="' . (empty($url_conf['height']) ? '500px' : $url_conf['height']) . '"></iframe>';
488 $file_action = "removed";
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->delete();
500 $file_action = "disabled";
501 $uh = new UpgradeHistory();
502 $the_md5 = md5_file( $install_file );
503 $md5_matches = $uh->findByMd5( $the_md5 );
504 if( sizeof( $md5_matches ) == 0 ){
505 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
507 foreach( $md5_matches as $md5_match ){
508 $md5_match->enabled = 0;
513 $file_action = "enabled";
514 $uh = new UpgradeHistory();
515 $the_md5 = md5_file( $install_file );
516 $md5_matches = $uh->findByMd5( $the_md5 );
517 if( sizeof( $md5_matches ) == 0 ){
518 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
520 foreach( $md5_matches as $md5_match ){
521 $md5_match->enabled = 1;
527 // present list to user
529 <form action="<?php print( $form_action ); ?>" method="post">
534 print( getUITextForType($install_type) . " ". getUITextForMode($mode) . " ". $mod_strings['LBL_UW_SUCCESSFULLY']);
537 print( "<input type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_MOD_LOADER']}\" /><br>" );
540 if(isset($lang_changed_string))
541 print($lang_changed_string);
542 if ($install_type != "module" && $install_type != "langpack"){
543 if( sizeof( $files_to_handle ) > 0 ){
544 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\'>
545 <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>';
546 print( "{$mod_strings['LBL_UW_FOLLOWING_FILES']} $file_action:<br>\n" );
547 print( "<ul id=\"subMenu\">\n" );
548 foreach( $files_to_handle as $file_to_copy ){
549 print( "<li>$file_to_copy<br>\n" );
554 else if( $mode != 'Disable' && $mode !='Enable' ){
555 print( "{$mod_strings['LBL_UW_NO_FILES_SELECTED']} $file_action.<br>\n" );
558 print($mod_strings['LBL_UW_UPGRADE_SUCCESSFUL']);
559 print( "<input class='button' type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_UW']}\" />\n" );
565 $GLOBALS['log']->info( "Upgrade Wizard patches" );