Skip to content

Instantly share code, notes, and snippets.

View datyger's full-sized avatar

Daniel Tyger datyger

View GitHub Profile
@datyger
datyger / lr62-delete-layouts-DQ.groovy
Last active May 4, 2018 15:16
Liferay 6.2 script for deleting layouts (pages), based on various columns and query logic. Thanks to Michael Bowerman for the help!
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery
import com.liferay.portal.kernel.dao.orm.DynamicQuery
import com.liferay.portal.kernel.dao.orm.Property
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil
import com.liferay.portal.kernel.exception.PortalException
import com.liferay.portal.kernel.exception.SystemException
import com.liferay.portal.model.Layout
import com.liferay.portal.service.LayoutLocalServiceUtil
import com.liferay.portal.service.persistence.LayoutActionableDynamicQuery
import com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil
@datyger
datyger / lr62-delete-old-docs-per-site.groovy
Last active February 20, 2020 10:24
Liferay 6.2 script to remove all old document versions except the latest version. This version can be tasked per-site and /or specific site's folder.
// Find and delete old versions of docs per site...
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import java.util.List;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.FileVersion;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
@datyger
datyger / lr62-delete-old-docs-all-docs.groovy
Last active February 20, 2020 10:23
Liferay 6.2 script to remove all old document versions except the latest version. This version cleans out all document versions.
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery
import com.liferay.portal.kernel.exception.PortalException
import com.liferay.portal.kernel.exception.SystemException
import com.liferay.portal.util.PropsValues
import com.liferay.portlet.documentlibrary.model.DLFileEntry
import com.liferay.portlet.documentlibrary.model.DLFileVersion
import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil
import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalServiceUtil
import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryActionableDynamicQuery
import com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionActionableDynamicQuery
@datyger
datyger / lr62-delete-specific-files.groovy
Last active February 20, 2020 10:23
In our case, there were 45 legacy / lost dlfileentries in our system with no corresponding dlfileversion record. Gather a list of the offending fileEntryIds and use this script to remove them. This script needs to be run before the mass document version cleanup can occur.
// Delete files that have no dlfileversion record...
// Use this query to find them...:
// select fileEntryId from dlfileentry where fileEntryId NOT IN
// (select dlfe.fileEntryId from dlfileentry dlfe, dlfileversion dlfv where dlfe.fileEntryId=dlfv.fileEntryId and dlfv.version=dlfe.version);
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import java.util.List;
import com.liferay.portal.kernel.repository.model.FileEntry;
@datyger
datyger / lr62-delete-web-content-versions.groovy
Created May 8, 2018 15:24
This runs through any / all web content resource objects and cycles through the historical versions of each, deleting any that are not the latest.
import com.liferay.portal.service.ServiceContext
import com.liferay.portlet.journal.service.JournalArticleServiceUtil
import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil
import java.util.List
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery
import com.liferay.portal.kernel.exception.PortalException
import com.liferay.portal.kernel.exception.SystemException
import com.liferay.portal.util.PropsValues
@datyger
datyger / lr62-delete-WC-Versions-wDQ.groovy
Last active June 10, 2022 19:58
Script to delete all old versions of web content besides the latest version.
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery
import com.liferay.portal.kernel.exception.PortalException
import com.liferay.portal.kernel.exception.SystemException
import com.liferay.portal.util.PropsValues
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil
import com.liferay.portal.kernel.dao.orm.DynamicQuery
import com.liferay.portal.kernel.dao.orm.Conjunction
import com.liferay.portlet.journal.service.persistence.JournalArticleResourceActionableDynamicQuery
import com.liferay.portlet.journal.service.JournalArticleServiceUtil