001    /**
002     * Copyright (c) 2000-2013 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_2_0;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
019    import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.upgrade.v6_2_0.util.BlogsEntryTable;
023    import com.liferay.portlet.PortletPreferencesFactoryUtil;
024    import com.liferay.util.RSSUtil;
025    
026    import javax.portlet.PortletPreferences;
027    
028    /**
029     * @author Sergio Gonz??lez
030     * @author Eduardo Garcia
031     */
032    public class UpgradeBlogs extends BaseUpgradePortletPreferences {
033    
034            @Override
035            protected void doUpgrade() throws Exception {
036                    super.doUpgrade();
037    
038                    updateEntries();
039            }
040    
041            @Override
042            protected String[] getPortletIds() {
043                    return new String[] {"33"};
044            }
045    
046            protected void updateEntries() throws Exception {
047                    try {
048                            runSQL("alter_column_type BlogsEntry description STRING null");
049                    }
050                    catch (Exception e) {
051                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
052                                    BlogsEntryTable.TABLE_NAME, BlogsEntryTable.TABLE_COLUMNS);
053    
054                            upgradeTable.setCreateSQL(BlogsEntryTable.TABLE_SQL_CREATE);
055                            upgradeTable.setIndexesSQL(BlogsEntryTable.TABLE_SQL_ADD_INDEXES);
056    
057                            upgradeTable.updateTable();
058                    }
059            }
060    
061            protected void upgradeDisplayStyle(PortletPreferences portletPreferences)
062                    throws Exception {
063    
064                    String pageDisplayStyle = GetterUtil.getString(
065                            portletPreferences.getValue("pageDisplayStyle", null));
066    
067                    if (Validator.isNotNull(pageDisplayStyle)) {
068                            portletPreferences.setValue("displayStyle", pageDisplayStyle);
069                    }
070    
071                    portletPreferences.reset("pageDisplayStyle");
072            }
073    
074            @Override
075            protected String upgradePreferences(
076                            long companyId, long ownerId, int ownerType, long plid,
077                            String portletId, String xml)
078                    throws Exception {
079    
080                    PortletPreferences portletPreferences =
081                            PortletPreferencesFactoryUtil.fromXML(
082                                    companyId, ownerId, ownerType, plid, portletId, xml);
083    
084                    upgradeDisplayStyle(portletPreferences);
085                    upgradeRss(portletPreferences);
086    
087                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
088            }
089    
090            protected void upgradeRss(PortletPreferences portletPreferences)
091                    throws Exception {
092    
093                    String rssFormat = GetterUtil.getString(
094                            portletPreferences.getValue("rssFormat", null));
095    
096                    if (Validator.isNotNull(rssFormat)) {
097                            String rssFormatType = RSSUtil.getFormatType(rssFormat);
098                            double rssFormatVersion = RSSUtil.getFormatVersion(rssFormat);
099    
100                            String rssFeedType = RSSUtil.getFeedType(
101                                    rssFormatType, rssFormatVersion);
102    
103                            portletPreferences.setValue("rssFeedType", rssFeedType);
104                    }
105    
106                    portletPreferences.reset("rssFormat");
107            }
108    
109    }