001
014
015 package com.liferay.portal.upgrade.v6_1_0;
016
017 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018 import com.liferay.portal.kernel.util.LoggingTimer;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.upgrade.v6_1_0.util.JournalArticleTable;
021 import com.liferay.portal.upgrade.v6_1_0.util.JournalStructureTable;
022 import com.liferay.portal.upgrade.v6_1_0.util.JournalTemplateTable;
023
024 import java.sql.PreparedStatement;
025 import java.sql.ResultSet;
026
027
031 public class UpgradeJournal extends UpgradeProcess {
032
033 @Override
034 protected void doUpgrade() throws Exception {
035 alter(
036 JournalArticleTable.class,
037 new AlterColumnType("title", "STRING null"));
038
039 alter(
040 JournalStructureTable.class,
041 new AlterColumnType("name", "STRING null"),
042 new AlterColumnType("description", "STRING null"));
043
044 alter(
045 JournalTemplateTable.class,
046 new AlterColumnType("name", "STRING null"),
047 new AlterColumnType("description", "STRING null"));
048
049 updateStructureXsd();
050 }
051
052 protected void updateStructureXsd() throws Exception {
053 try (LoggingTimer loggingTimer = new LoggingTimer()) {
054 runSQL(
055 "update JournalStructure set xsd = replace(xsd, " +
056 "'image_gallery', 'document_library') where xsd like " +
057 "'%image_gallery%'");
058 }
059 catch (Exception e) {
060 try (PreparedStatement ps = connection.prepareStatement(
061 "select id_, xsd from JournalStructure where xsd like " +
062 "'%image_gallery%'");
063 ResultSet rs = ps.executeQuery()) {
064
065 while (rs.next()) {
066 long id = rs.getLong("id_");
067 String xsd = rs.getString("xsd");
068
069 xsd = StringUtil.replace(
070 xsd, "image_gallery", "document_library");
071
072 updateStructureXsd(id, xsd);
073 }
074 }
075 }
076 }
077
078 protected void updateStructureXsd(long id, String xsd) throws Exception {
079 try (PreparedStatement ps = connection.prepareStatement(
080 "update JournalStructure set xsd = ? where id_ = ?")) {
081
082 ps.setString(1, xsd);
083 ps.setLong(2, id);
084
085 ps.executeUpdate();
086 }
087 }
088
089 }