Skip to content

Commit df997f8

Browse files
committed
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self] MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self] MOV [enrolstartdate,core],[enrolstartdate,enrol_self] MOV [enrolenddate,core],[enrolenddate,enrol_self] CPY [welcometocourse,core],[welcometocourse,enrol_self] CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self] MOV [notenrollable,core],[notenrollable,core_enrol] MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self] MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self] MOV [coursemanager,core_admin],[coursecontact,core_admin] MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin] MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual] MOV [enrolme,core],[enrolme,core_enrol] MOV [unenrol,core],[unenrol,core_enrol] MOV [unenrolme,core],[unenrolme,core_enrol] MOV [enrolmentnew,core],[enrolmentnew,core_enrol] MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol] MOV [enrolments,core],[enrolments,core_enrol] MOV [enrolperiod,core],[enrolperiod,core_enrol] MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol] AMOS END
1 parent 2c9bb9c commit df997f8

File tree

225 files changed

+11021
-7605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+11021
-7605
lines changed

admin/bloglevelupgrade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
$a->blogcount = 0;
4949

5050
foreach ($bloggers as $blogger) {
51-
$courses = get_my_courses($blogger->userid);
51+
$courses = enrol_get_users_courses($blogger->userid, true, 'groupmode,groupmodeforce');
5252
$blogentries = $DB->get_records('post', array('module' => 'blog', 'userid' => $blogger->userid));
5353

5454
foreach ($courses as $course) {

admin/cron.php

+9-79
Original file line numberDiff line numberDiff line change
@@ -205,34 +205,6 @@
205205
}
206206
mtrace('Finished admin reports');
207207

208-
mtrace('Removing expired enrolments ...', ''); // See MDL-8785
209-
$timenow = time();
210-
$somefound = false;
211-
// The preferred way saves memory, datablib
212-
// find courses where limited enrolment is enabled
213-
$sql = "SELECT ra.roleid, ra.userid, ra.contextid
214-
FROM {course} c
215-
JOIN {context} cx ON cx.instanceid = c.id
216-
JOIN {role_assignments} ra ON ra.contextid = cx.id
217-
WHERE cx.contextlevel = '".CONTEXT_COURSE."'
218-
AND ra.timeend > 0
219-
AND ra.timeend < ?
220-
AND c.enrolperiod > 0";
221-
if ($rs = $DB->get_recordset_sql($sql, array($timenow))) {
222-
foreach ($rs as $oldenrolment) {
223-
role_unassign($oldenrolment->roleid, $oldenrolment->userid, 0, $oldenrolment->contextid);
224-
$somefound = true;
225-
}
226-
$rs->close();
227-
}
228-
if ($somefound) {
229-
mtrace('Done');
230-
} else {
231-
mtrace('none found');
232-
}
233-
234-
235-
236208
mtrace('Starting main gradebook job ...');
237209
grade_cron();
238210
mtrace('done.');
@@ -270,41 +242,6 @@
270242
if ($random100 < 20) { // Approximately 20% of the time.
271243
mtrace("Running clean-up tasks...");
272244

273-
/// Unenrol users who haven't logged in for $CFG->longtimenosee
274-
275-
if ($CFG->longtimenosee) { // value in days
276-
$cuttime = $timenow - ($CFG->longtimenosee * 3600 * 24);
277-
$rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
278-
FROM {user_lastaccess}
279-
WHERE courseid != ".SITEID."
280-
AND timeaccess < ?", array($cuttime));
281-
foreach ($rs as $assign) {
282-
if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
283-
if (role_unassign(0, $assign->userid, 0, $context->id)) {
284-
mtrace("removing user $assign->userid from course $assign->courseid as they have not accessed the course for over $CFG->longtimenosee days");
285-
}
286-
}
287-
}
288-
$rs->close();
289-
/// Execute the same query again, looking for remaining records and deleting them
290-
/// if the user hasn't moodle/course:participate in the CONTEXT_COURSE context (orphan records)
291-
$rs = $DB->get_recordset_sql ("SELECT id, userid, courseid
292-
FROM {user_lastaccess}
293-
WHERE courseid != ".SITEID."
294-
AND timeaccess < ?", array($cuttime));
295-
foreach ($rs as $assign) {
296-
if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
297-
if (!is_enrolled($context, $assign->userid) and !is_viewing($context, $assign->userid)) {
298-
$DB->delete_records('user_lastaccess', array('userid'=>$assign->userid, 'courseid'=>$assign->courseid));
299-
mtrace("Deleted orphan user_lastaccess for user $assign->userid from course $assign->courseid");
300-
}
301-
}
302-
}
303-
$rs->close();
304-
}
305-
flush();
306-
307-
308245
/// Delete users who haven't confirmed within required period
309246

310247
if (!empty($CFG->deleteunconfirmed)) {
@@ -370,9 +307,6 @@
370307
}
371308
flush();
372309

373-
sync_metacourses();
374-
mtrace('Synchronised metacourses');
375-
376310
//
377311
// generate new password emails for users
378312
//
@@ -464,20 +398,16 @@
464398
unset($authplugin);
465399
}
466400

