1
19
20 package com.liferay.portal.upgrade.v5_2_4;
21
22 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
23 import com.liferay.portal.kernel.log.Log;
24 import com.liferay.portal.kernel.log.LogFactoryUtil;
25 import com.liferay.portal.model.Group;
26 import com.liferay.portal.model.Layout;
27 import com.liferay.portal.service.GroupLocalServiceUtil;
28 import com.liferay.portal.service.LayoutLocalServiceUtil;
29 import com.liferay.portal.upgrade.UpgradeException;
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
42 public class UpgradeSocial extends UpgradeProcess {
43
44 public void upgrade() throws UpgradeException {
45 _log.info("Upgrading");
46
47 try {
48 doUpgrade();
49 }
50 catch (Exception e) {
51 throw new UpgradeException(e);
52 }
53 }
54
55 protected void doUpgrade() throws Exception {
56 Connection con = null;
57 PreparedStatement ps = null;
58 ResultSet rs = null;
59
60 try {
61 con = DataAccess.getConnection();
62
63 ps = con.prepareStatement(
64 "select distinct(groupId) from SocialActivity");
65
66 rs = ps.executeQuery();
67
68 while (rs.next()) {
69 long groupId = rs.getLong("groupId");
70
71 try {
72 updateGroupId(groupId);
73 }
74 catch (Exception e) {
75 if (_log.isWarnEnabled()) {
76 _log.warn(e);
77 }
78 }
79 }
80 }
81 finally {
82 DataAccess.cleanUp(con, ps);
83 }
84 }
85
86 protected void updateGroupId(long groupId) throws Exception {
87 Group group = GroupLocalServiceUtil.getGroup(groupId);
88
89 if (group.isLayout()) {
90 Layout layout = LayoutLocalServiceUtil.getLayout(
91 group.getClassPK());
92
93 long layoutGroupId = layout.getGroupId();
94
95 runSQL(
96 "update SocialActivity set groupId = " + layoutGroupId +
97 " where groupId = " + groupId);
98 }
99 }
100
101 private static Log _log = LogFactoryUtil.getLog(UpgradeSocial.class);
102
103 }