diff --git a/course/lib.php b/course/lib.php index 5178efc8d77..787160b6fec 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1534,7 +1534,7 @@ function course_delete_module($cmid) { 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY)); // Delete the context. - delete_context(CONTEXT_MODULE, $cm->id); + context_helper::delete_instance(CONTEXT_MODULE, $cm->id); // Delete the module from the course_modules table. $DB->delete_records('course_modules', array('id' => $cm->id)); diff --git a/course/modlib.php b/course/modlib.php index daf6d9c11dc..88eefe5d642 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -99,7 +99,7 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) { if (!$returnfromfunc or !is_number($returnfromfunc)) { // Undo everything we can. $modcontext = context_module::instance($moduleinfo->coursemodule); - delete_context(CONTEXT_MODULE, $moduleinfo->coursemodule); + context_helper::delete_instance(CONTEXT_MODULE, $moduleinfo->coursemodule); $DB->delete_records('course_modules', array('id'=>$moduleinfo->coursemodule)); if (!is_number($returnfromfunc)) { diff --git a/lib/accesslib.php b/lib/accesslib.php index f1e9866d130..e730f4510e2 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -7246,29 +7246,6 @@ function context_instance_preload_sql($joinon, $contextlevel, $tablealias) { return array($select, $join); } -/** - * Remove a context record and any dependent entries, - * removes context from static context cache too - * - * @deprecated since 2.2, use $context->delete_content() instead - * @param int $contextlevel - * @param int $instanceid - * @param bool $deleterecord false means keep record for now - * @return bool returns true or throws an exception - */ -function delete_context($contextlevel, $instanceid, $deleterecord = true) { - if ($deleterecord) { - context_helper::delete_instance($contextlevel, $instanceid); - } else { - $classname = context_helper::get_class_for_level($contextlevel); - if ($context = $classname::instance($instanceid, IGNORE_MISSING)) { - $context->delete_content(); - } - } - - return true; -} - /** * Get a URL for a context, if there is a natural one. For example, for * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the diff --git a/lib/adminlib.php b/lib/adminlib.php index 4a76f82c164..b5231114a87 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -208,9 +208,7 @@ function uninstall_plugin($type, $name) { // delete module contexts if ($coursemods) { foreach ($coursemods as $coursemod) { - if (!delete_context(CONTEXT_MODULE, $coursemod->id)) { - echo $OUTPUT->notification("Could not delete the context for $strpluginname with id = $coursemod->id"); - } + context_helper::delete_instance(CONTEXT_MODULE, $coursemod->id); } } diff --git a/lib/blocklib.php b/lib/blocklib.php index ae413cfb6e7..fae8c8cdba5 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1981,7 +1981,7 @@ function blocks_delete_instance($instance, $nolongerused = false, $skipblockstab if ($block = block_instance($instance->blockname, $instance)) { $block->instance_delete(); } - delete_context(CONTEXT_BLOCK, $instance->id); + context_helper::delete_instance(CONTEXT_BLOCK, $instance->id); if (!$skipblockstables) { $DB->delete_records('block_positions', array('blockinstanceid' => $instance->id)); diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php index b3ddf1ac878..05bbc6ba592 100644 --- a/lib/coursecatlib.php +++ b/lib/coursecatlib.php @@ -1400,7 +1400,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate { // finally delete the category and it's context $DB->delete_records('course_categories', array('id' => $this->id)); - delete_context(CONTEXT_COURSECAT, $this->id); + context_helper::delete_instance(CONTEXT_COURSECAT, $this->id); add_to_log(SITEID, "category", "delete", "index.php", "$this->name (ID $this->id)"); cache_helper::purge_by_event('changesincoursecat'); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index dbe8f09176b..99715477cc1 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4111,3 +4111,29 @@ function mark_context_dirty($path) { } } } + +/** + * Remove a context record and any dependent entries, + * removes context from static context cache too + * + * @deprecated since Moodle 2.2 + * @see context_helper::delete_instance() or context::delete_content() + * @param int $contextlevel + * @param int $instanceid + * @param bool $deleterecord false means keep record for now + * @return bool returns true or throws an exception + */ +function delete_context($contextlevel, $instanceid, $deleterecord = true) { + if ($deleterecord) { + debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER); + context_helper::delete_instance($contextlevel, $instanceid); + } else { + debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER); + $classname = context_helper::get_class_for_level($contextlevel); + if ($context = $classname::instance($instanceid, IGNORE_MISSING)) { + $context->delete_content(); + } + } + + return true; +} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index f2912d186af..7b4d180a97a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4191,7 +4191,7 @@ function delete_user(stdClass $user) { session_kill_user($user->id); // now do a final accesslib cleanup - removes all role assignments in user context and context itself - delete_context(CONTEXT_USER, $user->id); + context_helper::delete_instance(CONTEXT_USER, $user->id); // workaround for bulk deletes of users with the same email address $delname = "$user->email.".time(); @@ -4837,7 +4837,7 @@ function delete_course($courseorid, $showfeedback = true) { remove_course_contents($courseid, $showfeedback); // delete the course and related context instance - delete_context(CONTEXT_COURSE, $courseid); + context_helper::delete_instance(CONTEXT_COURSE, $courseid); // We will update the course's timemodified, as it will be passed to the course_deleted event, // which should know about this updated property, as this event is meant to pass the full course record diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index ed4bdcb8ba3..b67fca5882a 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2462,7 +2462,10 @@ class accesslib_testcase extends advanced_testcase { $this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2]))); delete_context(CONTEXT_COURSE, $testcourses[2]); + $this->assertDebuggingCalled('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER); $this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2]))); + delete_context(CONTEXT_COURSE, $testcourses[2], false); + $this->assertDebuggingCalled('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER); $name = get_contextlevel_name(CONTEXT_COURSE); $this->assertDebuggingCalled('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 8918067f8e3..4d85ef7b50e 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -22,7 +22,8 @@ information provided here is intended especially for developers. * context_instance_preload() is deprecated, please use context_helper::preload_from_record(). * get_contextlevel_name() is deprecated, please use context_helper::get_level_name(). * print_context_name() is deprecated, please use $context->get_context_name(). -* mark_context_dirty() is deprecated, please use $context->mark_dirty(). +* mark_context_dirty($context->path) is deprecated, please use $context->mark_dirty(). +* delete_context() is deprecated, please use $context->delete_content() or context_helper::delete_instance(). === 2.5.1 ===