Skip to content

Commit

Permalink
MDL-30789 add new update_status() method to enrol plugins and improve…
Browse files Browse the repository at this point in the history
… enrol cache invalidation
  • Loading branch information
skodak committed Dec 18, 2011
1 parent f89a83b commit af7177d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
15 changes: 6 additions & 9 deletions enrol/instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@

if ($confirm) {
$plugin->delete_instance($instance);
$context->mark_dirty(); // invalidate all enrol caches
redirect($PAGE->url);
}

Expand All @@ -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);
}
}
Expand Down
24 changes: 24 additions & 0 deletions lib/enrollib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,26 @@ public function add_default_instance($course) {
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.
* @param object $instance
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit af7177d

Please sign in to comment.