02770, 'file_mode' => 0660, 'user' => '', 'group' => '', ); ksort($sugar_config); if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) { //writing to the file } } } function checkLoggerSettings(){ if(file_exists(getcwd().'/config.php')){ require(getcwd().'/config.php'); } global $sugar_config; if(!isset($sugar_config['logger'])){ $sugar_config['logger'] =array ( 'level'=>'fatal', 'file' => array ( 'ext' => '.log', 'name' => 'sugarcrm', 'dateFormat' => '%c', 'maxSize' => '10MB', 'maxLogs' => 10, 'suffix' => '%m_%Y', ), ); ksort($sugar_config); if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) { //writing to the file } } } function checkResourceSettings(){ if(file_exists(getcwd().'/config.php')){ require(getcwd().'/config.php'); } global $sugar_config; if(!isset($sugar_config['resource_management'])){ $sugar_config['resource_management'] = array ( 'special_query_limit' => 50000, 'special_query_modules' => array ( 0 => 'Reports', 1 => 'Export', 2 => 'Import', 3 => 'Administration', 4 => 'Sync', ), 'default_limit' => 1000, ); ksort($sugar_config); if(is_writable('config.php') && write_array_to_file("sugar_config", $sugar_config,'config.php')) { //writing to the file } } } //rebuild all relationships... function rebuildRelations($pre_path = ''){ $_REQUEST['silent'] = true; include($pre_path.'modules/Administration/RebuildRelationship.php'); $_REQUEST['upgradeWizard'] = true; include($pre_path.'modules/ACL/install_actions.php'); } function createMissingRels(){ $relForObjects = array('leads'=>'Leads','campaigns'=>'Campaigns','prospects'=>'Prospects'); foreach($relForObjects as $relObjName=>$relModName){ //assigned_user $guid = create_guid(); $query = "SELECT id FROM relationships WHERE relationship_name = '{$relObjName}_assigned_user'"; $result= $GLOBALS['db']->query($query, true); $a = null; $a = $GLOBALS['db']->fetchByAssoc($result); if($GLOBALS['db']->checkError()){ //log this } if(!isset($a['id']) && empty($a['id']) ){ $qRel = "INSERT INTO relationships (id,relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, relationship_role_column, relationship_role_column_value, reverse, deleted) VALUES ('{$guid}', '{$relObjName}_assigned_user','Users','users','id','{$relModName}','{$relObjName}','assigned_user_id',NULL,NULL,NULL,'one-to-many',NULL,NULL,'0','0')"; $GLOBALS['db']->query($qRel); if($GLOBALS['db']->checkError()){ //log this } } //modified_user $guid = create_guid(); $query = "SELECT id FROM relationships WHERE relationship_name = '{$relObjName}_modified_user'"; $result= $GLOBALS['db']->query($query, true); if($GLOBALS['db']->checkError()){ //log this } $a = null; $a = $GLOBALS['db']->fetchByAssoc($result); if(!isset($a['id']) && empty($a['id']) ){ $qRel = "INSERT INTO relationships (id,relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, relationship_role_column, relationship_role_column_value, reverse, deleted) VALUES ('{$guid}', '{$relObjName}_modified_user','Users','users','id','{$relModName}','{$relObjName}','modified_user_id',NULL,NULL,NULL,'one-to-many',NULL,NULL,'0','0')"; $GLOBALS['db']->query($qRel); if($GLOBALS['db']->checkError()){ //log this } } //created_by $guid = create_guid(); $query = "SELECT id FROM relationships WHERE relationship_name = '{$relObjName}_created_by'"; $result= $GLOBALS['db']->query($query, true); $a = null; $a = $GLOBALS['db']->fetchByAssoc($result); if(!isset($a['id']) && empty($a['id']) ){ $qRel = "INSERT INTO relationships (id,relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, relationship_role_column, relationship_role_column_value, reverse, deleted) VALUES ('{$guid}', '{$relObjName}_created_by','Users','users','id','{$relModName}','{$relObjName}','created_by',NULL,NULL,NULL,'one-to-many',NULL,NULL,'0','0')"; $GLOBALS['db']->query($qRel); if($GLOBALS['db']->checkError()){ //log this } } } //Also add tracker perf relationship } /** * This function will merge password default settings into config file * @param $sugar_config * @param $sugar_version * @return bool true if successful */ function merge_passwordsetting($sugar_config, $sugar_version) { $passwordsetting_defaults = array( 'passwordsetting' => array ( 'SystemGeneratedPasswordON' => '', 'generatepasswordtmpl' => '', 'lostpasswordtmpl' => '', 'forgotpasswordON' => false, 'linkexpiration' => '1', 'linkexpirationtime' => '30', 'linkexpirationtype' => '1', 'systexpiration' => '0', 'systexpirationtime' => '', 'systexpirationtype' => '0', 'systexpirationlogin' => '', ) , ); $sugar_config = sugarArrayMerge($passwordsetting_defaults, $sugar_config ); // need to override version with default no matter what $sugar_config['sugar_version'] = $sugar_version; ksort( $sugar_config ); if( write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){ return true; } else { return false; } } function addDefaultModuleRoles($defaultRoles = array()) { foreach($defaultRoles as $roleName=>$role){ foreach($role as $category=>$actions){ foreach($actions as $name=>$access_override){ $query = "SELECT * FROM acl_actions WHERE name='$name' AND category = '$category' AND acltype='$roleName' AND deleted=0 "; $result = $GLOBALS['db']->query($query); //only add if an action with that name and category don't exist $row=$GLOBALS['db']->fetchByAssoc($result); if ($row == null) { $guid = create_guid(); $currdate = gmdate($GLOBALS['timedate']->get_db_date_time_format()); $query= "INSERT INTO acl_actions (id,date_entered,date_modified,modified_user_id,name,category,acltype,aclaccess,deleted ) VALUES ('$guid','$currdate','$currdate','1','$name','$category','$roleName','$access_override','0')"; $GLOBALS['db']->query($query); if($GLOBALS['db']->checkError()){ //log this } } } } } } function verifyArguments($argv,$usage_dce,$usage_regular){ $upgradeType = ''; $cwd = getcwd(); // default to current, assumed to be in a valid SugarCRM root dir. if(isset($argv[3])) { if(is_dir($argv[3])) { $cwd = $argv[3]; chdir($cwd); } else { echo "*******************************************************************************\n"; echo "*** ERROR: 3rd parameter must be a valid directory. Tried to cd to [ {$argv[3]} ].\n"; exit(1); } } //check if this is an instance if(is_file("{$cwd}/ini_setup.php")){ // this is an instance $upgradeType = constant('DCE_INSTANCE'); //now that this is dce instance we want to make sure that there are // 7 arguments if(count($argv) < 7) { echo "*******************************************************************************\n"; echo "*** ERROR: Missing required parameters. Received ".count($argv)." argument(s), require 7.\n"; echo $usage_dce; echo "FAILURE\n"; exit(1); } // this is an instance if(!is_dir($argv[1])) { // valid directory . template path? echo "*******************************************************************************\n"; echo "*** ERROR: First argument must be a full path to the template. Got [ {$argv[1]} ].\n"; echo $usage_dce; echo "FAILURE\n"; exit(1); } } else if(is_file("{$cwd}/include/entryPoint.php")) { //this should be a regular sugar install $upgradeType = constant('SUGARCRM_INSTALL'); //check if this is a valid zip file if(!is_file($argv[1])) { // valid zip? echo "*******************************************************************************\n"; echo "*** ERROR: First argument must be a full path to the patch file. Got [ {$argv[1]} ].\n"; echo $usage_regular; echo "FAILURE\n"; exit(1); } if(count($argv) < 5) { echo "*******************************************************************************\n"; echo "*** ERROR: Missing required parameters. Received ".count($argv)." argument(s), require 5.\n"; echo $usage_regular; echo "FAILURE\n"; exit(1); } } else { //this should be a regular sugar install echo "*******************************************************************************\n"; echo "*** ERROR: Tried to execute in a non-SugarCRM root directory.\n"; exit(1); } if(isset($argv[7]) && file_exists($argv[7].'SugarTemplateUtilties.php')){ require_once($argv[7].'SugarTemplateUtilties.php'); } return $upgradeType; } function upgradeDCEFiles($argv,$instanceUpgradePath){ //copy and update following files from upgrade package $upgradeTheseFiles = array('cron.php','download.php','index.php','install.php','soap.php','sugar_version.php','vcal_server.php'); foreach($upgradeTheseFiles as $file){ $srcFile = clean_path("{$instanceUpgradePath}/$file"); $destFile = clean_path("{$argv[3]}/$file"); if(file_exists($srcFile)){ if(!is_dir(dirname($destFile))) { mkdir_recursive(dirname($destFile)); // make sure the directory exists } copy_recursive($srcFile,$destFile); $_GET['TEMPLATE_PATH'] = $destFile; $_GET['CONVERT_FILE_ONLY'] = true; if(!class_exists('TemplateConverter')){ include($argv[7].'templateConverter.php'); }else{ TemplateConverter::convertFile($_GET['TEMPLATE_PATH']); } } } } function threeWayMerge(){ //using threeway merge apis } //// END UTILITIES THAT MUST BE LOCAL :( /////////////////////////////////////////////////////////////////////////////// // only run from command line if(isset($_SERVER['HTTP_USER_AGENT'])) { fwrite(STDERR, 'This utility may only be run from the command line or command prompt.'); exit(1); } //Clean_string cleans out any file passed in as a parameter $_SERVER['PHP_SELF'] = 'silentUpgrade.php'; /////////////////////////////////////////////////////////////////////////////// //// USAGE $usage_dce =<<retrieve('1'); //This is DCE instance global $sugar_config; global $sugar_version; // require_once("{$cwd}/sugar_version.php"); //provides instance version, flavor etc.. //provides instance version, flavor etc.. $isDCEInstance = true; prepSystemForUpgradeSilent(); /////retrieve admin user $configOptions = $sugar_config['dbconfig']; $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM'); $db = &DBManagerFactory::getInstance(); /////////////////////////////////////////////////////////////////////////////// //// MAKE SURE PATCH IS COMPATIBLE if(is_file("{$argv[1]}/manifest.php")) { // provides $manifest array include("{$argv[1]}/manifest.php"); } //If Instance then the files will be accessed from Template/DCEUpgrade folder $zip_from_dir = ''; if( isset( $manifest['copy_files']['from_dir'] ) && $manifest['copy_files']['from_dir'] != "" ){ $zip_from_dir = $manifest['copy_files']['from_dir']; } $instanceUpgradePath = "{$argv[1]}/{$zip_from_dir}"; global $instancePath; $instancePath = $instanceUpgradePath; $_SESSION['instancePath'] = $instancePath; if(file_exists("{$instanceUpgradePath}/modules/UpgradeWizard/uw_utils.php")){ require_once("{$instanceUpgradePath}/modules/UpgradeWizard/uw_utils.php"); } else{ require_once("{$argv[4]}/modules/UpgradeWizard/uw_utils.php"); } if(function_exists('set_upgrade_vars')){ set_upgrade_vars(); } if(is_file("$argv[1]/manifest.php")) { // provides $manifest array //include("$instanceUpgradePath/manifest.php"); if(!isset($manifest)) { fwrite(STDERR, "\nThe patch did not contain a proper manifest.php file. Cannot continue.\n\n"); exit(1); } else { $error = validate_manifest($manifest); if(!empty($error)) { $error = strip_tags(br2nl($error)); fwrite(STDERR,"\n{$error}\n\nFAILURE\n"); exit(1); } } } else { fwrite(STDERR, "\nThe patch did not contain a proper manifest.php file. Cannot continue.\n\n"); exit(1); } $ce_to_pro_ent = isset($manifest['name']) && ($manifest['name'] == 'SugarCE to SugarPro' || $manifest['name'] == 'SugarCE to SugarEnt'); $_SESSION['upgrade_from_flavor'] = $manifest['name']; //get the latest uw_utils.php // require_once("{$instanceUpgradePath}/modules/UpgradeWizard/uw_utils.php"); logThis("*** SILENT DCE UPGRADE INITIATED.", $path); logThis("*** UpgradeWizard Upgraded ", $path); $_SESSION['sugar_version_file'] = ''; $srcFile = clean_path("{$instanceUpgradePath}/sugar_version.php"); if(file_exists($srcFile)) { logThis('Save the version file in session variable', $path); $_SESSION['sugar_version_file'] = $srcFile; } //check exit on conflicts $exitOnConflict = 'yes'; //default if($argv[5] != null && !empty($argv[5])){ if(strtolower($argv[5]) == 'no'){ $exitOnConflict = 'no'; //override } } if($exitOnConflict == 'yes'){ $customFiles = array(); $customFiles = findAllFiles(clean_path("{$argv[3]}/custom"), $customFiles); if($customFiles != null){ logThis("*** **************************** ****", $path); logThis("*** START LOGGING CUSTOM FILES ****", $path); $existsCustomFile = false; foreach($customFiles as $file) { $srcFile = clean_path($file); //$targetFile = clean_path(getcwd() . '/' . $srcFile); if (strpos($srcFile,".svn") !== false) { //do nothing } else{ $existsCustomFile = true; //log the custom file in logThis($file, $path); } } logThis("*** END LOGGING CUSTOM FILES ****", $path); logThis("*** **************************** ****", $path); if($existsCustomFile){ echo 'Stop and Exit Upgrade. There are customized files. Take a look in the upgrade log'; logThis("Stop and Exit Upgrade. There are customized files. Take a look in the upgrade log", $path); exit(1); } else{ upgradeDCEFiles($argv,$instanceUpgradePath); } } else{ //copy and update following files from upgrade package upgradeDCEFiles($argv,$instanceUpgradePath); } } else{ //copy and update following files from upgrade package upgradeDCEFiles($argv,$instanceUpgradePath); } global $unzip_dir; $unzip_dir = $argv[1]; $_SESSION['unzip_dir'] = $unzip_dir; global $path; $path = $argv[2]; } //END OF BIG if block /////////////////////////////////////////////////////////////////////////////// //// RECORD ERRORS $phpErrors = ob_get_contents(); ob_end_clean(); logThis("**** Potential PHP generated error messages: {$phpErrors}", $path); if(count($errors) > 0) { foreach($errors as $error) { logThis("****** SilentUpgrade ERROR: {$error}", $path); } echo "FAILED\n"; } ?>