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.util.GetterUtil;
27 import com.liferay.portal.kernel.util.UnicodeProperties;
28 import com.liferay.portal.model.Layout;
29 import com.liferay.portal.service.LayoutLocalServiceUtil;
30 import com.liferay.portal.upgrade.UpgradeProcess;
31
32 import java.sql.Connection;
33 import java.sql.PreparedStatement;
34 import java.sql.ResultSet;
35
36
41 public class UpgradeLayout extends UpgradeProcess {
42
43 protected void doUpgrade() throws Exception {
44 Connection con = null;
45 PreparedStatement ps = null;
46 ResultSet rs = null;
47
48 try {
49 con = DataAccess.getConnection();
50
51 ps = con.prepareStatement(
52 "select plid, typeSettings from Layout where type_ = " +
53 "'link_to_layout'");
54
55 rs = ps.executeQuery();
56
57 while (rs.next()) {
58 long plid = rs.getLong("plid");
59 String typeSettings = rs.getString("typeSettings");
60
61 String newTypeSettings = upgradeTypeSettings(typeSettings);
62
63 ps = con.prepareStatement(
64 "update Layout set typeSettings = ? where plid = " +
65 plid);
66
67 ps.setString(1, newTypeSettings);
68
69 ps.executeUpdate();
70
71 ps.close();
72 }
73 }
74 finally {
75 DataAccess.cleanUp(con, ps, rs);
76 }
77 }
78
79 protected String upgradeTypeSettings(String typeSettings) throws Exception {
80 UnicodeProperties props = new UnicodeProperties(true);
81
82 props.load(typeSettings);
83
84 long linkToPlid = GetterUtil.getLong(props.getProperty("linkToPlid"));
85
86 if (linkToPlid > 0) {
87 Layout layout = LayoutLocalServiceUtil.getLayout(linkToPlid);
88
89 props.remove("linkToPlid");
90 props.put("groupId", String.valueOf(layout.getGroupId()));
91 props.put(
92 "privateLayout", String.valueOf(layout.isPrivateLayout()));
93 props.put("linkToLayoutId", String.valueOf(layout.getLayoutId()));
94 }
95
96 return props.toString();
97 }
98
99 }