001
014
015 package com.liferay.portal.upgrade.v7_0_0;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.upgrade.util.UpgradePortletId;
020
021 import java.sql.PreparedStatement;
022 import java.sql.ResultSet;
023 import java.sql.SQLException;
024
025
028 @SuppressWarnings("deprecation")
029 public class UpgradeDocumentLibraryPortletId extends UpgradePortletId {
030
031 protected void deleteDuplicateResourceActions() throws SQLException {
032 try (PreparedStatement ps1 = connection.prepareStatement(
033 "select actionId from ResourceAction where name = '" +
034 _PORTLET_ID_DOCUMENT_LIBRARY + "'");
035 ResultSet rs = ps1.executeQuery()) {
036
037 while (rs.next()) {
038 try (PreparedStatement ps2 = connection.prepareStatement(
039 "delete from ResourceAction where name = ? and " +
040 "actionId = ?")) {
041
042 ps2.setString(1, _PORTLET_ID_DL_DISPLAY);
043 ps2.setString(2, rs.getString("actionId"));
044
045 ps2.execute();
046 }
047 }
048 }
049 }
050
051 protected void deleteDuplicateResourcePermissions() throws SQLException {
052 try (PreparedStatement ps1 = connection.prepareStatement(
053 "select companyId, scope, primKey from ResourcePermission " +
054 "where name = '" + _PORTLET_ID_DOCUMENT_LIBRARY + "'");
055 ResultSet rs = ps1.executeQuery()) {
056
057 while (rs.next()) {
058 try (PreparedStatement ps2 = connection.prepareStatement(
059 "delete from ResourcePermission where companyId = ? " +
060 "and name = ? and scope = ? and primKey = ?")) {
061
062 ps2.setLong(1, rs.getLong("companyId"));
063 ps2.setString(2, _PORTLET_ID_DL_DISPLAY);
064 ps2.setInt(3, rs.getInt("scope"));
065 ps2.setString(4, rs.getString("primKey"));
066
067 ps2.execute();
068 }
069 }
070 }
071 }
072
073 @Override
074 protected String[][] getRenamePortletIdsArray() {
075 return new String[][] {
076 new String[] {_PORTLET_ID_DL_DISPLAY, _PORTLET_ID_DOCUMENT_LIBRARY}
077 };
078 }
079
080 @Override
081 protected void updatePortlet(
082 String oldRootPortletId, String newRootPortletId)
083 throws Exception {
084
085 try {
086 runSQL(
087 "delete from Portlet where portletId = '" +
088 _PORTLET_ID_DL_DISPLAY + "'");
089
090 deleteDuplicateResourceActions();
091 deleteDuplicateResourcePermissions();
092 }
093 catch (Exception e) {
094 if (_log.isWarnEnabled()) {
095 _log.warn(e, e);
096 }
097 }
098
099 super.updatePortlet(oldRootPortletId, newRootPortletId);
100 }
101
102 private static final String _PORTLET_ID_DL_DISPLAY = "110";
103
104 private static final String _PORTLET_ID_DOCUMENT_LIBRARY = "20";
105
106 private static final Log _log = LogFactoryUtil.getLog(
107 UpgradeDocumentLibraryPortletId.class);
108
109 }