本文整理汇总了PHP中admin_apply_default_settings函数的典型用法代码示例。如果您正苦于以下问题:PHP admin_apply_default_settings函数的具体用法?PHP admin_apply_default_settings怎么用?PHP admin_apply_default_settings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了admin_apply_default_settings函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: admin_apply_default_settings
/**
* This function applies default settings.
*
* @param object $node, NULL means complete tree, null by default
* @param bool $unconditional if true overrides all values with defaults, null buy default
*/
function admin_apply_default_settings($node = NULL, $unconditional = true)
{
global $CFG;
if (is_null($node)) {
core_plugin_manager::reset_caches();
$node = admin_get_root(true, true);
}
if ($node instanceof admin_category) {
$entries = array_keys($node->children);
foreach ($entries as $entry) {
admin_apply_default_settings($node->children[$entry], $unconditional);
}
} else {
if ($node instanceof admin_settingpage) {
foreach ($node->settings as $setting) {
if (!$unconditional and !is_null($setting->get_setting())) {
//do not override existing defaults
continue;
}
$defaultsetting = $setting->get_defaultsetting();
if (is_null($defaultsetting)) {
// no value yet - default maybe applied after admin user creation or in upgradesettings
continue;
}
$setting->write_setting($defaultsetting);
$setting->write_setting_flags(null);
}
}
}
// Just in case somebody modifies the list of active plugins directly.
core_plugin_manager::reset_caches();
}
示例2: admin_apply_default_settings
/**
* This function applies default settings.
*
* @param object $node, NULL means complete tree, null by default
* @param bool $unconditional if true overrides all values with defaults, null buy default
*/
function admin_apply_default_settings($node = NULL, $unconditional = true)
{
global $CFG;
if (is_null($node)) {
$node = admin_get_root(true, true);
}
if ($node instanceof admin_category) {
$entries = array_keys($node->children);
foreach ($entries as $entry) {
admin_apply_default_settings($node->children[$entry], $unconditional);
}
} else {
if ($node instanceof admin_settingpage) {
foreach ($node->settings as $setting) {
if (!$unconditional and !is_null($setting->get_setting())) {
//do not override existing defaults
continue;
}
$defaultsetting = $setting->get_defaultsetting();
if (is_null($defaultsetting)) {
// no value yet - default maybe applied after admin user creation or in upgradesettings
continue;
}
$setting->write_setting($defaultsetting);
}
}
}
}
示例3: foreach
}
if ($user->id == $USER->id) {
// Override old $USER session variable.
foreach ((array) $usernew as $variable => $value) {
if ($variable === 'description' or $variable === 'password') {
// These are not set for security nad perf reasons.
continue;
}
$USER->{$variable} = $value;
}
// Preload custom fields.
profile_load_custom_fields($USER);
if (!empty($USER->newadminuser)) {
unset($USER->newadminuser);
// Apply defaults again - some of them might depend on admin user info, backup, roles, etc.
admin_apply_default_settings(null, false);
// Admin account is fully configured - set flag here in case the redirect does not work.
unset_config('adminsetuppending');
// Redirect to admin/ to continue with installation.
redirect("{$CFG->wwwroot}/{$CFG->admin}/");
} else {
if (empty($SITE->fullname)) {
// Somebody double clicked when editing admin user during install.
redirect("{$CFG->wwwroot}/{$CFG->admin}/");
} else {
if ($returnto === 'profile') {
if ($course->id != SITEID) {
$returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
} else {
$returnurl = new moodle_url('/user/profile.php', array('id' => $user->id));
}
示例4: install_cli_database
/**
* Install Moodle DB,
* config.php must exist, there must not be any tables in db yet.
*
* @param array $options adminpass is mandatory
* @param bool $interactive
* @return void
*/
function install_cli_database(array $options, $interactive)
{
global $CFG, $DB;
require_once $CFG->libdir . '/environmentlib.php';
require_once $CFG->libdir . '/upgradelib.php';
// show as much debug as possible
@error_reporting(E_ALL | E_STRICT);
@ini_set('display_errors', '1');
$CFG->debug = E_ALL | E_STRICT;
$CFG->debugdisplay = true;
$CFG->version = '';
$CFG->release = '';
$CFG->branch = '';
$version = null;
$release = null;
$branch = null;
// read $version and $release
require $CFG->dirroot . '/version.php';
if ($DB->get_tables()) {
cli_error(get_string('clitablesexist', 'install'));
}
if (empty($options['adminpass'])) {
cli_error('Missing required admin password');
}
// test environment first
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
$errors = environment_get_errors($environment_results);
cli_heading(get_string('environment', 'admin'));
foreach ($errors as $error) {
list($info, $report) = $error;
echo "!! {$info} !!\n{$report}\n\n";
}
exit(1);
}
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
cli_error(get_string('unicoderequired', 'admin'));
}
}
if ($interactive) {
cli_separator();
cli_heading(get_string('databasesetup'));
}
// install core
install_core($version, true);
set_config('release', $release);
set_config('branch', $branch);
if (PHPUNIT_TEST) {
// mark as test database as soon as possible
set_config('phpunittest', 'na');
}
// install all plugins types, local, etc.
upgrade_noncore(true);
// set up admin user password
$DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin'));
// rename admin username if needed
if (isset($options['adminuser']) and $options['adminuser'] !== 'admin' and $options['adminuser'] !== 'guest') {
$DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin'));
}
// indicate that this site is fully configured
set_config('rolesactive', 1);
upgrade_finished();
// log in as admin - we need do anything when applying defaults
$admins = get_admins();
$admin = reset($admins);
session_set_user($admin);
// apply all default settings, do it twice to fill all defaults - some settings depend on other setting
admin_apply_default_settings(NULL, true);
admin_apply_default_settings(NULL, true);
set_config('registerauth', '');
// set the site name
if (isset($options['shortname']) and $options['shortname'] !== '') {
$DB->set_field('course', 'shortname', $options['shortname'], array('format' => 'site'));
}
if (isset($options['fullname']) and $options['fullname'] !== '') {
$DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site'));
}
}
示例5: cli_heading
cli_heading(get_string('environment', 'admin'));
foreach ($errors as $error) {
list($info, $report) = $error;
echo "!! {$info} !!\n{$report}\n\n";
}
exit(1);
}
if ($interactive) {
echo html_to_text(get_string('upgradesure', 'admin', $newversion)) . "\n";
$prompt = get_string('cliyesnoprompt', 'admin');
$input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
if ($input == get_string('clianswerno', 'admin')) {
exit(1);
}
}
if ($version > $CFG->version) {
upgrade_core($version, true);
}
set_config('release', $release);
// unconditionally upgrade
upgrade_noncore(true);
// log in as admin - we need doanything permission when applying defaults
$admins = get_admins();
$admin = reset($admins);
session_set_user($admin);
// apply all default settings, just in case do it twice to fill all defaults
admin_apply_default_settings(NULL, false);
admin_apply_default_settings(NULL, false);
echo get_string('cliupgradefinished', 'admin') . "\n";
exit(0);
// 0 means success
示例6: install_core
/**
* Install core moodle tables and initialize
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function install_core($version, $verbose) {
global $CFG, $DB;
// We can not call purge_all_caches() yet, make sure the temp and cache dirs exist and are empty.
remove_dir($CFG->cachedir.'', true);
make_cache_directory('', true);
remove_dir($CFG->localcachedir.'', true);
make_localcache_directory('', true);
remove_dir($CFG->tempdir.'', true);
make_temp_directory('', true);
remove_dir($CFG->dataroot.'/muc', true);
make_writable_directory($CFG->dataroot.'/muc', true);
try {
core_php_time_limit::raise(600);
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install(); // installs the capabilities too
// store version
upgrade_main_savepoint(true, $version, false);
// Continue with the installation
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
\core\task\manager::reset_scheduled_tasks_for_component('moodle');
message_update_providers('moodle');
\core\message\inbound\manager::update_handlers_for_component('moodle');
// Write default settings unconditionally
admin_apply_default_settings(NULL, true);
print_upgrade_part_end(null, true, $verbose);
// Purge all caches. They're disabled but this ensures that we don't have any persistent data just in case something
// during installation didn't use APIs.
cache_helper::purge_all();
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
}
示例7: set_config
set_config('unicodedb', 1);
/// Continue with the instalation
$db->debug = false;
if ($status) {
/// Groups install is now in core above.
// Install the roles system.
moodle_install_roles();
set_config('statsrolesupgraded', time());
// install core event handlers
events_update_definition();
/// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'enrol' => 'manual', 'enrol_plugins_enabled' => 'manual', 'style' => 'default', 'template' => 'default', 'theme' => 'standardwhite', 'filter_multilang_converted' => 1));
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
admin_apply_default_settings(NULL, true);
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot . '/mnet/lib.php';
} else {
error("Error: Main databases NOT set up successfully");
}
print_continue('index.php');
print_footer('none');
die;
}
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
if (file_exists("{$CFG->dirroot}/lib/db/{$CFG->dbtype}.php")) {
include_once "{$CFG->dirroot}/lib/db/{$CFG->dbtype}.php";
# defines old upgrades
}
示例8: install_core
/**
* Install core moodle tables and initialize
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function install_core($version, $verbose) {
global $CFG, $DB;
try {
set_time_limit(600);
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install(); // installs the capabilities too
// store version
upgrade_main_savepoint(true, $version, false);
// Continue with the installation
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Write default settings unconditionally
admin_apply_default_settings(NULL, true);
print_upgrade_part_end(null, true, $verbose);
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
}
示例9: mnetadmin_rpc_upgrade
function mnetadmin_rpc_upgrade($user, $json_response = true)
{
global $CFG, $USER;
// Invoke local user and check his rights
if ($auth_response = invoke_local_user((array) $user)) {
if ($json_response) {
return $auth_response;
} else {
return json_decode($auth_response);
}
}
// Creating response
$response = new stdclass();
$response->status = RPC_SUCCESS;
require "{$CFG->dirroot}/version.php";
// defines $version, $release, $branch and $maturity
$CFG->target_release = $release;
// used during installation and upgrades
if ($version < $CFG->version) {
$response->status = RPC_FAILURE_RUN;
$response->error = get_string('downgradedcore', 'error');
$response->errors[] = get_string('downgradedcore', 'error');
if ($json_response) {
return json_encode($response);
} else {
return $response;
}
}
$oldversion = "{$CFG->release} ({$CFG->version})";
$newversion = "{$release} ({$version})";
if (!moodle_needs_upgrading()) {
$response->message = get_string('cliupgradenoneed', 'core_admin', $newversion);
if ($json_response) {
return json_encode($response);
} else {
return $response;
}
}
// debug_trace('Remote Upgrade : Environment check');
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_NEWER);
if (!$envstatus) {
$response->status = RPC_FAILURE_RUN;
$response->error = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade');
$response->errors[] = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade');
$response->detail = $environment_results;
if ($json_response) {
return json_encode($response);
} else {
return $response;
}
}
// Test plugin dependencies.
// debug_trace('Remote Upgrade : Plugins check');
$failed = array();
if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) {
$response->status = RPC_FAILURE_RUN;
$response->error = get_string('pluginschecktodo', 'admin');
$response->errors[] = get_string('pluginschecktodo', 'admin');
if ($json_response) {
return json_encode($response);
} else {
return $response;
}
}
ob_start();
// debug_trace('Remote Upgrade : Upgrade core');
if ($version > $CFG->version) {
upgrade_core($version, false);
}
set_config('release', $release);
set_config('branch', $branch);
// unconditionally upgrade
// debug_trace('Remote Upgrade : Upgrade other');
upgrade_noncore(false);
// log in as admin - we need doanything permission when applying defaults
// debug_trace('Remote Upgrade : Turning ADMIN ');
session_set_user(get_admin());
// apply all default settings, just in case do it twice to fill all defaults
// debug_trace('Remote Upgrade : Applying settings ');
admin_apply_default_settings(NULL, false);
admin_apply_default_settings(NULL, false);
ob_end_clean();
$response->message = vmoodle_get_string('upgradecomplete', 'vmoodleadminset_upgrade', $newversion);
if ($json_response) {
return json_encode($response);
} else {
return $response;
}
}
示例10: console_write_error
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
console_write_error('unicoderequired', 'admin');
}
}
$DB->get_manager()->install_from_xmldb_file("{$CFG->libdir}/db/install.xml");
//New method
/// Continue with the instalation
// Install the roles system.
moodle_install_roles();
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
$adminroot = admin_get_root();
$adminroot->prune('backups');
// backup settings table not created yet
admin_apply_default_settings($adminroot);
/// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('alternateloginurl' => '', 'auth' => 'email', 'auth_pop3mailbox' => 'INBOX', 'changepassword' => '', 'enrol' => 'manual', 'enrol_plugins_enabled' => 'manual', 'guestloginbutton' => 1, 'registerauth' => 'email', 'style' => 'default', 'template' => 'default', 'theme' => 'standardwhite', 'filter_multilang_converted' => 1));
notify($strdatabasesuccess, "green");
require_once $CFG->dirroot . '/mnet/lib.php';
}
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
if (file_exists("{$CFG->dirroot}/lib/db/upgrade.php")) {
include_once "{$CFG->dirroot}/lib/db/upgrade.php";
# defines new upgrades
}
$stradministration = get_string("administration");
if ($CFG->version) {
if ($version > $CFG->version) {
示例11: install_core
/**
* Install core moodle tables and initialize
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function install_core($version, $verbose) {
global $CFG, $DB;
try {
// Disable the use of cache stores here. We will reset the factory after we've performed the installation.
// This ensures that we don't permanently cache anything during installation.
cache_factory::disable_stores();
set_time_limit(600);
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install(); // installs the capabilities too
// store version
upgrade_main_savepoint(true, $version, false);
// Continue with the installation
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Write default settings unconditionally
admin_apply_default_settings(NULL, true);
print_upgrade_part_end(null, true, $verbose);
// Purge all caches. They're disabled but this ensures that we don't have any persistent data just in case something
// during installation didn't use APIs.
cache_helper::purge_all();
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
}