Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

modules/UpgradeWizard/silentUpgrade_step2.php (12 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 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 [email protected].
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
//// This is a stand alone file that can be run from the command prompt for upgrading a
41
//// Sugar Instance. Three parameters are required to be defined in order to execute this file.
42
//// php.exe -f silentUpgrade.php [Path to Upgrade Package zip] [Path to Log file] [Path to Instance]
43
//// See below the Usage for more details.
44
/////////////////////////////////////////////////////////////////////////////////////////
45
ini_set('memory_limit',-1);
46
///////////////////////////////////////////////////////////////////////////////
47
////	UTILITIES THAT MUST BE LOCAL :(
48
 //Bug 24890, 24892. default_permissions not written to config.php. Following function checks and if
49
 //no found then adds default_permissions to the config file.
50
 function checkConfigForPermissions(){
0 ignored issues
show
The function checkConfigForPermissions() has been defined more than once; this definition is ignored, only the first definition in modules/UpgradeWizard/silentUpgrade_dce_step1.php (L78-95) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
51
     if(file_exists(getcwd().'/config.php')){
52
         require(getcwd().'/config.php');
53
     }
54
     global $sugar_config;
55
     if(!isset($sugar_config['default_permissions'])){
56
             $sugar_config['default_permissions'] = array (
57
                     'dir_mode' => 02770,
58
                     'file_mode' => 0660,
59
                     'user' => '',
60
                     'group' => '',
61
             );
62
         ksort($sugar_config);
63
         if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
64
        	//writing to the file
65
 		}
66
     }
67
}
68
69
function checkLoggerSettings(){
0 ignored issues
show
The function checkLoggerSettings() has been defined more than once; this definition is ignored, only the first definition in modules/UpgradeWizard/silentUpgrade_dce_step1.php (L96-119) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
70
	if(file_exists(getcwd().'/config.php')){
71
         require(getcwd().'/config.php');
72
     }
73
    global $sugar_config;
74
	if(!isset($sugar_config['logger'])){
75
	    $sugar_config['logger'] =array (
76
			'level'=>'fatal',
77
		    'file' =>
78
		     array (
79
		      'ext' => '.log',
80
		      'name' => 'sugarcrm',
81
		      'dateFormat' => '%c',
82
		      'maxSize' => '10MB',
83
		      'maxLogs' => 10,
84
		      'suffix' => '', // bug51583, change default suffix to blank for backwards comptability
85
		    ),
86
		  );
87
		 ksort($sugar_config);
88
         if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
89
        	//writing to the file
90
 		}
91
	 }
92
}
93
94
function checkResourceSettings(){
0 ignored issues
show
The function checkResourceSettings() has been defined more than once; this definition is ignored, only the first definition in modules/UpgradeWizard/silentUpgrade_dce_step1.php (L121-145) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
95
	if(file_exists(getcwd().'/config.php')){
96
         require(getcwd().'/config.php');
97
     }
98
    global $sugar_config;
99
	if(!isset($sugar_config['resource_management'])){
100
	  $sugar_config['resource_management'] =
101
		  array (
102
		    'special_query_limit' => 50000,
103
		    'special_query_modules' =>
104
		    array (
105
		      0 => 'Reports',
106
		      1 => 'Export',
107
		      2 => 'Import',
108
		      3 => 'Administration',
109
		      4 => 'Sync',
110
		    ),
111
		    'default_limit' => 1000,
112
		  );
113
		 ksort($sugar_config);
114
         if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
115
        	//writing to the file
116
 		}
117
	}
