use of com.liferay.portal.kernel.model.PortletPreferences in project liferay-db-setup-core by ableneo.
the class SetupPages method removeAllPortlets.
private static void removeAllPortlets(final long runasUser, final LayoutTypePortlet layoutTypePortlet, final Layout layout) {
List<Portlet> portlets = null;
try {
portlets = layoutTypePortlet.getAllPortlets();
} catch (SystemException e1) {
LOG.error(e1);
}
if (portlets != null) {
for (Portlet portlet : portlets) {
String portletId = portlet.getPortletId();
try {
if (layoutTypePortlet.hasPortletId(portletId)) {
LOG.debug(String.format("Removing wrappedPortlet %1$s", portletId));
layoutTypePortlet.removePortletId(runasUser, portletId);
String rootPortletId = PortletIdCodec.decodePortletName(portletId);
LOG.debug(String.format("Root portletId: %1$s", rootPortletId));
ResourceLocalServiceUtil.deleteResource(layout.getCompanyId(), rootPortletId, ResourceConstants.SCOPE_INDIVIDUAL, PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId));
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
List<PortletPreferences> list = PortletPreferencesLocalServiceUtil.getPortletPreferences(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(), portletId);
for (PortletPreferences p : list) {
PortletPreferencesLocalServiceUtil.deletePortletPreferences(p);
}
}
} catch (PortalException | SystemException e) {
LOG.error(e);
}
}
}
}
Aggregations