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