118
}
119
120
121
function verifyArguments($argv,$usage_regular){
0 ignored issues
show
The function verifyArguments() has been defined more than once; this definition is ignored, only the first definition in modules/UpgradeWizard/silentUpgrade_dce_step1.php (L255-322) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
122
    $upgradeType = '';
123
    $cwd = getcwd(); // default to current, assumed to be in a valid SugarCRM root dir.
124
    if(isset($argv[3])) {
125
        if(is_dir($argv[3])) {
126
            $cwd = $argv[3];
127
            chdir($cwd);
128
        } else {
129
            echo "*******************************************************************************\n";
130
            echo "*** ERROR: 3rd parameter must be a valid directory.  Tried to cd to [ {$argv[3]} ].\n";
131
            exit(1);
132
        }
133
    }
134
135
    //check if this is an instance
136
    if(is_file("{$cwd}/include/entryPoint.php")) {
137
        //this should be a regular sugar install
138
        $upgradeType = constant('SUGARCRM_INSTALL');
139
        //check if this is a valid zip file
140
        if(!is_file($argv[1])) { // valid zip?
141
            echo "*******************************************************************************\n";
142
            echo "*** ERROR: First argument must be a full path to the patch file. Got [ {$argv[1]} ].\n";
143
            echo $usage_regular;
144
            echo "FAILURE\n";
145
            exit(1);
146
        }
147
        if(count($argv) < 5) {
148
            echo "*******************************************************************************\n";
149
            echo "*** ERROR: Missing required parameters.  Received ".count($argv)." argument(s), require 5.\n";
150
            echo $usage_regular;
151
            echo "FAILURE\n";
152
            exit(1);
153
        }
154
    }
155
    else {
156
        //this should be a regular sugar install
157
        echo "*******************************************************************************\n";
158
        echo "*** ERROR: Tried to execute in a non-SugarCRM root directory.\n";
159
        exit(1);
160
    }
161
162
    if(isset($argv[7]) && file_exists($argv[7].'SugarTemplateUtilties.php')){
163
        require_once($argv[7].'SugarTemplateUtilties.php');
164
    }
165
166
    return $upgradeType;
167
}
168
169
////	END UTILITIES THAT MUST BE LOCAL :(
170
///////////////////////////////////////////////////////////////////////////////
171
172
function rebuildRelations($pre_path = '')
0 ignored issues
show
The function rebuildRelations() has been defined more than once; this definition is ignored, only the first definition in modules/UpgradeWizard/silentUpgrade_dce_step1.php (L149-154) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
173
{
174
	$_REQUEST['silent'] = true;
175
	include($pre_path.'modules/Administration/RebuildRelationship.php');
176
	$_REQUEST['upgradeWizard'] = true;
177
	include($pre_path.'modules/ACL/install_actions.php');
178
}
179
180
//Bug 52872. Dies if the request does not come from CLI.
181
$sapi_type = php_sapi_name();
182
if (substr($sapi_type, 0, 3) != 'cli') {
183
    die("This is command-line only script");
184
}
185
//End of #52872
186
187
// only run from command line
188
if(isset($_SERVER['HTTP_USER_AGENT'])) {
189
	fwrite(STDERR,'This utility may only be run from the command line or command prompt.');
190
	exit(1);
191
}
192
//Clean_string cleans out any file  passed in as a parameter
193
$_SERVER['PHP_SELF'] = 'silentUpgrade.php';
194
195
196
///////////////////////////////////////////////////////////////////////////////
197
////	USAGE
198
$usage_regular =<<<eoq2
199
Usage: php.exe -f silentUpgrade.php [upgradeZipFile] [logFile] [pathToSugarInstance] [admin-user]
200
201
On Command Prompt Change directory to where silentUpgrade.php resides. Then type path to
202
php.exe followed by -f silentUpgrade.php and the arguments.
203
204
Example:
205
    [path-to-PHP/]php.exe -f silentUpgrade.php [path-to-upgrade-package/]SugarEnt-Upgrade-5.2.0-to-5.5.0.zip [path-to-log-file/]silentupgrade.log  [path-to-sugar-instance/] admin
206
207
Arguments:
208
    upgradeZipFile                       : Upgrade package file.
209
    logFile                              : Silent Upgarde log file.
210
    pathToSugarInstance                  : Sugar Instance instance being upgraded.
211
    admin-user                           : admin user performing the upgrade
