MDL-40428 Libraries: Deprecated delete_context
This commit is contained in:
+1
-1
@@ -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));
|
||||
|
||||
+1
-1
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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));
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-1
@@ -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 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user