467-
/// Run the enrolment cron, if any
468-
if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
469-
$plugins = array($CFG->enrol);
470-
}
471-
require_once($CFG->dirroot .'/enrol/enrol.class.php');
472-
foreach ($plugins as $p) {
473-
$enrol = enrolment_factory::factory($p);
474-
if (method_exists($enrol, 'cron')) {
475-
$enrol->cron();
476-
}
477-
if (!empty($enrol->log)) {
478-
mtrace($enrol->log);
401+
mtrace("Running enrol crons if required...");
402+
$enrols = enrol_get_plugins(true);
403+
foreach($enrols as $ename=>$enrol) {
404+
// do this for all plugins, disabled plugins might want to cleanup stuff such as roles
405+
if (!$enrol->is_cron_required()) {
406+
continue;
479407
}
480-
unset($enrol);
408+
mtrace("Running cron for enrol_$ename...");
409+
$enrol->cron();
410+
$enrol->set_config('lastcron', time());
481411
}
482412

483413
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {

admin/enrol.php

+109-130
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,120 @@
11
<?php
2-
// enrol.php - allows admin to edit all enrollment variables
3-
// Yes, enrol is correct English spelling.
4-
5-
require_once('../config.php');
6-
require_once($CFG->libdir.'/adminlib.php');
7-
8-
$enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
9-
$savesettings = optional_param('savesettings', 0, PARAM_BOOL);
10-
11-
admin_externalpage_setup('enrolment');
12-
13-
if (!isset($CFG->sendcoursewelcomemessage)) {
14-
set_config('sendcoursewelcomemessage', 1);
15-
}
16-
17-
18-
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
19-
20-
/// Save settings
21-
22-
if ($frm = data_submitted() and !$savesettings) {
23-
if (!confirm_sesskey()) {
24-
print_error('confirmsesskeybad', 'error');
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Enrol config manipulation script.
19+
*
20+
* @package core
21+
* @subpackage enrol
22+
* @copyright 2010 Petr Skoda {@link http://skodak.org}
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
require_once('../config.php');
27+
require_once($CFG->libdir.'/adminlib.php');
28+
29+
$action = required_param('action', PARAM_ACTION);
30+
$enrol = required_param('enrol', PARAM_SAFEDIR);
31+
$confirm = optional_param('confirm', 0, PARAM_BOOL);
32+
33+
$PAGE->set_url('/admin/enrol.php');
34+
35+
require_login();
36+
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
37+
require_sesskey();
38+
39+
$enabled = enrol_get_plugins(true);
40+
$all = enrol_get_plugins(false);
41+
42+
$return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
43+
44+
switch ($action) {
45+
case 'disable':
46+
unset($enabled[$enrol]);
47+
set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
48+
break;
49+
50+
case 'enable':
51+
if (!isset($all[$enrol])) {
52+
break;
2553
}
26-
if (empty($frm->enable)) {
27-
$frm->enable = array();
54+
$enabled = array_keys($enabled);
55+
$enabled[] = $enrol;
56+
set_config('enrol_plugins_enabled', implode(',', $enabled));
57+
break;
58+
59+
case 'up':
60+
if (!isset($enabled[$enrol])) {
61+
break;
2862
}
29-
if (empty($frm->default)) {
30-
$frm->default = '';
31-
}
32-
if ($frm->default && $frm->default != 'manual' && !in_array($frm->default, $frm->enable)) {
33-
$frm->enable[] = $frm->default;
34-
}
35-
asort($frm->enable);
36-
$frm->enable = array_merge(array('manual'), $frm->enable); // make sure manual plugin is called first
37-
set_config('enrol_plugins_enabled', implode(',', $frm->enable));
38-
set_config('enrol', $frm->default);
39-
redirect("enrol.php", get_string("changessaved"), 1);
40-
41-
} else if ($frm = data_submitted() and $savesettings) {
42-
if (!confirm_sesskey()) {
43-
print_error('confirmsesskeybad', 'error');
44-
}
45-
set_config('sendcoursewelcomemessage', required_param('sendcoursewelcomemessage', PARAM_BOOL));
46-
}
47-
48-
/// Print the form
49-
50-
$str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
51-
52-
echo $OUTPUT->header();
53-
54-
$modules = get_plugin_list('enrol');
55-
$options = array();
56-
foreach ($modules as $module => $moduledir) {
57-
$options[$module] = get_string("enrolname", "enrol_$module");
58-
}
59-
asort($options);
60-
61-
echo $OUTPUT->box(get_string('configenrolmentplugins', 'admin'));
62-
63-
echo "<form id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
64-
echo "<div>";
65-
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
66-
67-
$table = new html_table();
68-
$table->head = array(get_string('name'), get_string('enable'), get_string('default'), $str->settings);
69-
$table->align = array('left', 'center', 'center', 'center');
70-
$table->size = array('60%', '', '', '15%');
71-
$table->attributes['class'] = 'generaltable enrolplugintable';
72-
$table->data = array();
73-
74-
$enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
75-
foreach ($modules as $module => $moduledir) {
76-
77-
// skip if directory is empty
78-
if (!file_exists("$moduledir/enrol.php")) {
79-
continue;
63+
$enabled = array_keys($enabled);
64+
$enabled = array_flip($enabled);
65+
$current = $enabled[$enrol];
66+
if ($current == 0) {
67+
break; //already at the top
8068
}
81-
82-
$name = get_string("enrolname", "enrol_$module");
83-
$plugin = enrolment_factory::factory($module);
84-
$enable = '<input type="checkbox" name="enable[]" value="'.$module.'"';
85-
if (in_array($module, $enabledplugins)) {
86-
$enable .= ' checked="checked"';
69+
$enabled = array_flip($enabled);
70+
$enabled[$current] = $enabled[$current - 1];
71+
$enabled[$current - 1] = $enrol;
72+
set_config('enrol_plugins_enabled', implode(',', $enabled));
73+
break;
74+
75+
case 'down':
76+
if (!isset($enabled[$enrol])) {
77+
break;
8778
}
88-
if ($module == 'manual') {
89-
$enable .= ' disabled="disabled"';
79+
$enabled = array_keys($enabled);
80+
$enabled = array_flip($enabled);
81+
$current = $enabled[$enrol];
82+
if ($current == count($enabled) - 1) {
83+
break; //already at the end
9084
}
91-
$enable .= ' />';
92-
if (method_exists($plugin, 'print_entry')) {
93-
$default = '<input type="radio" name="default" value="'.$module.'"';
94-
if ($CFG->enrol == $module) {
95-
$default .= ' checked="checked"';
96-
}
97-
$default .= ' />';
85+
$enabled = array_flip($enabled);
86+
$enabled[$current] = $enabled[$current + 1];
87+
$enabled[$current + 1] = $enrol;
88+
set_config('enrol_plugins_enabled', implode(',', $enabled));
89+
break;
90+
91+
case 'uninstall':
92+
echo $OUTPUT->header();
93+
echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
94+
95+
if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
96+
$strplugin = get_string('pluginname', 'enrol_'.$enrol);
9897
} else {
99-
$default = '';
98+
$strplugin = $enrol;
10099
}
101-
$table->data[$name] = array($name, $enable, $default,
102-
'<a href="enrol_config.php?enrol='.$module.'">'.$str->edit.'</a>');
103-
}
104-
asort($table->data);
105-
106-
echo html_writer::table($table);
107-
108-
echo "<div style=\"text-align:center\"><input type=\"submit\" value=\"".get_string("savechanges")."\" /></div>\n";
109-
echo "</div>";
110-
echo "</form>";
111100

112-
echo '<hr />';
113-
114-
$yesnooptions = array(0=>get_string('no'), 1=>get_string('yes'));
115-
116-
echo '<form id="adminsettings" method="post" action="enrol.php">';
117-
echo '<div class="settingsform clearfix">';
118-
echo $OUTPUT->heading(get_string('commonsettings', 'admin'));
119-
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
120-
echo '<input type="hidden" name="savesettings" value="1" />';
121-
echo '<fieldset>';
122-
echo '<div class="form-item clearfix" id="admin-sendcoursewelcomemessage">';
123-
124-
echo '<div class="form-label"><label for = "menusendcoursewelcomemessage">' . get_string('sendcoursewelcomemessage', 'admin');
125-
echo '<span class="form-shortname">sendcoursewelcomemessage</span>';
126-
echo '</label></div>';
127-
echo '<div class="form-setting"><div class="form-checkbox defaultsnext">';
128-
echo html_writer::select($yesnooptions, 'sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, false);
129-
echo '</div><div class="form-defaultinfo">'.get_string('defaultsettinginfo', 'admin', get_string('yes')).'</div></div>';
130-
echo '<div class="form-description">' . get_string('configsendcoursewelcomemessage', 'admin') . '</div>';
131-
echo '</div>';
132-
133-
echo '</fieldset>';
134-
135-
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
136-
echo '</div>';
137-
echo '</form>';
138-
139-
echo $OUTPUT->footer();
101+
if (!$confirm) {
102+
$uurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1));
103+
echo $OUTPUT->confirm(get_string('uninstallconfirm', 'enrol', $strplugin), $uurl, $return);
104+
echo $OUTPUT->footer();
105+
exit;
106+
107+
} else { // Delete everything!!
108+
uninstall_plugin('enrol', $enrol);
109+
110+
$a->plugin = $strplugin;
111+
$a->directory = "$CFG->dirroot/enrol/$enrol";
112+
echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess');
113+
echo $OUTPUT->continue_button($return);
114+
echo $OUTPUT->footer();
115+
exit;
116+
}
117+
}
140118

141119

120+
redirect($return);

0 commit comments

Comments
 (0)