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