本文整理汇总了PHP中context_helper::create_instances方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::create_instances方法的具体用法?PHP context_helper::create_instances怎么用?PHP context_helper::create_instances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context_helper
的用法示例。
在下文中一共展示了context_helper::create_instances方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cron_run
//.........这里部分代码省略.........
mtrace(' Cleaned up context instances');
context_helper::build_all_paths(false);
// If you suspect that the context paths are somehow corrupt
// replace the line below with: context_helper::build_all_paths(true);
mtrace(' Built context paths');
// Remove expired cache flags
gc_cache_flags();
mtrace(' Cleaned cache flags');
// Cleanup messaging
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
$notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
$DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
mtrace(' Cleaned up read notifications');
}
mtrace(' Deleting temporary files...');
cron_delete_from_temp();
// Cleanup user password reset records
// Delete any reset request records which are expired by more than a day.
// (We keep recently expired requests around so we can give a different error msg to users who
// are trying to user a recently expired reset attempt).
$pwresettime = isset($CFG->pwresettime) ? $CFG->pwresettime : 1800;
$earliestvalid = time() - $pwresettime - DAYSECS;
$DB->delete_records_select('user_password_resets', "timerequested < ?", array($earliestvalid));
mtrace(' Cleaned up old password reset records');
mtrace("...finished clean-up tasks");
}
// End of occasional clean-up tasks
// Send login failures notification - brute force protection in moodle is weak,
// we should at least send notices early in each cron execution
if (notify_login_failures()) {
mtrace(' Notified login failures');
}
// Make sure all context instances are properly created - they may be required in auth, enrol, etc.
context_helper::create_instances();
mtrace(' Created missing context instances');
// Session gc.
mtrace("Running session gc tasks...");
\core\session\manager::gc();
mtrace("...finished stale session cleanup");
// Run the auth cron, if any before enrolments
// because it might add users that will be needed in enrol plugins
$auths = get_enabled_auth_plugins();
mtrace("Running auth crons if required...");
cron_trace_time_and_memory();
foreach ($auths as $auth) {
$authplugin = get_auth_plugin($auth);
if (method_exists($authplugin, 'cron')) {
mtrace("Running cron for auth/{$auth}...");
$authplugin->cron();
if (!empty($authplugin->log)) {
mtrace($authplugin->log);
}
}
unset($authplugin);
}
// Generate new password emails for users - ppl expect these generated asap
if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
mtrace('Creating passwords for new users...');
$usernamefields = get_all_user_name_fields(true, 'u');
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email,\n {$usernamefields}, u.username, u.lang,\n p.id as prefid\n FROM {user} u\n JOIN {user_preferences} p ON u.id=p.userid\n WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin' AND u.deleted = 0");
// note: we can not send emails to suspended accounts
foreach ($newusers as $newuser) {
// Use a low cost factor when generating bcrypt hash otherwise
// hashing would be slow when emailing lots of users. Hashes
// will be automatically updated to a higher cost factor the first
// time the user logs in.
示例2: create_contexts
/**
* Precreates all contexts including all parents
*
* @deprecated since 2.2
* @param int $contextlevel empty means all
* @param bool $buildpaths update paths and depths
* @return void
*/
function create_contexts($contextlevel = null, $buildpaths = true)
{
context_helper::create_instances($contextlevel, $buildpaths);
}
示例3: create_contexts
/**
* Precreates all contexts including all parents.
*
* @see context_helper::create_instances()
* @deprecated since 2.2
* @param int $contextlevel empty means all
* @param bool $buildpaths update paths and depths
* @return void
*/
function create_contexts($contextlevel = null, $buildpaths = true)
{
debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
context_helper::create_instances($contextlevel, $buildpaths);
}
示例4: upgrade_core
/**
* Upgrade moodle core
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function upgrade_core($version, $verbose) {
global $CFG, $SITE, $DB, $COURSE;
raise_memory_limit(MEMORY_EXTRA);
require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
try {
// Reset caches before any output.
cache_helper::purge_all(true);
purge_all_caches();
// Upgrade current language pack if we can
upgrade_language_pack();
print_upgrade_part_start('moodle', false, $verbose);
// Pre-upgrade scripts for local hack workarounds.
$preupgradefile = "$CFG->dirroot/local/preupgrade.php";
if (file_exists($preupgradefile)) {
core_php_time_limit::raise();
require($preupgradefile);
// Reset upgrade timeout to default.
upgrade_set_timeout();
}
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
upgrade_main_savepoint($result, $version, false);
}
// In case structure of 'course' table has been changed and we forgot to update $SITE, re-read it from db.
$SITE = $DB->get_record('course', array('id' => $SITE->id));
$COURSE = clone($SITE);
// perform all other component upgrade routines
update_capabilities('moodle');
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');
// Update core definitions.
cache_helper::update_definitions(true);
// Purge caches again, just to be sure we arn't holding onto old stuff now.
cache_helper::purge_all(true);
purge_all_caches();
// Clean up contexts - more and more stuff depends on existence of paths and contexts
context_helper::cleanup_instances();
context_helper::create_instances(null, false);
context_helper::build_all_paths(false);
$syscontext = context_system::instance();
$syscontext->mark_dirty();
print_upgrade_part_end('moodle', false, $verbose);
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}
示例5: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
// Make sure all context instances are properly created - they may be required in auth, enrol, etc.
\context_helper::create_instances();
mtrace(' Created missing context instances');
}
示例6: test_everything_in_accesslib
//.........这里部分代码省略.........
$DB->delete_records('cache_flags', array());
$context->delete(); // should delete also linked blocks
$dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
$this->assertTrue(isset($dirty[$context->path]));
$this->assertFalse($DB->record_exists('context', array('id'=>$context->id)));
$this->assertFalse($DB->record_exists('context', array('id'=>$bicontext->id)));
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_MODULE, 'instanceid'=>$testpages[4])));
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_BLOCK, 'instanceid'=>$bi->id)));
$this->assertEquals(0, $DB->count_records('block_instances', array('parentcontextid'=>$context->id)));
context_module::instance($testpages[4]);
// ====== context_helper::delete_instance() =============================
context_helper::reset_caches();
$lastcourse = array_pop($testcourses);
$this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$lastcourse)));
$coursecontext = context_course::instance($lastcourse);
$this->assertEquals(context_inspection::test_context_cache_size(), 1);
$this->assertFalse($coursecontext->instanceid == CONTEXT_COURSE);
$DB->delete_records('cache_flags', array());
context_helper::delete_instance(CONTEXT_COURSE, $lastcourse);
$dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
$this->assertTrue(isset($dirty[$coursecontext->path]));
$this->assertEquals(context_inspection::test_context_cache_size(), 0);
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$lastcourse)));
context_course::instance($lastcourse);
// ======= context_helper::create_instances() ==========================
$prevcount = $DB->count_records('context');
$DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
context_helper::create_instances(null, true);
$this->assertSame($DB->count_records('context'), $prevcount);
$this->assertEquals($DB->count_records('context', array('depth'=>0)), 0);
$this->assertEquals($DB->count_records('context', array('path'=>NULL)), 0);
$DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
$DB->delete_records('block_instances', array());
$prevcount = $DB->count_records('context');
$DB->delete_records_select('context', 'contextlevel <> '.CONTEXT_SYSTEM);
context_helper::create_instances(null, true);
$this->assertSame($DB->count_records('context'), $prevcount);
$this->assertEquals($DB->count_records('context', array('depth'=>0)), 0);
$this->assertEquals($DB->count_records('context', array('path'=>NULL)), 0);
// ======= context_helper::cleanup_instances() ==========================
$lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
$DB->delete_records('course', array('id'=>$lastcourse));
$lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
$DB->delete_records('course_categories', array('id'=>$lastcategory));
$lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
$DB->delete_records('user', array('id'=>$lastuser));
$DB->delete_records('block_instances', array('parentcontextid'=>$frontpagepagecontext->id));
$DB->delete_records('course_modules', array('id'=>$frontpagepagecontext->instanceid));
context_helper::cleanup_instances();
$count = 1; //system
$count += $DB->count_records('user', array('deleted'=>0));
$count += $DB->count_records('course_categories');
$count += $DB->count_records('course');
$count += $DB->count_records('course_modules');
$count += $DB->count_records('block_instances');
$this->assertEquals($DB->count_records('context'), $count);
示例7: upgrade_core
/**
* Upgrade moodle core
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function upgrade_core($version, $verbose) {
global $CFG;
raise_memory_limit(MEMORY_EXTRA);
require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
try {
// Reset caches before any output
purge_all_caches();
// Upgrade current language pack if we can
upgrade_language_pack();
print_upgrade_part_start('moodle', false, $verbose);
// one time special local migration pre 2.0 upgrade script
if ($CFG->version < 2007101600) {
$pre20upgradefile = "$CFG->dirroot/local/upgrade_pre20.php";
if (file_exists($pre20upgradefile)) {
set_time_limit(0);
require($pre20upgradefile);
// reset upgrade timeout to default
upgrade_set_timeout();
}
}
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
upgrade_main_savepoint($result, $version, false);
}
// perform all other component upgrade routines
update_capabilities('moodle');
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Reset caches again, just to be sure
purge_all_caches();
// Clean up contexts - more and more stuff depends on existence of paths and contexts
context_helper::cleanup_instances();
context_helper::create_instances(null, false);
context_helper::build_all_paths(false);
$syscontext = context_system::instance();
$syscontext->mark_dirty();
print_upgrade_part_end('moodle', false, $verbose);
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}
示例8: test_everything_in_accesslib
//.........这里部分代码省略.........
$context = context_module::instance($testpages[4]);
$this->assertTrue($DB->record_exists('context', array('id' => $context->id)));
$this->assertEqual(1, $DB->count_records('block_instances', array('parentcontextid' => $context->id)));
$bi = $DB->get_record('block_instances', array('parentcontextid' => $context->id));
$bicontext = context_block::instance($bi->id);
$DB->delete_records('cache_flags', array());
$context->delete();
// should delete also linked blocks
$dirty = get_cache_flags('accesslib/dirtycontexts', time() - 2);
$this->assertTrue(isset($dirty[$context->path]));
$this->assertFalse($DB->record_exists('context', array('id' => $context->id)));
$this->assertFalse($DB->record_exists('context', array('id' => $bicontext->id)));
$this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_MODULE, 'instanceid' => $testpages[4])));
$this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_BLOCK, 'instanceid' => $bi->id)));
$this->assertEqual(0, $DB->count_records('block_instances', array('parentcontextid' => $context->id)));
context_module::instance($testpages[4]);
// ====== context_helper::delete_instance() =============================
context_helper::reset_caches();
$lastcourse = array_pop($testcourses);
$this->assertTrue($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $lastcourse)));
$coursecontext = context_course::instance($lastcourse);
$this->assertEqual(context_inspection::test_context_cache_size(), 1);
$this->assertFalse($coursecontext->instanceid == CONTEXT_COURSE);
$DB->delete_records('cache_flags', array());
context_helper::delete_instance(CONTEXT_COURSE, $lastcourse);
$dirty = get_cache_flags('accesslib/dirtycontexts', time() - 2);
$this->assertTrue(isset($dirty[$coursecontext->path]));
$this->assertEqual(context_inspection::test_context_cache_size(), 0);
$this->assertFalse($DB->record_exists('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $lastcourse)));
context_course::instance($lastcourse);
// ======= context_helper::create_instances() ==========================
$prevcount = $DB->count_records('context');
$DB->delete_records('context', array('contextlevel' => CONTEXT_BLOCK));
context_helper::create_instances(null, true);
$this->assertIdentical($DB->count_records('context'), $prevcount);
$this->assertEqual($DB->count_records('context', array('depth' => 0)), 0);
$this->assertEqual($DB->count_records('context', array('path' => NULL)), 0);
$DB->delete_records('context', array('contextlevel' => CONTEXT_BLOCK));
$DB->delete_records('block_instances', array());
$prevcount = $DB->count_records('context');
$DB->delete_records_select('context', 'contextlevel <> ' . CONTEXT_SYSTEM);
context_helper::create_instances(null, true);
$this->assertIdentical($DB->count_records('context'), $prevcount);
$this->assertEqual($DB->count_records('context', array('depth' => 0)), 0);
$this->assertEqual($DB->count_records('context', array('path' => NULL)), 0);
// ======= context_helper::cleanup_instances() ==========================
$lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}");
$DB->delete_records('course', array('id' => $lastcourse));
$lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}");
$DB->delete_records('course_categories', array('id' => $lastcategory));
$lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0");
$DB->delete_records('user', array('id' => $lastuser));
$DB->delete_records('block_instances', array('parentcontextid' => $frontpagepagecontext->id));
$DB->delete_records('course_modules', array('id' => $frontpagepagecontext->instanceid));
context_helper::cleanup_instances();
$count = 1;
//system
$count += $DB->count_records('user', array('deleted' => 0));
$count += $DB->count_records('course_categories');
$count += $DB->count_records('course');
$count += $DB->count_records('course_modules');
$count += $DB->count_records('block_instances');
$this->assertEqual($DB->count_records('context'), $count);
// ======= context cache size restrictions ==============================
$testusers = array();
for ($i = 0; $i < CONTEXT_CACHE_MAX_SIZE + 100; $i++) {
示例9: upgrade_core
/**
* Upgrade moodle core
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function upgrade_core($version, $verbose)
{
global $CFG;
raise_memory_limit(MEMORY_EXTRA);
require_once $CFG->libdir . '/db/upgrade.php';
// Defines upgrades
try {
// Reset caches before any output.
cache_helper::purge_all(true);
purge_all_caches();
// Upgrade current language pack if we can
upgrade_language_pack();
print_upgrade_part_start('moodle', false, $verbose);
// Pre-upgrade scripts for local hack workarounds.
$preupgradefile = "{$CFG->dirroot}/local/preupgrade.php";
if (file_exists($preupgradefile)) {
core_php_time_limit::raise();
require $preupgradefile;
// Reset upgrade timeout to default.
upgrade_set_timeout();
}
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
upgrade_main_savepoint($result, $version, false);
}
// perform all other component upgrade routines
update_capabilities('moodle');
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Update core definitions.
cache_helper::update_definitions(true);
// Purge caches again, just to be sure we arn't holding onto old stuff now.
cache_helper::purge_all(true);
purge_all_caches();
// Clean up contexts - more and more stuff depends on existence of paths and contexts
context_helper::cleanup_instances();
context_helper::create_instances(null, false);
context_helper::build_all_paths(false);
$syscontext = context_system::instance();
$syscontext->mark_dirty();
print_upgrade_part_end('moodle', false, $verbose);
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}
示例10: local_ent_installer_make_teacher_category
/**
* make a course category for the teacher and give full control to it
*
*
*/
function local_ent_installer_make_teacher_category($user, $unassignteachercategoryrole = null)
{
global $DB, $CFG;
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/lib/coursecatlib.php';
try {
$institutionid = get_config('local_ent_installer', 'institution_id');
$teacherstubcategory = get_config('local_ent_installer', 'teacher_stub_category');
if (!$teacherstubcategory) {
mtrace("No stub");
return;
}
$teachercategoryrole = $DB->get_record('role', array('shortname' => ENT_TEACHER_CATEGORY_ROLE));
$teachercatidnum = $institutionid . '$' . $user->idnumber . '$CAT';
$existingcategory = $DB->get_record('course_categories', array('idnumber' => $teachercatidnum));
if ($existingcategory) {
$categorycontext = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSECAT, 'instanceid' => $existingcategory->id));
}
if (!empty($unassignteachercategoryrole)) {
$rolestounassign = explode(',', $unassignteachercategoryrole);
foreach ($rolestounassign as $myrole) {
$roletounassign = $DB->get_record('role', array('shortname' => $myrole));
if (isset($roletounassign)) {
role_unassign($roletounassign->id, $user->id, $categorycontext->id);
}
}
}
if (isset($categorycontext)) {
$roleassignedtoteachercategory = $DB->get_records('role_assignments', array('roleid' => $teachercategoryrole->id, 'contextid' => $categorycontext->id, 'userid' => $user->id, 'component' => "", 'itemid' => 0), 'id');
if (!$roleassignedtoteachercategory) {
role_assign($teachercategoryrole->id, $user->id, $categorycontext->id);
}
} else {
if (!$existingcategory) {
$newcategory = new StdClass();
$newcategory->name = fullname($user);
$newcategory->idnumber = $teachercatidnum;
$newcategory->parent = $teacherstubcategory;
$newcategory->visible = 1;
$newcategory = coursecat::create($newcategory);
fix_course_sortorder();
$categorycontext = context_coursecat::instance($newcategory->id);
} else {
context_helper::create_instances(CONTEXT_COURSECAT, true);
$categorycontext = context_coursecat::instance($existingcategory->id);
}
role_assign($teachercategoryrole->id, $user->id, $categorycontext->id);
}
} catch (Exception $e) {
mtrace("ERROR : exception into make_teacher_category");
mtrace('ERROR MSG : ' . $e->getMessage());
if ($options['verbose']) {
mtrace(' ###### ');
mtrace("ERROR FILE : {$e->getFile()} : {$e->getLine()}");
mtrace('ERROR TRACE : ' . $e->getTraceAsString());
mtrace(' ###### ');
}
}
}
示例11: upgrade_core
/**
* Upgrade moodle core
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function upgrade_core($version, $verbose)
{
global $CFG;
raise_memory_limit(MEMORY_EXTRA);
require_once $CFG->libdir . '/db/upgrade.php';
// Defines upgrades
try {
// Reset caches before any output
purge_all_caches();
// 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();
// Upgrade current language pack if we can
upgrade_language_pack();
print_upgrade_part_start('moodle', false, $verbose);
// one time special local migration pre 2.0 upgrade script
if ($CFG->version < 2007101600) {
$pre20upgradefile = "{$CFG->dirroot}/local/upgrade_pre20.php";
if (file_exists($pre20upgradefile)) {
set_time_limit(0);
require $pre20upgradefile;
// reset upgrade timeout to default
upgrade_set_timeout();
}
}
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
upgrade_main_savepoint($result, $version, false);
}
// perform all other component upgrade routines
update_capabilities('moodle');
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Update core definitions.
cache_helper::update_definitions(true);
// Reset the cache, this returns it to a normal operation state.
cache_factory::reset();
// Purge caches again, just to be sure we arn't holding onto old stuff now.
purge_all_caches();
// Clean up contexts - more and more stuff depends on existence of paths and contexts
context_helper::cleanup_instances();
context_helper::create_instances(null, false);
context_helper::build_all_paths(false);
$syscontext = context_system::instance();
$syscontext->mark_dirty();
print_upgrade_part_end('moodle', false, $verbose);
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}