Skip to content

Instantly share code, notes, and snippets.

@prince-neres
Last active October 18, 2023 18:43
Show Gist options
  • Save prince-neres/680f2b9676c8e49925a101060473c9d0 to your computer and use it in GitHub Desktop.
Save prince-neres/680f2b9676c8e49925a101060473c9d0 to your computer and use it in GitHub Desktop.
import com.liferay.portal.kernel.service.UserLocalServiceUtil
import com.liferay.portal.kernel.util.PortalUtil
def deleteUsersByEmails(emails) {
def company = PortalUtil.getCompany(actionRequest)
def companyId = company.getCompanyId()
for (email in emails.split('\n')) {
try {
def user = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, email.trim())
if (user) {
UserLocalServiceUtil.deleteUser(user)
println "Usuário ${email.trim()} deletado com sucesso"
} else {
println "Não foi possível encontrar usuário ${email.trim()}"
}
} catch (Exception e) {
e.printStackTrace()
}
}
}
def emails = """
[email protected]
[email protected]
[email protected]
"""
deleteUsersByEmails(emails)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment