1
22
23 package com.liferay.portal.upgrade.v5_1_0;
24
25 import com.liferay.portal.NoSuchLayoutException;
26 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.model.Layout;
30 import com.liferay.portal.service.LayoutLocalServiceUtil;
31 import com.liferay.portal.upgrade.UpgradeException;
32 import com.liferay.portal.upgrade.UpgradeProcess;
33 import com.liferay.portal.upgrade.v4_4_0.UpgradeLayout;
34 import com.liferay.portlet.PortletPreferencesImpl;
35 import com.liferay.portlet.PortletPreferencesSerializer;
36
37 import java.sql.Connection;
38 import java.sql.PreparedStatement;
39 import java.sql.ResultSet;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44
50 public class UpgradeSitemap extends UpgradeProcess {
51
52 public void upgrade() throws UpgradeException {
53 _log.info("Upgrading");
54
55 try {
56 doUpgrade();
57 }
58 catch (Exception e) {
59 throw new UpgradeException(e);
60 }
61 }
62
63 protected void doUpgrade() throws Exception {
64 Connection con = null;
65 PreparedStatement ps = null;
66 ResultSet rs = null;
67
68 try {
69 con = DataAccess.getConnection();
70
71 ps = con.prepareStatement(
72 "select ownerId, ownerType, plid, portletId, preferences " +
73 "from PortletPreferences where portletId like '85_%'");
74
75 rs = ps.executeQuery();
76
77 while (rs.next()) {
78 long ownerId = rs.getLong("ownerId");
79 int ownerType = rs.getInt("ownerType");
80 long plid = rs.getLong("plid");
81 String portletId = rs.getString("portletId");
82 String preferences = rs.getString("preferences");
83
84 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
85
86 String newPreferences = upgradePreferences(
87 layout.getCompanyId(), ownerId, ownerType, plid, portletId,
88 preferences);
89
90 ps = con.prepareStatement(
91 "update PortletPreferences set preferences = ? where " +
92 "plid = " + plid + " and portletId = ?");
93
94 ps.setString(1, newPreferences);
95 ps.setString(2, portletId);
96
97 ps.executeUpdate();
98
99 ps.close();
100 }
101 }
102 finally {
103 DataAccess.cleanUp(con, ps, rs);
104 }
105 }
106
107 protected String upgradePreferences(
108 long companyId, long ownerId, int ownerType, long plid,
109 String portletId, String preferences)
110 throws Exception {
111
112 PortletPreferencesImpl prefs = PortletPreferencesSerializer.fromXML(
113 companyId, ownerId, ownerType, plid, portletId, preferences);
114
115 long rootPlid = GetterUtil.getLong(
116 prefs.getValue("root-plid", StringPool.BLANK));
117
118 if (rootPlid > 0) {
119 try {
120 Layout layout = LayoutLocalServiceUtil.getLayout(rootPlid);
121
122 prefs.setValue(
123 "root-layout-id", String.valueOf(layout.getLayoutId()));
124 }
125 catch (NoSuchLayoutException nsle) {
126 }
127 }
128
129 prefs.setValue("root-plid", null);
130
131 return PortletPreferencesSerializer.toXML(prefs);
132 }
133
134 private static Log _log = LogFactory.getLog(UpgradeLayout.class);
135
136 }