mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-30789 add new update_status() method to enrol plugins and improve enrol cache invalidation
This commit is contained in:
parent
f89a83b87b
commit
af7177dbcb
2 changed files with 30 additions and 9 deletions
|
@ -98,7 +98,6 @@ if ($canconfig and $action and confirm_sesskey()) {
|
||||||
|
|
||||||
if ($confirm) {
|
if ($confirm) {
|
||||||
$plugin->delete_instance($instance);
|
$plugin->delete_instance($instance);
|
||||||
$context->mark_dirty(); // invalidate all enrol caches
|
|
||||||
redirect($PAGE->url);
|
redirect($PAGE->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,19 +112,17 @@ if ($canconfig and $action and confirm_sesskey()) {
|
||||||
|
|
||||||
} else if ($action === 'disable') {
|
} else if ($action === 'disable') {
|
||||||
$instance = $instances[$instanceid];
|
$instance = $instances[$instanceid];
|
||||||
if ($instance->status == ENROL_INSTANCE_ENABLED) {
|
$plugin = $plugins[$instance->enrol];
|
||||||
$instance->status = ENROL_INSTANCE_DISABLED;
|
if ($instance->status != ENROL_INSTANCE_DISABLED) {
|
||||||
$DB->update_record('enrol', $instance);
|
$plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
|
||||||
$context->mark_dirty(); // invalidate all enrol caches
|
|
||||||
redirect($PAGE->url);
|
redirect($PAGE->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ($action === 'enable') {
|
} else if ($action === 'enable') {
|
||||||
$instance = $instances[$instanceid];
|
$instance = $instances[$instanceid];
|
||||||
if ($instance->status == ENROL_INSTANCE_DISABLED) {
|
$plugin = $plugins[$instance->enrol];
|
||||||
$instance->status = ENROL_INSTANCE_ENABLED;
|
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||||
$DB->update_record('enrol', $instance);
|
$plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
|
||||||
$context->mark_dirty(); // invalidate all enrol caches
|
|
||||||
redirect($PAGE->url);
|
redirect($PAGE->url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1553,6 +1553,26 @@ abstract class enrol_plugin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update instance status
|
||||||
|
*
|
||||||
|
* Override when plugin needs to do some action when enabled or disabled.
|
||||||
|
*
|
||||||
|
* @param stdClass $instance
|
||||||
|
* @param int $newstatus ENROL_INSTANCE_ENABLED, ENROL_INSTANCE_DISABLED
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function update_status($instance, $newstatus) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$instance->status = $newstatus;
|
||||||
|
$DB->update_record('enrol', $instance);
|
||||||
|
|
||||||
|
// invalidate all enrol caches
|
||||||
|
$context = context_course::instance($instance->courseid);
|
||||||
|
$context->mark_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete course enrol plugin instance, unenrol all users.
|
* Delete course enrol plugin instance, unenrol all users.
|
||||||
* @param object $instance
|
* @param object $instance
|
||||||
|
@ -1579,6 +1599,10 @@ abstract class enrol_plugin {
|
||||||
|
|
||||||
// finally drop the enrol row
|
// finally drop the enrol row
|
||||||
$DB->delete_records('enrol', array('id'=>$instance->id));
|
$DB->delete_records('enrol', array('id'=>$instance->id));
|
||||||
|
|
||||||
|
// invalidate all enrol caches
|
||||||
|
$context = context_course::instance($instance->courseid);
|
||||||
|
$context->mark_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue