// Check if the test mode is enabledif(isset($CFG->behat_dataroot)){require_once($CFG->docroot.'/testing/frameworks/behat/classes/util.php');if(BehatTestingUtil::is_test_site_enabled()){define('BEHAT_TEST',1);}

// Now we can begin switching $CFG->X for $CFG->behat_X.// Keep the origin settings for validating only$CFG->wwwroot_orig=isset($CFG->wwwroot)?$CFG->wwwroot:null;$CFG->dataroot_orig=isset($CFG->dataroot)?$CFG->dataroot:null;$CFG->dbprefix_orig=isset($CFG->dbprefix)?$CFG->dbprefix:null;$CFG->wwwroot=$CFG->behat_wwwroot;$CFG->dataroot=$CFG->behat_dataroot;$CFG->dbprefix=$CFG->behat_dbprefix;

}// Fix up paths in $CFGforeach(array('docroot','dataroot')as$path){$CFG->{$path}=(substr($CFG->{$path},-1)!=DIRECTORY_SEPARATOR)?$CFG->{$path}.DIRECTORY_SEPARATOR:$CFG->{$path};}// Set default configs that are dependent on the docroot and datarootif(empty($CFG->sessionpath)){$CFG->sessionpath=$CFG->dataroot.'sessions';}

// Now that we know json_decode exists we check if any config vars are// encoded json strings and we convert them to be used in phpforeach($CFGas$key=>$option){if(is_string($option)){$decode=json_decode($option,true);if($decode!==null&&is_array($decode)&&json_last_error()===JSON_ERROR_NONE){$CFG->$key=$decode;}}}

// If we have cleanurl subdomains turned on, we need to set cookiedomain// to ensure cookies are given back to us in all subdomainsif(isset($CFG->cleanurls)&&isset($CFG->cleanurlusersubdomains)&&!isset($CFG->cookiedomain)){$url=parse_url(get_config('wwwroot'));$CFG->cookiedomain='.'.$url['host'];}

$bcrypt_cost=get_config('bcrypt_cost');// bcrypt_cost is the cost parameter passed as part of the bcrypt hash// See http://php.net/manual/en/function.crypt.php// The value is a 2 digit number in the range of 04-31if(!$bcrypt_cost||!is_int($bcrypt_cost)||$bcrypt_cost<4||$bcrypt_cost>31){$bcrypt_cost=12;}$CFG->bcrypt_cost=sprintf('%02d',$bcrypt_cost);

// The installer does its own auth_setup checking, because some upgrades may// break logging in and so need to allow no logins.// Command-line scripts obviously have no logged-in user.if(!defined('INSTALLER')&&!defined('CLI')&&!defined('CRON')){auth_setup();}

// Force the user to log out if:// - the site is closed by the system due to a pending upgrade// - the site was closed by an admin (and the user is not an admin)if($siteclosedforupgrade||(get_config('siteclosedbyadmin')&&!$USER->admin)){

if(!defined('INSTALLER')){// make sure the table exists if upgrading from older versionrequire_once('ddl.php');if(table_exists(newXMLDBTable('module_installed'))){if($plugins=plugins_installed('module')){foreach($pluginsas&$plugin){if(safe_require_plugin('module',$plugin->name)){call_static_method(generate_class_name('module',$plugin->name),'bootstrap');}

// Ensure that externalfilesystem is configured correctly.if(get_config('externalfilesystem')){if(empty($CFG->externalfilesystem['includefilepath'])||empty($CFG->externalfilesystem['class'])){thrownewConfigSanityException('externalfilesystem configuration detected but the settings are invalid');}if(!file_exists($CFG->docroot.'/'.$CFG->externalfilesystem['includefilepath'])){thrownewConfigSanityException('externalfilesystem is configured, but file '.$CFG->externalfilesystem['includefilepath'].' does not exist');}require_once($CFG->docroot.'/'.$CFG->externalfilesystem['includefilepath']);if(!class_exists($CFG->externalfilesystem['class'])){thrownewConfigSanityException('externalfilesystem is configured, but class '.$CFG->externalfilesystem['class'].' does not exist');}if(!is_subclass_of($CFG->externalfilesystem['class'],'external_file_system')){thrownewConfigSanityException('externalfilesystem is configured, but '.$CFG->externalfilesystem['class'].' class does not implement external_file_system interface');}}