1
22
23 package com.liferay.portal.upgrade.v4_4_0;
24
25 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
26 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.UnicodeProperties;
29
30 import java.sql.Connection;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33
34
39 public class UpgradeLayout extends UpgradeProcess {
40
41 protected void doUpgrade() throws Exception {
42 Connection con = null;
43 PreparedStatement ps = null;
44 ResultSet rs = null;
45
46 try {
47 con = DataAccess.getConnection();
48
49 ps = con.prepareStatement(
50 "select plid, typeSettings from Layout where type_ = " +
51 "'link_to_layout'");
52
53 rs = ps.executeQuery();
54
55 while (rs.next()) {
56 long plid = rs.getLong("plid");
57 String typeSettings = rs.getString("typeSettings");
58
59 UnicodeProperties typeSettingsProperties =
60 new UnicodeProperties(true);
61
62 typeSettingsProperties.load(typeSettings);
63
64 long linkToPlid = GetterUtil.getLong(
65 typeSettingsProperties.getProperty("linkToPlid"));
66
67 if (linkToPlid > 0) {
68 Object[] layout = getLayout(linkToPlid);
69
70 if (layout != null) {
71 long groupId = (Long)layout[0];
72 boolean privateLayout = (Boolean)layout[1];
73 long layoutId = (Long)layout[2];
74
75 typeSettingsProperties.remove("linkToPlid");
76 typeSettingsProperties.put(
77 "groupId", String.valueOf(groupId));
78 typeSettingsProperties.put(
79 "privateLayout", String.valueOf(privateLayout));
80 typeSettingsProperties.put(
81 "linkToLayoutId", String.valueOf(layoutId));
82 }
83 }
84
85 updateTypeSettings(plid, typeSettingsProperties.toString());
86 }
87 }
88 finally {
89 DataAccess.cleanUp(con, ps, rs);
90 }
91 }
92
93 protected Object[] getLayout(long plid) throws Exception {
94 Object[] layout = null;
95
96 Connection con = null;
97 PreparedStatement ps = null;
98 ResultSet rs = null;
99
100 try {
101 con = DataAccess.getConnection();
102
103 ps = con.prepareStatement(_GET_LAYOUT);
104
105 ps.setLong(1, plid);
106
107 rs = ps.executeQuery();
108
109 while (rs.next()) {
110 long groupId = rs.getLong("groupId");
111 boolean privateLayout = rs.getBoolean("privateLayout");
112 long layoutId = rs.getLong("layoutId");
113
114 layout = new Object[] {groupId, privateLayout, layoutId};
115 }
116 }
117 finally {
118 DataAccess.cleanUp(con, ps, rs);
119 }
120
121 return layout;
122 }
123
124 protected void updateTypeSettings(long plid, String typeSettings)
125 throws Exception {
126
127 Connection con = null;
128 PreparedStatement ps = null;
129
130 try {
131 con = DataAccess.getConnection();
132
133 ps = con.prepareStatement(
134 "update Layout set typeSettings = ? where plid = " + plid);
135
136 ps.setString(1, typeSettings);
137
138 ps.executeUpdate();
139 }
140 finally {
141 DataAccess.cleanUp(con, ps);
142 }
143 }
144
145 private static final String _GET_LAYOUT =
146 "select * from Layout where plid = ?";
147
148 }