001
014
015 package com.liferay.portal.upgrade.v5_2_3;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.util.LocaleUtil;
020 import com.liferay.portal.kernel.util.UnicodeProperties;
021 import com.liferay.portal.kernel.util.Validator;
022
023 import java.sql.Connection;
024 import java.sql.PreparedStatement;
025 import java.sql.ResultSet;
026
027
030 public class UpgradeLayout extends UpgradeProcess {
031
032 protected void doUpgrade() throws Exception {
033 String languageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());
034
035 Connection con = null;
036 PreparedStatement ps = null;
037 ResultSet rs = null;
038
039 try {
040 con = DataAccess.getConnection();
041
042 ps = con.prepareStatement(
043 "select plid, typeSettings from Layout where typeSettings " +
044 "like '%meta-description=%'");
045
046 rs = ps.executeQuery();
047
048 while (rs.next()) {
049 long plid = rs.getLong("plid");
050 String typeSettings = rs.getString("typeSettings");
051
052 UnicodeProperties typeSettingsProperties =
053 new UnicodeProperties(true);
054
055 typeSettingsProperties.load(typeSettings);
056
057 String oldMetaDescription = typeSettingsProperties.getProperty(
058 "meta-description");
059 String newMetaDescription = typeSettingsProperties.getProperty(
060 "meta-description_" + languageId);
061
062 if (Validator.isNotNull(oldMetaDescription) &&
063 Validator.isNull(newMetaDescription)) {
064
065 typeSettingsProperties.setProperty(
066 "meta-description_" + languageId, oldMetaDescription);
067 }
068
069 typeSettingsProperties.remove("meta-description");
070
071 String oldMetaKeywords = typeSettingsProperties.getProperty(
072 "meta-keywords");
073 String newMetaKeywords = typeSettingsProperties.getProperty(
074 "meta-keywords_" + languageId);
075
076 if (Validator.isNotNull(oldMetaKeywords) &&
077 Validator.isNull(newMetaKeywords)) {
078
079 typeSettingsProperties.setProperty(
080 "meta-keywords_" + languageId, oldMetaKeywords);
081 }
082
083 typeSettingsProperties.remove("meta-keywords");
084
085 String oldMetaRobots = typeSettingsProperties.getProperty(
086 "meta-robots");
087 String newMetaRobots = typeSettingsProperties.getProperty(
088 "meta-robots_" + languageId);
089
090 if (Validator.isNotNull(oldMetaRobots) &&
091 Validator.isNull(newMetaRobots)) {
092
093 typeSettingsProperties.setProperty(
094 "meta-robots_" + languageId, oldMetaRobots);
095 }
096
097 typeSettingsProperties.remove("meta-robots");
098
099 updateTypeSettings(plid, typeSettingsProperties.toString());
100 }
101 }
102 finally {
103 DataAccess.cleanUp(con, ps, rs);
104 }
105 }
106
107 protected void updateTypeSettings(long plid, String typeSettings)
108 throws Exception {
109
110 Connection con = null;
111 PreparedStatement ps = null;
112
113 try {
114 con = DataAccess.getConnection();
115
116 ps = con.prepareStatement(
117 "update Layout set typeSettings = ? where plid = " + plid);
118
119 ps.setString(1, typeSettings);
120
121 ps.executeUpdate();
122 }
123 finally {
124 DataAccess.cleanUp(con, ps);
125 }
126 }
127
128 }