212
eoq2;
213
////	END USAGE
214
///////////////////////////////////////////////////////////////////////////////
215
216
217
218
///////////////////////////////////////////////////////////////////////////////
219
////	STANDARD REQUIRED SUGAR INCLUDES AND PRESETS
220
if(!defined('sugarEntry')) define('sugarEntry', true);
221
222
$_SESSION = array();
223
$_SESSION['schema_change'] = 'sugar'; // we force-run all SQL
224
$_SESSION['silent_upgrade'] = true;
225
$_SESSION['step'] = 'silent'; // flag to NOT try redirect to 4.5.x upgrade wizard
226
227
$_REQUEST = array();
228
$_REQUEST['addTaskReminder'] = 'remind';
229
230
231
define('SUGARCRM_INSTALL', 'SugarCRM_Install');
232
define('DCE_INSTANCE', 'DCE_Instance');
233
234
global $cwd;
235
$cwd = getcwd(); // default to current, assumed to be in a valid SugarCRM root dir.
236
237
$upgradeType = verifyArguments($argv,$usage_regular);
0 ignored issues
show
The call to verifyArguments() misses a required argument $usage_regular.

This check looks for function calls that miss required arguments.

Loading history...
238
239
$path			= $argv[2]; // custom log file, if blank will use ./upgradeWizard.log
240
$subdirs		= array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
241
242
require_once('include/entryPoint.php');
243
require_once('modules/UpgradeWizard/uw_utils.php');
244
require_once('include/utils/zip_utils.php');
245
require_once('include/utils/sugar_file_utils.php');
246
require_once('include/SugarObjects/SugarConfig.php');
247
global $sugar_config;
248
$isDCEInstance = false;
249
$errors = array();
250
251
	require('config.php');
252
	if(isset($argv[3])) {
253
		if(is_dir($argv[3])) {
254
			$cwd = $argv[3];
255
			chdir($cwd);
256
		}
257
	}
258
259
	require_once("{$cwd}/sugar_version.php"); // provides $sugar_version & $sugar_flavor
260
261
	global $sugar_config;
262
	$configOptions = $sugar_config['dbconfig'];
263
264
    $GLOBALS['log']	= LoggerManager::getLogger('SugarCRM');
0 ignored issues
show
The call to LoggerManager::getLogger() has too many arguments starting with 'SugarCRM'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
265
	$patchName		= basename($argv[1]);
266
	$zip_from_dir	= substr($patchName, 0, strlen($patchName) - 4); // patch folder name (minus ".zip")
267
	$path			= $argv[2]; // custom log file, if blank will use ./upgradeWizard.log
268
    $db				= &DBManagerFactory::getInstance();
269
	$UWstrings		= return_module_language('en_us', 'UpgradeWizard', true);
270
	$adminStrings	= return_module_language('en_us', 'Administration', true);
271
    $app_list_strings = return_app_list_strings_language('en_us');
272
	$mod_strings	= array_merge($adminStrings, $UWstrings);
273
	$subdirs		= array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
274
	global $unzip_dir;
275
    $license_accepted = false;
276
    if(isset($argv[5]) && (strtolower($argv[5])=='yes' || strtolower($argv[5])=='y')){
277
    	$license_accepted = true;
278
	 }
279
	//////////////////////////////////////////////////////////////////////////////
280
	//Adding admin user to the silent upgrade
281
282
	$current_user = new User();
283
	if(isset($argv[4])) {
284
	   //if being used for internal upgrades avoid admin user verification
285
	   $user_name = $argv[4];
286
	   $q = "select id from users where user_name = '" . $user_name . "' and is_admin=1";
287
	   $result = $GLOBALS['db']->query($q, false);
288
	   $logged_user = $GLOBALS['db']->fetchByAssoc($result);
289
	   if(isset($logged_user['id']) && $logged_user['id'] != null){
290
		//do nothing
291
	    $current_user->retrieve($logged_user['id']);
292
	   }
293
	   else{
294
	   	echo "Not an admin user in users table. Please provide an admin user\n";
295
		exit(1);
296
	   }
297
	}
