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