Last active
December 17, 2015 06:28
-
-
Save slemarchand/5565262 to your computer and use it in GitHub Desktop.
This file contains 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 java.util.Calendar | |
import com.liferay.portal.service.* | |
import com.liferay.portal.model.* | |
import com.liferay.portal.kernel.dao.orm.* | |
import static com.liferay.portal.kernel.workflow.WorkflowConstants.* | |
// | |
// Deactivate users never logged and created since more than 2 years | |
// | |
previewMode = true // Update this flag to false to really make changes | |
Calendar twoYearsAgo = Calendar.getInstance() | |
twoYearsAgo.setTime(new Date()) | |
twoYearsAgo.add(Calendar.YEAR, -2) | |
DynamicQuery query = DynamicQueryFactoryUtil.forClass(User.class) | |
.add(PropertyFactoryUtil.forName("lastLoginDate").isNull()) | |
.add(PropertyFactoryUtil.forName("createDate").lt(twoYearsAgo.getTime())) | |
users = UserLocalServiceUtil.dynamicQuery(query) | |
users.each { u -> | |
if(!u.isDefaultUser() && u.getStatus() != STATUS_INACTIVE) { | |
out.println(u.getEmailAddress()) | |
if(!previewMode) { | |
UserLocalServiceUtil.updateStatus(u.getUserId(), STATUS_INACTIVE) | |
} | |
} | |
} | |
if(previewMode) { | |
out.println('Preview mode is on: switch off the flag and execute ' | |
+ 'again this script to make changes to the database') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment