Hi all !
I'm creating an add-on to add users from a csv. But I'd like to check if the user I want to add already exists to avoid updating its password.
Thank you !
if you know the username you can do something like that:
if ($user = $modx->getObject('modUser', array('username'=>$username))){
//do something with existing user
}
else{
//add new user
$user = $modx->newObject('modUser');
}
-
☆ A M B ☆
- 24,524 Posts
Username field is unique so it will throw an exception if you try to insert a user that already exists. You should be able to use a try/catch exception handler to skip to the next record.