1
22
23 package com.liferay.portal.upgrade.v5_1_5;
24
25 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
26 import com.liferay.portal.kernel.util.LocaleUtil;
27 import com.liferay.portal.kernel.util.UnicodeProperties;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.upgrade.UpgradeProcess;
30
31 import java.sql.Connection;
32 import java.sql.PreparedStatement;
33 import java.sql.ResultSet;
34
35
40 public class UpgradeLayout extends UpgradeProcess {
41
42 protected void doUpgrade() throws Exception {
43 String languageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());
44
45 Connection con = null;
46 PreparedStatement ps = null;
47 ResultSet rs = null;
48
49 try {
50 con = DataAccess.getConnection();
51
52 ps = con.prepareStatement(
53 "select plid, typeSettings from Layout where typeSettings " +
54 "like '%meta-description=%'");
55
56 rs = ps.executeQuery();
57
58 while (rs.next()) {
59 long plid = rs.getLong("plid");
60 String typeSettings = rs.getString("typeSettings");
61
62 UnicodeProperties typeSettingsProperties =
63 new UnicodeProperties();
64
65 typeSettingsProperties.load(typeSettings);
66
67 String oldMetaDescription = typeSettingsProperties.getProperty(
68 "meta-description");
69 String newMetaDescription = typeSettingsProperties.getProperty(
70 "meta-description_" + languageId);
71
72 if (Validator.isNotNull(oldMetaDescription) &&
73 Validator.isNull(newMetaDescription)) {
74
75 typeSettingsProperties.setProperty(
76 "meta-description_" + languageId, oldMetaDescription);
77 }
78
79 typeSettingsProperties.remove("meta-description");
80
81 String oldMetaKeywords = typeSettingsProperties.getProperty(
82 "meta-keywords");
83 String newMetaKeywords = typeSettingsProperties.getProperty(
84 "meta-keywords_" + languageId);
85
86 if (Validator.isNotNull(oldMetaKeywords) &&
87 Validator.isNull(newMetaKeywords)) {
88
89 typeSettingsProperties.setProperty(
90 "meta-keywords_" + languageId, oldMetaKeywords);
91 }
92
93 typeSettingsProperties.remove("meta-keywords");
94
95 String oldMetaRobots = typeSettingsProperties.getProperty(
96 "meta-robots");
97 String newMetaRobots = typeSettingsProperties.getProperty(
98 "meta-robots_" + languageId);
99
100 if (Validator.isNotNull(oldMetaRobots) &&
101 Validator.isNull(newMetaRobots)) {
102
103 typeSettingsProperties.setProperty(
104 "meta-robots_" + languageId, oldMetaRobots);
105 }
106
107 typeSettingsProperties.remove("meta-robots");
108
109 updateTypeSettings(plid, typeSettingsProperties.toString());
110 }
111 }
112 finally {
113 DataAccess.cleanUp(con, ps, rs);
114 }
115 }
116
117 protected void updateTypeSettings(long plid, String typeSettings)
118 throws Exception {
119
120 Connection con = null;
121 PreparedStatement ps = null;
122 ResultSet rs = null;
123
124 try {
125 con = DataAccess.getConnection();
126
127 ps = con.prepareStatement(
128 "update Layout set typeSettings = ? where plid = ?");
129
130 ps.setString(1, typeSettings);
131 ps.setLong(2, plid);
132
133 ps.executeUpdate();
134 }
135 finally {
136 DataAccess.cleanUp(con, ps, rs);
137 }
138 }
139
140 }