Last active
October 18, 2023 18:43
-
-
Save prince-neres/680f2b9676c8e49925a101060473c9d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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