001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.upgrade.util.UpgradeTable;
019    import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
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    /**
025     * @author Juan Fernández
026     * @author Sergio González
027     */
028    public class UpgradeJournal extends UpgradeProcess {
029    
030            @Override
031            protected void doUpgrade() throws Exception {
032                    try {
033                            runSQL("alter_column_type JournalArticle title STRING null");
034                    }
035                    catch (Exception e) {
036                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
037                                    JournalArticleTable.TABLE_NAME,
038                                    JournalArticleTable.TABLE_COLUMNS);
039    
040                            upgradeTable.setCreateSQL(JournalArticleTable.TABLE_SQL_CREATE);
041                            upgradeTable.setIndexesSQL(
042                                    JournalArticleTable.TABLE_SQL_ADD_INDEXES);
043    
044                            upgradeTable.updateTable();
045                    }
046    
047                    try {
048                            runSQL("alter_column_type JournalStructure name STRING null");
049                            runSQL(
050                                    "alter_column_type JournalStructure description STRING null");
051                    }
052                    catch (Exception e) {
053                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
054                                    JournalStructureTable.TABLE_NAME,
055                                    JournalStructureTable.TABLE_COLUMNS);
056    
057                            upgradeTable.setCreateSQL(JournalStructureTable.TABLE_SQL_CREATE);
058                            upgradeTable.setIndexesSQL(
059                                    JournalStructureTable.TABLE_SQL_ADD_INDEXES);
060    
061                            upgradeTable.updateTable();
062                    }
063    
064                    try {
065                            runSQL("alter_column_type JournalTemplate name STRING null");
066                            runSQL("alter_column_type JournalTemplate description STRING null");
067                    }
068                    catch (Exception e) {
069                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
070                                    JournalTemplateTable.TABLE_NAME,
071                                    JournalTemplateTable.TABLE_COLUMNS);
072    
073                            upgradeTable.setCreateSQL(JournalTemplateTable.TABLE_SQL_CREATE);
074                            upgradeTable.setIndexesSQL(
075                                    JournalTemplateTable.TABLE_SQL_ADD_INDEXES);
076    
077                            upgradeTable.updateTable();
078                    }
079    
080                    updateStructureXsd();
081            }
082    
083            protected void updateStructureXsd() throws Exception {
084                    runSQL(
085                            "update JournalStructure set xsd = replace(CAST_TEXT(xsd), " +
086                                    "'image_gallery', 'document_library') where xsd like " +
087                                            "'%image_gallery%'");
088            }
089    
090    }