Skip to content
Browse files

Merge branch 'w51_MDL-30789_m22_enrolupdatestatus' of git://github.co…

…m/skodak/moodle into MOODLE_22_STABLE
  • Loading branch information...
2 parents e50e70d + 9cf83e6 commit 415be0ff9410d5a6fe8c30685bdd998857581b4e Sam Hemelryk committed Dec 19, 2011
Showing with 30 additions and 9 deletions.
  1. +6 −9 enrol/instances.php
  2. +24 −0 lib/enrollib.php
View
15 enrol/instances.php
@@ -98,7 +98,6 @@
if ($confirm) {
$plugin->delete_instance($instance);
- $context->mark_dirty(); // invalidate all enrol caches
redirect($PAGE->url);
}
@@ -113,19 +112,17 @@
} else if ($action === 'disable') {
$instance = $instances[$instanceid];
- if ($instance->status == ENROL_INSTANCE_ENABLED) {
- $instance->status = ENROL_INSTANCE_DISABLED;
- $DB->update_record('enrol', $instance);
- $context->mark_dirty(); // invalidate all enrol caches
+ $plugin = $plugins[$instance->enrol];
+ if ($instance->status != ENROL_INSTANCE_DISABLED) {
+ $plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
redirect($PAGE->url);
}
} else if ($action === 'enable') {
$instance = $instances[$instanceid];
- if ($instance->status == ENROL_INSTANCE_DISABLED) {
- $instance->status = ENROL_INSTANCE_ENABLED;
- $DB->update_record('enrol', $instance);
- $context->mark_dirty(); // invalidate all enrol caches
+ $plugin = $plugins[$instance->enrol];
+ if ($instance->status != ENROL_INSTANCE_ENABLED) {
+ $plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
redirect($PAGE->url);
}
}
View
24 lib/enrollib.php
@@ -1554,6 +1554,26 @@ public function add_default_instance($course) {
}
/**
+ * 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.
* @param object $instance
* @return void
@@ -1579,6 +1599,10 @@ public function delete_instance($instance) {
// finally drop the enrol row
$DB->delete_records('enrol', array('id'=>$instance->id));
+
+ // invalidate all enrol caches
+ $context = context_course::instance($instance->courseid);
+ $context->mark_dirty();
}
/**

0 comments on commit 415be0f

Please sign in to comment.
Something went wrong with that request. Please try again.