Commit c7c228a6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Expire inactive users before sending warning emails



Processing the actual inactive users before sending the email warnings
will stop users from receiving warnings when it's already too late for
them to do anything about it.

Change-Id: Ie3d160b858e339d78da068adbc6e2d8b4658ed5a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 19addd7b
......@@ -1487,6 +1487,19 @@ function auth_handle_account_expiries() {
$installationtime = get_config('installation_time');
$lastactive = "COALESCE(u.lastaccess, u.lastlogin, u.ctime, ?)";
// Actual inactive users
if ($users = get_records_sql_array("
SELECT u.id
FROM {usr} u
WHERE $lastactive + $dbexpire < current_timestamp
AND (u.expiry IS NULL OR u.expiry > current_timestamp) AND id > 0", array($installationtime))) {
// Users have become inactive!
foreach ($users as $user) {
deactivate_user($user->id);
}
}
// Inactivity warning emails
if ($users = get_records_sql_array("
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
FROM {usr} u
......@@ -1502,18 +1515,6 @@ function auth_handle_account_expiries() {
set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
}
}
// Actual inactive users
if ($users = get_records_sql_array("
SELECT u.id
FROM {usr} u
WHERE $lastactive + $dbexpire < current_timestamp
AND (u.expiry IS NULL OR u.expiry > current_timestamp) AND id > 0", array($installationtime))) {
// Users have become inactive!
foreach ($users as $user) {
deactivate_user($user->id);
}
}
}
// Institution membership expiry
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment