2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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() {
43 $log =& $GLOBALS['log'];
44 $db =& $GLOBALS['db'];
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 = gmdate($GLOBALS['timedate']->get_db_date_time_format());
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']);
109 $log =& $GLOBALS['log'];
110 $db =& $GLOBALS['db'];
113 if( !isset($_REQUEST['mode']) || ($_REQUEST['mode'] == "") ){
114 die($mod_strings['ERR_UW_NO_MODE']);
116 $mode = $_REQUEST['mode'];
119 if( !isset($_REQUEST['version']) ){
120 die($mod_strings['ERR_UW_NO_MODE']);
122 $version = $_REQUEST['version'];
124 if( !isset($_REQUEST['copy_count']) || ($_REQUEST['copy_count'] == "") ){
125 die($mod_strings['ERR_UW_NO_FILES']);
128 if( !isset($_REQUEST['unzip_dir']) || ($_REQUEST['unzip_dir'] == "") ){
129 die($mod_strings['ERR_UW_NO_TEMP_DIR']);
131 $unzip_dir = $_REQUEST['unzip_dir'];
133 if(empty($_REQUEST['install_file'])){
134 die($mod_strings['ERR_UW_NO_INSTALL_FILE']);
137 $install_file = hashToFile($_REQUEST['install_file'] );
138 $install_type = getInstallType( $install_file );
140 if(isset($_REQUEST['id_name'])){
141 $id_name = $_REQUEST['id_name'];
144 if(isset($_REQUEST['s_manifest'])){
145 $s_manifest = $_REQUEST['s_manifest'];
147 $previous_version = '';
148 if(isset($_REQUEST['previous_version'])){
149 $previous_version = $_REQUEST['previous_version'];
152 if(isset($_REQUEST['previous_id'])){
153 $previous_id = $_REQUEST['previous_id'];
155 if( $install_type != "module" ){
156 if( !isset($_REQUEST['zip_from_dir']) || ($_REQUEST['zip_from_dir'] == "") ){
160 $zip_from_dir = $_REQUEST['zip_from_dir'];
162 if( !isset($_REQUEST['zip_to_dir']) || ($_REQUEST['zip_to_dir'] == "") ){
166 $zip_to_dir = $_REQUEST['zip_to_dir'];
169 $remove_tables = 'true';
170 if(isset($_REQUEST['remove_tables'])){
171 $remove_tables = $_REQUEST['remove_tables'];
173 $overwrite_files = true;
174 if(isset($_REQUEST['radio_overwrite'])){
175 $overwrite_files = (($_REQUEST['radio_overwrite'] == 'do_not_overwrite') ? false : true);
180 $is_uninstallable = true;
184 if($install_type == 'module'){
185 $is_uninstallable = $_REQUEST['is_uninstallable'];
186 $name = $_REQUEST['name'];
187 $description = $_REQUEST['description'];
194 $rest_dir = clean_path( remove_file_extension($install_file)."-restore");
196 $files_to_handle = array();
198 if(!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan']) && $install_type != 'patch'){
199 require_once('ModuleInstall/ModuleScanner.php');
200 $ms = new ModuleScanner();
201 $ms->scanPackage($unzip_dir);
202 if($ms->hasIssues()){
203 $ms->displayIssues();
209 // execute the PRE scripts
211 if($install_type == 'patch' || $install_type == 'module')
216 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_INSTALL_FILE');
219 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
225 $file = "$unzip_dir/" . constant('SUGARCRM_PRE_UNINSTALL_FILE');
228 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
239 // perform the action
242 for( $iii = 0; $iii < $_REQUEST['copy_count']; $iii++ ){
243 if( isset($_REQUEST["copy_" . $iii]) && ($_REQUEST["copy_" . $iii] != "") ){
244 $file_to_copy = $_REQUEST["copy_" . $iii];
245 $src_file = clean_path( "$unzip_dir/$zip_from_dir/$file_to_copy" );
247 $sugar_home_dir = getCwd();
248 $dest_file = clean_path( "$sugar_home_dir/$zip_to_dir/$file_to_copy" );
249 if($zip_to_dir != '.')
250 $rest_file = clean_path("$rest_dir/$zip_to_dir/$file_to_copy");
252 $rest_file = clean_path("$rest_dir/$file_to_copy");
256 mkdir_recursive( dirname( $dest_file ) );
258 if($install_type=="patch" && is_file($dest_file))
260 if(!is_dir(dirname( $rest_file )))
261 mkdir_recursive( dirname( $rest_file ) );
263 copy( $dest_file, $rest_file);
264 sugar_touch( $rest_file, filemtime($dest_file) );
267 if( !copy( $src_file, $dest_file ) ){
268 die( $mod_strings['ERR_UW_COPY_FAILED'].$src_file.$mod_strings['LBL_TO'].$dest_file);
270 $uh_status = "installed";
273 if($install_type=="patch" && is_file($rest_file))
275 copy( $rest_file, $dest_file);
276 sugar_touch( $dest_file, filemtime($rest_file) );
278 elseif(file_exists($dest_file) && !unlink($dest_file))
280 die($mod_strings['ERR_UW_REMOVE_FAILED'].$dest_file);
282 $uh_status = "uninstalled";
285 die("{$mod_strings['LBL_UW_OP_MODE']} '$mode' {$mod_strings['ERR_UW_NOT_RECOGNIZED']}." );
287 $files_to_handle[] = clean_path( "$zip_to_dir/$file_to_copy" );
291 switch( $install_type ){
293 if( !isset($_REQUEST['new_lang_name']) || ($_REQUEST['new_lang_name'] == "") ){
294 die($mod_strings['ERR_UW_NO_LANG']);
296 if( !isset($_REQUEST['new_lang_desc']) || ($_REQUEST['new_lang_desc'] == "") ){
297 die($mod_strings['ERR_UW_NO_LANG_DESC']);
300 if( $mode == "Install" || $mode=="Enable" ){
301 $sugar_config['languages'] = $sugar_config['languages'] + array( $_REQUEST['new_lang_name'] => $_REQUEST['new_lang_desc'] );
303 else if( $mode == "Uninstall" || $mode=="Disable" ){
304 $new_langs = array();
305 $old_langs = $sugar_config['languages'];
306 foreach( $old_langs as $key => $value ){
307 if( $key != $_REQUEST['new_lang_name'] ){
308 $new_langs += array( $key => $value );
311 $sugar_config['languages'] = $new_langs;
313 $default_sugar_instance_lang = 'en_us';
314 if($current_language == $_REQUEST['new_lang_name']){
315 $_SESSION['authenticated_user_language'] =$default_sugar_instance_lang;
316 $lang_changed_string = $mod_strings['LBL_CURRENT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
319 if($sugar_config['default_language'] == $_REQUEST['new_lang_name']){
320 $cfg = new Configurator();
321 $cfg->config['languages'] = $new_langs;
322 $cfg->config['default_language'] = $default_sugar_instance_lang;
323 $cfg->handleOverride();
324 $lang_changed_string .= $mod_strings['LBL_DEFAULT_LANGUAGE_CHANGE'].$sugar_config['languages'][$default_sugar_instance_lang].'<br/>';
327 ksort( $sugar_config );
328 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){
329 die($mod_strings['ERR_UW_CONFIG_FAILED']);
333 require_once( "ModuleInstall/ModuleInstaller.php" );
334 $mi = new ModuleInstaller();
337 //here we can determine if this is an upgrade or a new version
338 if(!empty($previous_version)){
339 $mi->install( "$unzip_dir", true, $previous_version);
341 $mi->install( "$unzip_dir" );
344 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
347 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
353 if($remove_tables == 'false')
354 $GLOBALS['mi_remove_tables'] = false;
356 $GLOBALS['mi_remove_tables'] = true;
357 $mi->uninstall( "$unzip_dir" );
360 if(!$overwrite_files)
361 $GLOBALS['mi_overwrite_files'] = false;
363 $GLOBALS['mi_overwrite_files'] = true;
364 $mi->disable( "$unzip_dir" );
367 if(!$overwrite_files)
368 $GLOBALS['mi_overwrite_files'] = false;
370 $GLOBALS['mi_overwrite_files'] = true;
371 $mi->enable( "$unzip_dir" );
378 // purposely flow into "case: patch"
383 $file = "$unzip_dir/" . constant('SUGARCRM_POST_INSTALL_FILE');
386 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
394 $file = "$unzip_dir/" . constant('SUGARCRM_POST_UNINSTALL_FILE');
396 print("{$mod_strings['LBL_UW_INCLUDING']}: $file <br>\n");
401 if(is_dir($rest_dir))
403 rmdir_recursive($rest_dir);
412 require( "sugar_version.php" );
413 $sugar_config['sugar_version'] = $sugar_version;
414 ksort( $sugar_config );
416 if( !write_array_to_file( "sugar_config", $sugar_config, "config.php" ) )
418 die($mod_strings['ERR_UW_UPDATE_CONFIG']);
427 $file_action = "copied";
428 // if error was encountered, script should have died before now
429 $new_upgrade = new UpgradeHistory();
430 //determine if this module has already been installed given the unique_key to
431 //identify the module
432 // $new_upgrade->checkForExisting($unique_key);
433 if(!empty($previous_id)){
434 $new_upgrade->id = $previous_id;
435 $uh = new UpgradeHistory();
436 $uh->retrieve($previous_id);
437 if(is_file($uh->filename)) {
438 unlink($uh->filename);
441 $new_upgrade->filename = $install_file;
442 $new_upgrade->md5sum = md5_file( $install_file );
443 $new_upgrade->type = $install_type;
444 $new_upgrade->version = $version;
445 $new_upgrade->status = "installed";
446 $new_upgrade->name = $name;
447 $new_upgrade->description = $description;
448 $new_upgrade->id_name = $id_name;
449 $new_upgrade->manifest = $s_manifest;
450 $new_upgrade->save();
452 //Check if we need to show a page for the user to finalize their install with.
453 if (is_file("$unzip_dir/manifest.php"))
455 include("$unzip_dir/manifest.php");
456 if (!empty($manifest['post_install_url']))
458 $url_conf = $manifest['post_install_url'];
459 if (is_string($url_conf))
460 $url_conf = array('url' => $url_conf);
461 if (isset($url_conf['type']) && $url_conf['type'] == 'popup')
463 echo '<script type="text/javascript">window.open("' . $url_conf['url']
464 . '","' . (empty($url_conf['name']) ? 'sugar_popup' : $url_conf['name']) . '","'
465 . 'height=' . (empty($url_conf['height']) ? '500' : $url_conf['height']) . ','
466 . 'width=' . (empty($url_conf['width']) ? '800' : $url_conf['width']) . '");</script>';
469 echo '<iframe src="' . $url_conf['url'] . '" '
470 . 'width="' . (empty($url_conf['width']) ? '100%' : $url_conf['width']) . '" '
471 . 'height="' . (empty($url_conf['height']) ? '500px' : $url_conf['height']) . '"></iframe>';
477 $file_action = "removed";
478 $uh = new UpgradeHistory();
479 $the_md5 = md5_file( $install_file );
480 $md5_matches = $uh->findByMd5( $the_md5 );
481 if( sizeof( $md5_matches ) == 0 ){
482 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
484 foreach( $md5_matches as $md5_match ){
485 $md5_match->delete();
489 $file_action = "disabled";
490 $uh = new UpgradeHistory();
491 $the_md5 = md5_file( $install_file );
492 $md5_matches = $uh->findByMd5( $the_md5 );
493 if( sizeof( $md5_matches ) == 0 ){
494 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
496 foreach( $md5_matches as $md5_match ){
497 $md5_match->enabled = 0;
502 $file_action = "enabled";
503 $uh = new UpgradeHistory();
504 $the_md5 = md5_file( $install_file );
505 $md5_matches = $uh->findByMd5( $the_md5 );
506 if( sizeof( $md5_matches ) == 0 ){
507 die( "{$mod_strings['ERR_UW_NO_UPDATE_RECORD']} $install_file." );
509 foreach( $md5_matches as $md5_match ){
510 $md5_match->enabled = 1;
516 // present list to user
518 <form action="<?php print( $form_action ); ?>" method="post">
523 print( getUITextForType($install_type) . " ". getUITextForMode($mode) . " ". $mod_strings['LBL_UW_SUCCESSFULLY']);
526 print( "<input type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_MOD_LOADER']}\" /><br>" );
529 if(isset($lang_changed_string))
530 print($lang_changed_string);
531 if ($install_type != "module" && $install_type != "langpack"){
532 if( sizeof( $files_to_handle ) > 0 ){
533 echo '<div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;" onclick=\'this.style.display="none"; toggleDisplay("more");\' id="all_text"><img src="'.SugarThemeRegistry::current()->getImageURL('advanced_search.gif').'"> Show Details</div><div id=\'more\' style=\'display: none\'>
534 <div style="text-align: left; cursor: hand; cursor: pointer; text-decoration: underline;" onclick=\'document.getElementById("all_text").style.display=""; toggleDisplay("more");\'><img name="options" src="'.SugarThemeRegistry::current()->getImageURL('basic_search.gif').'"> Hide Details</div><br>';
535 print( "{$mod_strings['LBL_UW_FOLLOWING_FILES']} $file_action:<br>\n" );
536 print( "<ul id=\"subMenu\">\n" );
537 foreach( $files_to_handle as $file_to_copy ){
538 print( "<li>$file_to_copy<br>\n" );
543 else if( $mode != 'Disable' && $mode !='Enable' ){
544 print( "{$mod_strings['LBL_UW_NO_FILES_SELECTED']} $file_action.<br>\n" );
547 print($mod_strings['LBL_UW_UPGRADE_SUCCESSFUL']);
548 print( "<input class='button' type=submit value=\"{$mod_strings['LBL_UW_BTN_BACK_TO_UW']}\" />\n" );
554 $GLOBALS['log']->info( "Upgrade Wizard patches" );