Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-23719 longtimenosee finally reimplemented - it is now used in sel…
Browse files Browse the repository at this point in the history
…f enrol only. It should be faster, easier to configure and finally there should not be any "my users are disappearing" reports in the future
  • Loading branch information
skodak committed Aug 9, 2010
1 parent 8f639ad commit 770ab27
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 39 deletions.
12 changes: 0 additions & 12 deletions admin/settings/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,6 @@
$ADMIN->add('server', $temp);

$temp = new admin_settingpage('cleanup', get_string('cleanup', 'admin'));
$temp->add(new admin_setting_configselect('longtimenosee', get_string('longtimenosee', 'admin'), get_string('configlongtimenosee', 'admin'), 120, array(0 => get_string('never'),
1000 => get_string('numdays', '', 1000),
365 => get_string('numdays', '', 365),
180 => get_string('numdays', '', 180),
150 => get_string('numdays', '', 150),
120 => get_string('numdays', '', 120),
90 => get_string('numdays', '', 90),
60 => get_string('numdays', '', 60),
30 => get_string('numdays', '', 30),
21 => get_string('numdays', '', 21),
14 => get_string('numdays', '', 14),
7 => get_string('numdays', '', 7) )));
$temp->add(new admin_setting_configselect('deleteunconfirmed', get_string('deleteunconfirmed', 'admin'), get_string('configdeleteunconfirmed', 'admin'), 168, array(0 => get_string('never'),
168 => get_string('numdays', '', 7),
144 => get_string('numdays', '', 6),
Expand Down
4 changes: 0 additions & 4 deletions enrol/manual/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,5 @@ public function add_instance($course, array $fields = NULL) {

return parent::add_instance($course, $fields);
}

public function cron() {
// TODO: deal with $CFG->longtimenosee
}
}

11 changes: 10 additions & 1 deletion enrol/self/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@
defined('MOODLE_INTERNAL') || die();

function xmldb_enrol_self_install() {
global $CFG;
global $CFG, $DB;

// migrate welcome message
if (isset($CFG->sendcoursewelcomemessage)) {
set_config('sendcoursewelcomemessage', $CFG->sendcoursewelcomemessage, 'enrol_self');
unset_config('sendcoursewelcomemessage');
}

// migrate long-time-no-see feature settings
if (isset($CFG->longtimenosee)) {
$nosee = $CFG->longtimenosee * 3600 * 24;
set_config('longtimenosee', $nosee, 'enrol_self');
$DB->set_field('enrol', 'customint2', $nosee, array('enrol'=>'self'));
unset_config('longtimenosee');
}
}
5 changes: 3 additions & 2 deletions enrol/self/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
$instance->name = $data->name;
$instance->password = $data->password;
$instance->customint1 = $data->customint1;
$instance->customint2 = $data->customint2;
$instance->roleid = $data->roleid;
$instance->enrolperiod = $data->enrolperiod;
$instance->enrolstartdate = $data->enrolstartdate;
Expand All @@ -77,8 +78,8 @@
$DB->update_record('enrol', $instance);

} else {
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'roleid'=>$data->roleid,
'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2,
'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
$plugin->add_instance($course, $fields);
}

Expand Down
17 changes: 17 additions & 0 deletions enrol/self/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ function definition() {
$mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_self'), array('optional' => true));
$mform->setDefault('enrolenddate', 0);

$options = array(0 => get_string('never'),
1800 * 3600 * 24 => get_string('numdays', '', 1800),
1000 * 3600 * 24 => get_string('numdays', '', 1000),
365 * 3600 * 24 => get_string('numdays', '', 365),
180 * 3600 * 24 => get_string('numdays', '', 180),
150 * 3600 * 24 => get_string('numdays', '', 150),
120 * 3600 * 24 => get_string('numdays', '', 120),
90 * 3600 * 24 => get_string('numdays', '', 90),
60 * 3600 * 24 => get_string('numdays', '', 60),
30 * 3600 * 24 => get_string('numdays', '', 30),
21 * 3600 * 24 => get_string('numdays', '', 21),
14 * 3600 * 24 => get_string('numdays', '', 14),
7 * 3600 * 24 => get_string('numdays', '', 7));
$mform->addElement('select', 'customint2', get_string('longtimenosee', 'enrol_self'), $options);
$mform->setDefault('customint2', $plugin->get_config('longtimenosee'));
$mform->addHelpButton('customint2', 'longtimenosee', 'enrol_self');

$mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'courseid');

Expand Down
2 changes: 2 additions & 0 deletions enrol/self/lang/en/enrol_self.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
$string['groupkey_help'] = 'In addition to restricting access to the course to only those who know the key, use of a group enrolment key means users are automatically added to the group when they enrol in the course.
To use a group enrolment key, an enrolment key must be specified in the course settings as well as the group enrolment key in the group settings.';
$string['longtimenosee'] = 'Unenrol inactive after';
$string['longtimenosee_help'] = 'If users haven\'t accessed a course for a long time, then they are automatically unenrolled. This parameter specifies that time limit.';
$string['password'] = 'Enrolment key';
$string['password_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key.
Expand Down
49 changes: 49 additions & 0 deletions enrol/self/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public function add_default_instance($course) {
global $DB;

$fields = array('customint1' => $this->get_config('groupkey'),
'customint2' => $this->get_config('longtimenosee'),
'enrolperiod' => $this->get_config('enrolperiod', 0),
'status' => $this->get_config('status'),
'roleid' => $this->get_config('roleid', 0));
Expand Down Expand Up @@ -261,6 +262,54 @@ protected function email_welcome_message($instance, $user) {

email_to_user($user, $contact, $subject, $message);
}

/**
* Enrol self cron support
* @return void
*/
public function cron() {
global $DB;

if (!enrol_is_enabled('self')) {
return;
}

$plugin = enrol_get_plugin('self');

$now = time();

// first deal with users that did not log in for a really long time
$sql = "SELECT e.*, ue.userid
FROM {user_enrolments} ue
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
JOIN {user} u ON u.id = ue.userid
WHERE :now - u.lastaccess > e.customint2";
$rs = $DB->get_recordset_sql($sql, array('now'=>$now));
foreach ($rs as $instance) {
$userid = $instance->userid;
unset($instance->userid);
$plugin->unenrol_user($instance, $userid);
mtrace("unenrolling user $userid from course $instance->courseid as they have did not log in for $instance->customint2 days");
}
$rs->close();

// now unenrol from course user did not visit for a long time
$sql = "SELECT e.*, ue.userid
FROM {user_enrolments} ue
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
JOIN {user_lastaccess} ul ON (ul.userid = ue.userid AND ul.courseid = e.courseid)
WHERE :now - ul.timeaccess > e.customint2";
$rs = $DB->get_recordset_sql($sql, array('now'=>$now));
foreach ($rs as $instance) {
$userid = $instance->userid;
unset($instance->userid);
$plugin->unenrol_user($instance, $userid);
mtrace("unenrolling user $userid from course $instance->courseid as they have did not access course for $instance->customint2 days");
}
$rs->close();

flush();
}
}


16 changes: 16 additions & 0 deletions enrol/self/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,20 @@
$settings->add(new admin_setting_configtext('enrol_self/enrolperiod',
get_string('enrolperiod', 'enrol_self'), get_string('enrolperiod_desc', 'enrol_self'), 0, PARAM_INT));

$options = array(0 => get_string('never'),
1800 * 3600 * 24 => get_string('numdays', '', 1800),
1000 * 3600 * 24 => get_string('numdays', '', 1000),
365 * 3600 * 24 => get_string('numdays', '', 365),
180 * 3600 * 24 => get_string('numdays', '', 180),
150 * 3600 * 24 => get_string('numdays', '', 150),
120 * 3600 * 24 => get_string('numdays', '', 120),
90 * 3600 * 24 => get_string('numdays', '', 90),
60 * 3600 * 24 => get_string('numdays', '', 60),
30 * 3600 * 24 => get_string('numdays', '', 30),
21 * 3600 * 24 => get_string('numdays', '', 21),
14 * 3600 * 24 => get_string('numdays', '', 14),
7 * 3600 * 24 => get_string('numdays', '', 7));
$settings->add(new admin_setting_configselect('enrol_self/longtimenosee',
get_string('longtimenosee', 'enrol_self'), get_string('longtimenosee_help', 'enrol_self'), 0, $options));

}
3 changes: 2 additions & 1 deletion enrol/self/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2010061600;
$plugin->version = 2010080900;
$plugin->cron = 180;
2 changes: 0 additions & 2 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
$string['configlocale'] = 'Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left blank.';
$string['configloginhttps'] = 'Turning this on will make Moodle use a secure https connection just for the login page (providing a secure login), and then afterwards revert back to the normal http URL for general speed. CAUTION: this setting REQUIRES https to be specifically enabled on the web server - if it is not then YOU COULD LOCK YOURSELF OUT OF YOUR SITE.';
$string['configloglifetime'] = 'This specifies the length of time you want to keep logs about user activity. Logs that are older than this age are automatically deleted. It is best to keep logs as long as possible, in case you need them, but if you have a very busy server and are experiencing performance problems, then you may want to lower the log lifetime. Values lower than 30 are not recommended because statistics may not work properly.';
$string['configlongtimenosee'] = 'If students haven\'t logged in for a very long time, then they are automatically unsubscribed from courses. This parameter specifies that time limit.';
$string['configlookahead'] = 'Days to look ahead';
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
$string['configmaxbytes'] = 'This specifies a maximum size that uploaded files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody. In turn, maxbytes limits the range of sizes that can be chosen at course level or module level. If \'Server Limit\' is chosen, the server maximum allowed by the server will be used.';
Expand Down Expand Up @@ -635,7 +634,6 @@
$string['log'] = 'Logs';
$string['loginhttps'] = 'Use HTTPS for logins';
$string['loglifetime'] = 'Keep logs for';
$string['longtimenosee'] = 'Unsubscribe users from courses after';
$string['longtimewarning'] = '<b>Please note that this process can take a long time.</b>';
$string['mail'] = 'Email';
$string['mailnewline'] = 'Newline characters in mail';
Expand Down
5 changes: 0 additions & 5 deletions theme/boxxie/style/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,6 @@ h2.headingblock {
text-align: center;
}

#page-user-index #participantsform #longtimenosee {
font-style: italic;
font-size: 0.95em;
}

