Duplicate Users - suggest preventing

Duplicate Users - suggest preventing

by Dierk Polzin -
Number of replies: 5

Is there admin toggle that will prevent new users from being created with a duplicate idnumber in the mdl_users table.

Before going off and customizing our code it would be nice to know if something like this already exists or if it could be added.

We have many returning graduate students who take time off and then return. To prevent duplicate records it would be nice if the index of the mdl_user table could block the creation of duplicate users.

Here is my sql code to find duplicates in this table:

# Users with Duplicate ID in the mdl_user table.
SELECT username, idnumber, email, deleted, suspended, lastname, firstname
FROM mdl_user
WHERE idnumber IN (
    SELECT idnumber FROM (
        SELECT idnumber, COUNT(*) cnt
        FROM mdl_user
        GROUP BY idnumber
        HAVING cnt > 1 and cnt < 20 ) AS DUPS
    )
ORDER BY idnumber;

Average of ratings: Useful (1)
In reply to Dierk Polzin

Re: Duplicate Users - suggest preventing

by Luis de Vasconcelos -
Moodle currently doesn't have anything like that - although I agree fully that this would be a very useful feature when implemented.

How do you currently create your new users? Manually or do you use some kind of enrollment plugin?
In reply to Luis de Vasconcelos

Re: Duplicate Users - suggest preventing

by Dierk Polzin -
I think we do some kind of bulk import. I am not the administrator.
In reply to Dierk Polzin

Re: Duplicate Users - suggest preventing

by Luis de Vasconcelos -
Just wondering... why do you need that "cnt < 20" condition?

Isn't this enough?
HAVING cnt > 1 AS DUPS

In reply to Luis de Vasconcelos

Re: Duplicate Users - suggest preventing

by Dierk Polzin -
Because we have 21000 records with no id# and 22 with id number '000000'

Do you know what the base for the integer value in lastlogin is? some date in time plus this integer.
In reply to Dierk Polzin

Re: Duplicate Users - suggest preventing

by Luis de Vasconcelos -
Dates in Moodle are unix timestamps. And unix timestamps use 1970/01/01 00:00:000 as the base date. So the dates in Moodle are the number of seconds that have passed since that 1970 base date.

So the value in mdl_user.lastlogin is the integer representing the number of seconds that have passed since that 1970/01/01 date to the date/time that the user last logged into Moodle.

https://en.wikipedia.org/wiki/Unix_time
Average of ratings: Useful (1)