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_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                    updateEntries();
037                    updatePortletPreferences();
038            }
039    
040            @Override
041            protected String[] getPortletIds() {
042                    return new String[] {"33"};
043            }
044    
045            protected void updateEntries() throws Exception {
046                    try {
047                            runSQL("alter_column_type BlogsEntry description STRING null");
048                    }
049                    catch (Exception e) {
050                            UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
051                                    BlogsEntryTable.TABLE_NAME, BlogsEntryTable.TABLE_COLUMNS);
052    
053                            upgradeTable.setCreateSQL(BlogsEntryTable.TABLE_SQL_CREATE);
054                            upgradeTable.setIndexesSQL(BlogsEntryTable.TABLE_SQL_ADD_INDEXES);
055    
056                            upgradeTable.updateTable();
057                    }
058            }
059    
060            @Override
061            protected String upgradePreferences(
062                            long companyId, long ownerId, int ownerType, long plid,
063                            String portletId, String xml)
064                    throws Exception {
065    
066                    PortletPreferences portletPreferences =
067                            PortletPreferencesFactoryUtil.fromXML(
068                                    companyId, ownerId, ownerType, plid, portletId, xml);
069    
070                    String rssFormat = GetterUtil.getString(
071                            portletPreferences.getValue("rssFormat", null));
072    
073                    if (Validator.isNotNull(rssFormat)) {
074                            String rssFormatType = RSSUtil.getFormatType(rssFormat);
075                            double rssFormatVersion = RSSUtil.getFormatVersion(rssFormat);
076    
077                            String rssFeedType = RSSUtil.getFeedType(
078                                    rssFormatType, rssFormatVersion);
079    
080                            portletPreferences.setValue("rssFeedType", rssFeedType);
081                    }
082    
083                    portletPreferences.reset("rssFormat");
084    
085                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
086            }
087    
088    }