mass suspend accounts

mass suspend accounts

by C R -
Number of replies: 2
Hi,
Is there a way to mass suspend accounts? I can only see a delete option under bulk ?
Basically I want to suspend accounts that haven't logged in for over a year.
Thanks


Average of ratings: -
In reply to C R

Re: mass suspend accounts

by Colin Fraser -
Picture of Documentation writers Picture of Testers

You can use a flat file, the same as the flat file that you can use to enroll new users. You may have a list of users you want to target already generated and downloaded as a flat file in a report format. Open it in your text editor, or Excel or similar, anything that can handle a csv file, and add "suspended" to the field list, then add the value of 1 on each row. Upload the flat file and that should solve your problem. Make sure you have set the parameters of your flat file correctly when you upload it, so read the linked docs, and anything else you feel is relevant. 

This is not the only way, though. If you have access to the database, create an SQL UPDATE statement, identify the users you want to change with some SQL Code that looks like: 

begin

  for i in (select  mdl_user.id from moodledbname)

  loop

    if mdl_user.lastlogin<1408952937 then

      update moodledbname

      set suspended=1

      where i=mdl_user.id;

    end if;

  end loop;

end;   


DO NOT TAKE MY WORD FOR THIS, it has been far too long for me since doing this sort of thing so my recall of syntax is likely to be wrong. You will have to rewrite this to better suit your requirements, but I think this will be something around the mark. You will have to determine the cutoff date and work it out timestamped. If you look at this article from Stackoverflow, that might help. 

In reply to C R

Re: mass suspend accounts

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers

It should be possible to mass suspend at the site level via a CSV file : 

From the Docs

Tip: A similar field is available for suspended. This enables a user account to be temporarily disabled rather than completely removed. For example, the following file will suspend the user
username,firstname,lastname,email,suspended
marwan.maheria,Marwan,Maheria,marwan@gmail.com,1


I end up suspending users manually (by editing their profiles) so I also switch their enrollment type to "No Login". Then I place the text (Inactive) next to their last names so all teachers can quickly see who is inactive and then make them inactive in their courses as well.