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