298
	else {
299
		echo "*******************************************************************************\n";
300
		echo "*** ERROR: 4th parameter must be a valid admin user.\n";
301
		echo $usage;
302
		echo "FAILURE\n";
303
		exit(1);
304
	}
305
306
/////retrieve admin user
307
308
$unzip_dir = sugar_cached("upgrades/temp");
309
$install_file = $sugar_config['upload_dir']."/upgrades/patch/".basename($argv[1]);
310
sugar_mkdir($sugar_config['upload_dir']."/upgrades/patch", 0775, true);
311
312
$_SESSION['unzip_dir'] = $unzip_dir;
313
$_SESSION['install_file'] = $install_file;
314
$_SESSION['zip_from_dir'] = $zip_from_dir;
315
316
mkdir_recursive($unzip_dir);
317
if(!is_dir($unzip_dir)) {
318
	fwrite(STDERR,"\n{$unzip_dir} is not an available directory\nFAILURE\n");
319
    exit(1);
320
}
321
unzip($argv[1], $unzip_dir);
322
// mimic standard UW by copy patch zip to appropriate dir
323
copy($argv[1], $install_file);
324
////	END UPGRADE PREP
325
///////////////////////////////////////////////////////////////////////////////
326
327
328
if(function_exists('set_upgrade_vars')){
329
	set_upgrade_vars();
330
}
331
332
///////////////////////////////////////////////////////////////////////////////
333
////	RUN SILENT UPGRADE
334
ob_start();
335
set_time_limit(0);
336
337
///    RELOAD NEW DEFINITIONS
338
global $ACLActions, $beanList, $beanFiles;
339
340
require_once('modules/Trackers/TrackerManager.php');
341
$trackerManager = TrackerManager::getInstance();
342
$trackerManager->pause();
343
$trackerManager->unsetMonitors();
344
345
include('modules/ACLActions/actiondefs.php');
346
include('include/modules.php');
347
348
require_once('modules/Administration/upgrade_custom_relationships.php');
349
upgrade_custom_relationships();
350
351
logThis('Upgrading user preferences start .', $path);
352
if(function_exists('upgradeUserPreferences')){
353
   upgradeUserPreferences();
354
}
355
logThis('Upgrading user preferences finish .', $path);
356
357
// clear out the theme cache
358
if(is_dir($GLOBALS['sugar_config']['cache_dir'].'themes')){
359
    $allModFiles = array();
360
    $allModFiles = findAllFiles($GLOBALS['sugar_config']['cache_dir'].'themes',$allModFiles);
361
    foreach($allModFiles as $file){
362
        //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
363
        if(file_exists($file)){
364
            unlink($file);
365
        }
366
    }
367
}
368
369
// re-minify the JS source files
370
$_REQUEST['root_directory'] = getcwd();
371
$_REQUEST['js_rebuild_concat'] = 'rebuild';
372
require_once('jssource/minify.php');
373
374
//Add the cache cleaning here.
375
if(function_exists('deleteCache'))
376
{
377
	logThis('Call deleteCache', $path);
378
	@deleteCache();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
379
}
380
/*
381
// creating full text search logic hooks
382
// this will be merged into application/Ext/LogicHooks/logichooks.ext.php
383
// when rebuild_extensions is called
384
logThis(' Writing FTS hooks');
385
if (!function_exists('createFTSLogicHook')) {
386
    $customFileLoc = create_custom_directory('Extension/application/Ext/LogicHooks/SugarFTSHooks.php');
387
    $fp = sugar_fopen($customFileLoc, 'wb');
388
    $contents = <<<CIA
389
<?php
390
if (!isset(\$hook_array) || !is_array(\$hook_array)) {
391
    \$hook_array = array();
392
}
393
if (!isset(\$hook_array['after_save']) || !is_array(\$hook_array['after_save'])) {
394
    \$hook_array['after_save'] = array();
395
}
396
\$hook_array['after_save'][] = array(1, 'fts', 'include/SugarSearchEngine/SugarSearchEngineQueueManager.php', 'SugarSearchEngineQueueManager', 'populateIndexQueue');
397
CIA;
398
399
    fwrite($fp,$contents);
400
    fclose($fp);
401
} else {
402
    createFTSLogicHook('Extension/application/Ext/LogicHooks/SugarFTSHooks.php');
403
}
404
*/
405
//First repair the databse to ensure it is up to date with the new vardefs/tabledefs
406
logThis('About to repair the database.', $path);
407
//Use Repair and rebuild to update the database.
408
global $dictionary;
409
require_once("modules/Administration/QuickRepairAndRebuild.php");
410
$rac = new RepairAndClear();
411
$rac->clearVardefs();
412
$rac->rebuildExtensions();
413
//bug: 44431 - defensive check to ensure the method exists since upgrades to 6.2.0 may not have this method define yet.
414
if(method_exists($rac, 'clearExternalAPICache'))
415
{
416
    $rac->clearExternalAPICache();
417
}
418
419
$repairedTables = array();
420
foreach ($beanFiles as $bean => $file) {
421
	if(file_exists($file)){
422
		unset($GLOBALS['dictionary'][$bean]);
423
		require_once($file);
424
		$focus = new $bean ();
425
		if(empty($focus->table_name) || isset($repairedTables[$focus->table_name])) {
426
		   continue;
427
		}
428
429
		if (($focus instanceOf SugarBean)) {
430
			if(!isset($repairedTables[$focus->table_name]))
431
			{
432
				$sql = $GLOBALS['db']->repairTable($focus, true);
433
                if(trim($sql) != '')
434
                {
435
				    logThis('Running sql:' . $sql, $path);
436
                }
437
				$repairedTables[$focus->table_name] = true;
438
			}
439
440
			//Check to see if we need to create the audit table
441
		    if($focus->is_AuditEnabled() && !$focus->db->tableExists($focus->get_audit_table_name())){
442
               logThis('Creating audit table:' . $focus->get_audit_table_name(), $path);
443
		       $focus->create_audit_table();
444
            }
445
		}
446
	}
447
}
448
449
unset ($dictionary);
450
include ("{$argv[3]}/modules/TableDictionary.php");
451
foreach ($dictionary as $meta) {
452
	$tablename = $meta['table'];
453
454
	if(isset($repairedTables[$tablename])) {
455
	   continue;
456
	}
457
458
	$fielddefs = $meta['fields'];
459
	$indices = $meta['indices'];
460
	$sql = $GLOBALS['db']->repairTableParams($tablename, $fielddefs, $indices, true);
461
	if(!empty($sql)) {
462
	    logThis($sql, $path);
463
	    $repairedTables[$tablename] = true;
464
	}
465
466
}
467
468
logThis('database repaired', $path);
469
470
logThis('Start rebuild relationships.', $path);
471
@rebuildRelations();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
472
logThis('End rebuild relationships.', $path);
473
474
include("$unzip_dir/manifest.php");
475
$ce_to_pro_ent = isset($manifest['name']) && ($manifest['name'] == 'SugarCE to SugarPro' || $manifest['name'] == 'SugarCE to SugarEnt'  || $manifest['name'] == 'SugarCE to SugarCorp' || $manifest['name'] == 'SugarCE to SugarUlt');
476
$sugar_version = getSilentUpgradeVar('origVersion');
477
if (!$sugar_version)
478
{
479
    global $silent_upgrade_vars_loaded;
480
    logThis("Error retrieving silent upgrade var for sugar_version: cache dir is {$GLOBALS['sugar_config']['cache_dir']} -- full cache for \$silent_upgrade_vars_loaded is ".var_export($silent_upgrade_vars_loaded, true), $path);
481
}
482
483
484
if($ce_to_pro_ent) {
485
	//add the global team if it does not exist
486
	$globalteam = new Team();
487
	$globalteam->retrieve('1');
488
	require_once($unzip_dir.'/'.$zip_from_dir.'/modules/Administration/language/en_us.lang.php');
489
	if(isset($globalteam->name)){
490
		echo 'Global '.$mod_strings['LBL_UPGRADE_TEAM_EXISTS'].'<br>';
491
		logThis(" Finish Building Global Team", $path);
492
	}else{
493
		$globalteam->create_team("Global", $mod_strings['LBL_GLOBAL_TEAM_DESC'], $globalteam->global_team);
494
	}
495
496
	logThis(" Start Building private teams", $path);
497
498
    upgradeModulesForTeam();
499
    logThis(" Finish Building private teams", $path);
500
501
    logThis(" Start Building the team_set and team_sets_teams", $path);
502
    upgradeModulesForTeamsets();
503
    logThis(" Finish Building the team_set and team_sets_teams", $path);
504
505
	logThis(" Start modules/Administration/upgradeTeams.php", $path);
506
        include('modules/Administration/upgradeTeams.php');
507
        logThis(" Finish modules/Administration/upgradeTeams.php", $path);
508
509
    if(check_FTS()){
510
    	$GLOBALS['db']->full_text_indexing_setup();
511
    }
512
}
513
514
//bug: 37214 - merge config_si.php settings if available
515
logThis('Begin merge_config_si_settings', $path);
516
merge_config_si_settings(true, '', '', $path);
517
logThis('End merge_config_si_settings', $path);
518
519
//Upgrade connectors
520
logThis('Begin upgrade_connectors', $path);
521
upgrade_connectors();
522
logThis('End upgrade_connectors', $path);
523
524
525
//Unlink files that have been removed
526
if(function_exists('unlinkUpgradeFiles'))
527
{
528
	unlinkUpgradeFiles($sugar_version);
529
}
530
531
if(function_exists('rebuildSprites') && function_exists('imagecreatetruecolor'))
532
{
533
    rebuildSprites(true);
534
}
535
536
//Run repairUpgradeHistoryTable
537
if (version_compare($sugar_version, '6.5.0', '<') && function_exists('repairUpgradeHistoryTable'))
538
{
539
    repairUpgradeHistoryTable();
540
}
541
542
///////////////////////////////////////////////////////////////////////////////
543
////	TAKE OUT TRASH
544
if(empty($errors)) {
545
	set_upgrade_progress('end','in_progress','unlinkingfiles','in_progress');
546
	logThis('Taking out the trash, unlinking temp files.', $path);
547
	unlinkUWTempFiles();
548
	removeSilentUpgradeVarsCache();
549
	logThis('Taking out the trash, done.', $path);
550
}
551
552
///////////////////////////////////////////////////////////////////////////////
553
////	RECORD ERRORS
554
555
$phpErrors = ob_get_contents();
556
ob_end_clean();
557
logThis("**** Potential PHP generated error messages: {$phpErrors}", $path);
558
559
if(count($errors) > 0) {
560
	foreach($errors as $error) {
561
		logThis("****** SilentUpgrade ERROR: {$error}", $path);
562
	}
563
	echo "FAILED\n";
564
} else {
565
	logThis("***** SilentUpgrade completed successfully.", $path);
566
	echo "********************************************************************\n";
567
	echo "*************************** SUCCESS*********************************\n";
568
	echo "********************************************************************\n";
569
	echo "******** If your pre-upgrade Leads data is not showing  ************\n";
570
	echo "******** Or you see errors in detailview subpanels  ****************\n";
571
	echo "************* In order to resolve them  ****************************\n";
572
	echo "******** Log into application as Administrator  ********************\n";
573
	echo "******** Go to Admin panel  ****************************************\n";
574
	echo "******** Run Repair -> Rebuild Relationships  **********************\n";
575
	echo "********************************************************************\n";
576
}
577