本文整理汇总了PHP中context_helper::build_all_paths方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::build_all_paths方法的具体用法?PHP context_helper::build_all_paths怎么用?PHP context_helper::build_all_paths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context_helper
的用法示例。
在下文中一共展示了context_helper::build_all_paths方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
// Context maintenance stuff.
\context_helper::cleanup_instances();
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).
}
示例2: reset_paths
/**
* Remove all context path info and optionally rebuild it.
*
* @param bool $rebuild
* @return void
*/
public function reset_paths($rebuild = true)
{
global $DB;
if ($this->_path) {
$this->mark_dirty();
}
$DB->set_field_select('context', 'depth', 0, "path LIKE '%/{$this->_id}/%'");
$DB->set_field_select('context', 'path', NULL, "path LIKE '%/{$this->_id}/%'");
if ($this->_contextlevel != CONTEXT_SYSTEM) {
$DB->set_field('context', 'depth', 0, array('id' => $this->_id));
$DB->set_field('context', 'path', NULL, array('id' => $this->_id));
$this->_depth = 0;
$this->_path = null;
}
if ($rebuild) {
context_helper::build_all_paths(false);
}
context::reset_caches();
}
示例3: cron_run
/**
* Execute cron tasks
*/
function cron_run()
{
global $DB, $CFG, $OUTPUT;
if (CLI_MAINTENANCE) {
echo "CLI maintenance mode active, cron execution suspended.\n";
exit(1);
}
if (moodle_needs_upgrading()) {
echo "Moodle upgrade pending, cron execution suspended.\n";
exit(1);
}
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/gradelib.php';
if (!empty($CFG->showcronsql)) {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
set_debugging(DEBUG_DEVELOPER, true);
}
set_time_limit(0);
$starttime = microtime();
// Increase memory limit
raise_memory_limit(MEMORY_EXTRA);
// Emulate normal session - we use admin accoutn by default
cron_setup_user();
// Start output log
$timenow = time();
mtrace("Server Time: " . date('r', $timenow) . "\n\n");
// Run cleanup core cron jobs, but not every time since they aren't too important.
// These don't have a timer to reduce load, so we'll use a random number
// to randomly choose the percentage of times we should run these jobs.
$random100 = rand(0, 100);
if ($random100 < 20) {
// Approximately 20% of the time.
mtrace("Running clean-up tasks...");
cron_trace_time_and_memory();
// Delete users who haven't confirmed within required period
if (!empty($CFG->deleteunconfirmed)) {
$cuttime = $timenow - $CFG->deleteunconfirmed * 3600;
$rs = $DB->get_recordset_sql("SELECT *\n FROM {user}\n WHERE confirmed = 0 AND firstaccess > 0\n AND firstaccess < ?", array($cuttime));
foreach ($rs as $user) {
delete_user($user);
// we MUST delete user properly first
$DB->delete_records('user', array('id' => $user->id));
// this is a bloody hack, but it might work
mtrace(" Deleted unconfirmed user for " . fullname($user, true) . " ({$user->id})");
}
$rs->close();
}
// Delete users who haven't completed profile within required period
if (!empty($CFG->deleteincompleteusers)) {
$cuttime = $timenow - $CFG->deleteincompleteusers * 3600;
$rs = $DB->get_recordset_sql("SELECT *\n FROM {user}\n WHERE confirmed = 1 AND lastaccess > 0\n AND lastaccess < ? AND deleted = 0\n AND (lastname = '' OR firstname = '' OR email = '')", array($cuttime));
foreach ($rs as $user) {
if (isguestuser($user) or is_siteadmin($user)) {
continue;
}
delete_user($user);
mtrace(" Deleted not fully setup user {$user->username} ({$user->id})");
}
$rs->close();
}
// Delete old logs to save space (this might need a timer to slow it down...)
if (!empty($CFG->loglifetime)) {
// value in days
$loglifetime = $timenow - $CFG->loglifetime * 3600 * 24;
$DB->delete_records_select("log", "time < ?", array($loglifetime));
mtrace(" Deleted old log records");
}
// Delete old backup_controllers and logs.
$loglifetime = get_config('backup', 'loglifetime');
if (!empty($loglifetime)) {
// Value in days.
$loglifetime = $timenow - $loglifetime * 3600 * 24;
// Delete child records from backup_logs.
$DB->execute("DELETE FROM {backup_logs}\n WHERE EXISTS (\n SELECT 'x'\n FROM {backup_controllers} bc\n WHERE bc.backupid = {backup_logs}.backupid\n AND bc.timecreated < ?)", array($loglifetime));
// Delete records from backup_controllers.
$DB->execute("DELETE FROM {backup_controllers}\n WHERE timecreated < ?", array($loglifetime));
mtrace(" Deleted old backup records");
}
// Delete old cached texts
if (!empty($CFG->cachetext)) {
// Defined in config.php
$cachelifetime = time() - $CFG->cachetext - 60;
// Add an extra minute to allow for really heavy sites
$DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
mtrace(" Deleted old cache_text records");
}
if (!empty($CFG->usetags)) {
require_once $CFG->dirroot . '/tag/lib.php';
tag_cron();
mtrace(' Executed tag cron');
}
// Context maintenance stuff
context_helper::cleanup_instances();
mtrace(' Cleaned up context instances');
context_helper::build_all_paths(false);
//.........这里部分代码省略.........
示例4: fix_course_sortorder
/**
* Fixes course category and course sortorder, also verifies category and course parents and paths.
* (circular references are not fixed)
*
* @global object
* @global object
* @uses MAX_COURSES_IN_CATEGORY
* @uses MAX_COURSE_CATEGORIES
* @uses SITEID
* @uses CONTEXT_COURSE
* @return void
*/
function fix_course_sortorder()
{
global $DB, $SITE;
//WARNING: this is PHP5 only code!
if ($unsorted = $DB->get_records('course_categories', array('sortorder' => 0))) {
//move all categories that are not sorted yet to the end
$DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES, array('sortorder' => 0));
}
$allcats = $DB->get_records('course_categories', null, 'sortorder, id', 'id, sortorder, parent, depth, path');
$topcats = array();
$brokencats = array();
foreach ($allcats as $cat) {
$sortorder = (int) $cat->sortorder;
if (!$cat->parent) {
while (isset($topcats[$sortorder])) {
$sortorder++;
}
$topcats[$sortorder] = $cat;
continue;
}
if (!isset($allcats[$cat->parent])) {
$brokencats[] = $cat;
continue;
}
if (!isset($allcats[$cat->parent]->children)) {
$allcats[$cat->parent]->children = array();
}
while (isset($allcats[$cat->parent]->children[$sortorder])) {
$sortorder++;
}
$allcats[$cat->parent]->children[$sortorder] = $cat;
}
unset($allcats);
// add broken cats to category tree
if ($brokencats) {
$defaultcat = reset($topcats);
foreach ($brokencats as $cat) {
$topcats[] = $cat;
}
}
// now walk recursively the tree and fix any problems found
$sortorder = 0;
$fixcontexts = array();
_fix_course_cats($topcats, $sortorder, 0, 0, '', $fixcontexts);
// detect if there are "multiple" frontpage courses and fix them if needed
$frontcourses = $DB->get_records('course', array('category' => 0), 'id');
if (count($frontcourses) > 1) {
if (isset($frontcourses[SITEID])) {
$frontcourse = $frontcourses[SITEID];
unset($frontcourses[SITEID]);
} else {
$frontcourse = array_shift($frontcourses);
}
$defaultcat = reset($topcats);
foreach ($frontcourses as $course) {
$DB->set_field('course', 'category', $defaultcat->id, array('id' => $course->id));
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$fixcontexts[$context->id] = $context;
}
unset($frontcourses);
} else {
$frontcourse = reset($frontcourses);
}
// now fix the paths and depths in context table if needed
if ($fixcontexts) {
foreach ($fixcontexts as $fixcontext) {
$fixcontext->reset_paths(false);
}
context_helper::build_all_paths(false);
unset($fixcontexts);
}
// release memory
unset($topcats);
unset($brokencats);
unset($fixcontexts);
// fix frontpage course sortorder
if ($frontcourse->sortorder != 1) {
$DB->set_field('course', 'sortorder', 1, array('id' => $frontcourse->id));
}
// now fix the course counts in category records if needed
$sql = "SELECT cc.id, cc.coursecount, COUNT(c.id) AS newcount\n FROM {course_categories} cc\n LEFT JOIN {course} c ON c.category = cc.id\n GROUP BY cc.id, cc.coursecount\n HAVING cc.coursecount <> COUNT(c.id)";
if ($updatecounts = $DB->get_records_sql($sql)) {
// categories with more courses than MAX_COURSES_IN_CATEGORY
$categories = array();
foreach ($updatecounts as $cat) {
$cat->coursecount = $cat->newcount;
if ($cat->coursecount >= MAX_COURSES_IN_CATEGORY) {
$categories[] = $cat->id;
//.........这里部分代码省略.........
示例5: 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);
}
}
示例6: rebuild_contexts
/**
* Rebuild all related context depth and path caches.
*
* @see context::reset_paths()
* @deprecated since 2.2
* @param array $fixcontexts array of contexts, strongtyped
* @return void
*/
function rebuild_contexts(array $fixcontexts)
{
debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
foreach ($fixcontexts as $fixcontext) {
$fixcontext->reset_paths(false);
}
context_helper::build_all_paths(false);
}
示例7: test_everything_in_accesslib
//.........这里部分代码省略.........
$systemcontext->mark_dirty();
$dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
$this->assertTrue(isset($dirty[$systemcontext->path]));
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$systemcontext->path]));
// ======= $context->reload_if_dirty(); =================================
$DB->delete_records('cache_flags', array());
accesslib_clear_all_caches(false);
load_all_capabilities();
$context = context_course::instance($testcourses[2]);
$page = $DB->get_record('page', array('course'=>$testcourses[2]));
$pagecontext = context_module::instance($page->id);
$context->mark_dirty();
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$context->path]));
$USER->access['test'] = true;
$context->reload_if_dirty();
$this->assertFalse(isset($USER->access['test']));
$context->mark_dirty();
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$context->path]));
$USER->access['test'] = true;
$pagecontext->reload_if_dirty();
$this->assertFalse(isset($USER->access['test']));
// ======= context_helper::build_all_paths() ============================
$oldcontexts = $DB->get_records('context', array(), 'id');
$DB->set_field_select('context', 'path', NULL, "contextlevel <> ".CONTEXT_SYSTEM);
$DB->set_field_select('context', 'depth', 0, "contextlevel <> ".CONTEXT_SYSTEM);
context_helper::build_all_paths();
$newcontexts = $DB->get_records('context', array(), 'id');
$this->assertEquals($oldcontexts, $newcontexts);
unset($oldcontexts);
unset($newcontexts);
// ======= $context->reset_paths() ======================================
$context = context_course::instance($testcourses[2]);
$children = $context->get_child_contexts();
$context->reset_paths(false);
$this->assertSame($DB->get_field('context', 'path', array('id'=>$context->id)), NULL);
$this->assertEquals($DB->get_field('context', 'depth', array('id'=>$context->id)), 0);
foreach ($children as $child) {
$this->assertSame($DB->get_field('context', 'path', array('id'=>$child->id)), NULL);
$this->assertEquals($DB->get_field('context', 'depth', array('id'=>$child->id)), 0);
}
$this->assertEquals(count($children)+1, $DB->count_records('context', array('depth'=>0)));
$this->assertEquals(count($children)+1, $DB->count_records('context', array('path'=>NULL)));
$context = context_course::instance($testcourses[2]);
$context->reset_paths(true);
$context = context_course::instance($testcourses[2]);
$this->assertEquals($DB->get_field('context', 'path', array('id'=>$context->id)), $context->path);
$this->assertEquals($DB->get_field('context', 'depth', array('id'=>$context->id)), $context->depth);
$this->assertEquals(0, $DB->count_records('context', array('depth'=>0)));
$this->assertEquals(0, $DB->count_records('context', array('path'=>NULL)));
// ====== $context->update_moved(); ======================================
accesslib_clear_all_caches(false);
示例8: 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);
}
}
示例9: test_everything_in_accesslib
//.........这里部分代码省略.........
$USER->id = 0;
unset($contexts);
unset($users);
unset($capabilities);
// Now let's do all the remaining tests that break our carefully prepared fake site
// ======= $context->mark_dirty() =======================================
$DB->delete_records('cache_flags', array());
accesslib_clear_all_caches(false);
$systemcontext->mark_dirty();
$dirty = get_cache_flags('accesslib/dirtycontexts', time() - 2);
$this->assertTrue(isset($dirty[$systemcontext->path]));
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$systemcontext->path]));
// ======= $context->reload_if_dirty(); =================================
$DB->delete_records('cache_flags', array());
accesslib_clear_all_caches(false);
load_all_capabilities();
$context = context_course::instance($testcourses[2]);
$page = $DB->get_record('page', array('course' => $testcourses[2]));
$pagecontext = context_module::instance($page->id);
$context->mark_dirty();
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$context->path]));
$USER->access['test'] = true;
$context->reload_if_dirty();
$this->assertFalse(isset($USER->access['test']));
$context->mark_dirty();
$this->assertTrue(isset($ACCESSLIB_PRIVATE->dirtycontexts[$context->path]));
$USER->access['test'] = true;
$pagecontext->reload_if_dirty();
$this->assertFalse(isset($USER->access['test']));
// ======= context_helper::build_all_paths() ============================
$oldcontexts = $DB->get_records('context', array(), 'id');
$DB->set_field_select('context', 'path', NULL, "contextlevel <> " . CONTEXT_SYSTEM);
$DB->set_field_select('context', 'depth', 0, "contextlevel <> " . CONTEXT_SYSTEM);
context_helper::build_all_paths();
$newcontexts = $DB->get_records('context', array(), 'id');
$this->assertIdentical($oldcontexts, $newcontexts);
unset($oldcontexts);
unset($newcontexts);
// ======= $context->reset_paths() ======================================
$context = context_course::instance($testcourses[2]);
$children = $context->get_child_contexts();
$context->reset_paths(false);
$this->assertIdentical($DB->get_field('context', 'path', array('id' => $context->id)), NULL);
$this->assertEqual($DB->get_field('context', 'depth', array('id' => $context->id)), 0);
foreach ($children as $child) {
$this->assertIdentical($DB->get_field('context', 'path', array('id' => $child->id)), NULL);
$this->assertEqual($DB->get_field('context', 'depth', array('id' => $child->id)), 0);
}
$this->assertEqual(count($children) + 1, $DB->count_records('context', array('depth' => 0)));
$this->assertEqual(count($children) + 1, $DB->count_records('context', array('path' => NULL)));
$context = context_course::instance($testcourses[2]);
$context->reset_paths(true);
$context = context_course::instance($testcourses[2]);
$this->assertEqual($DB->get_field('context', 'path', array('id' => $context->id)), $context->path);
$this->assertEqual($DB->get_field('context', 'depth', array('id' => $context->id)), $context->depth);
$this->assertEqual(0, $DB->count_records('context', array('depth' => 0)));
$this->assertEqual(0, $DB->count_records('context', array('path' => NULL)));
// ====== $context->update_moved(); ======================================
accesslib_clear_all_caches(false);
$DB->delete_records('cache_flags', array());
$course = $DB->get_record('course', array('id' => $testcourses[0]));
$context = context_course::instance($course->id);
$oldpath = $context->path;
$miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
$categorycontext = context_coursecat::instance($miscid);
$course->category = $miscid;
示例10: 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);
}
}
示例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);
}
}
示例12: test_version1importmovescourseintocategoryfromrecordid
/**
* Validate that the import can move a course into an existing category
* based on the category's database record id
*/
public function test_version1importmovescourseintocategoryfromrecordid()
{
global $DB;
// Setup.
$data = $this->get_core_course_data('childcategory');
$data['shortname'] = 'categoryidupdate';
$this->run_core_course_import($data);
$categoryid = $DB->get_field('course_categories', 'id', array('name' => 'childcategory'));
$newcategory = new stdClass();
$newcategory->name = $categoryid;
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
context_coursecat::instance($newcategory->id);
context_helper::build_all_paths(true);
$data = array('action' => 'update', 'shortname' => 'categoryidupdate', 'category' => $newcategory->id);
$this->run_core_course_import($data, false);
$DB->delete_records('course_categories', array('id' => $newcategory->id));
$this->assert_record_exists('course', array('shortname' => 'categoryidupdate', 'category' => $newcategory->id));
}