#page-user-index #participants {
margin: 25px auto;
width: 85%;
Expand Down
6 changes: 0 additions & 6 deletions theme/canvas/style/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,6 @@ padding: 0
text-align: center;
}

#longtimenosee {
font-style: italic;
font-size: 0.95em;
text-align: center;
}

#participants {
width: 100%;
margin: 1em auto 0;
Expand Down
2 changes: 0 additions & 2 deletions theme/standard/style/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ form.popupform label {margin-right: 0.5em;}
#userselector_options {font-size: 0.75em;}
.userinfobox {border-color: #DDDDDD;}
.userinfobox .links {font-size: 0.7em;}
#page-user-index #longtimenosee {font-size: 0.8em;}
.iplookup #header h1.headermain {font-size:1em;}
.iplookup #note {font-size:0.8em;font-style: italic;}
.groupinfobox {border-color: #DDDDDD;width: 60%;margin-left: 20%;margin-right: 20%;}
.userinfobox {width:80%;margin:10px auto;}
#page-user-index h2 {text-align: center;}
#page-user-index #longtimenosee,
#page-user-index #showall {text-align: center;}
#page-user-profile .remoteuserinfo, #page-user-view .remoteuserinfo{background-color:#D2EBFF;text-align:center;padding:3px;}
#page-user-profile .messagebox {text-align:center;margin-left:auto;margin-right:auto;padding:5px;}
Expand Down
4 changes: 0 additions & 4 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,6 @@
echo '<input type="hidden" name="returnto" value="'.s(me()).'" />';
}

if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
}

if ($mode === MODE_USERDETAILS) { // Print simple listing
if ($totalcount < 1) {
echo $OUTPUT->heading(get_string('nothingtodisplay'));
Expand Down

0 comments on commit 770ab27

Please sign in to comment.