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_0_12;
016    
017    import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portlet.PortletPreferencesFactoryUtil;
020    
021    import javax.portlet.PortletPreferences;
022    
023    /**
024     * @author Brett Swaim
025     */
026    public class UpgradeScopes extends BaseUpgradePortletPreferences {
027    
028            @Override
029            protected void doUpgrade() throws Exception {
030                    updatePortletPreferences();
031            }
032    
033            @Override
034            protected String getUpdatePortletPreferencesWhereClause() {
035                    return "preferences like '%lfr-scope-layout-uuid%'";
036            }
037    
038            @Override
039            protected String upgradePreferences(
040                            long companyId, long ownerId, int ownerType, long plid,
041                            String portletId, String xml)
042                    throws Exception {
043    
044                    PortletPreferences portletPreferences =
045                            PortletPreferencesFactoryUtil.fromXML(
046                                    companyId, ownerId, ownerType, plid, portletId, xml);
047    
048                    boolean hasScopeType = GetterUtil.getBoolean(
049                            portletPreferences.getValue("lfr-scope-type", "false"));
050    
051                    if (!hasScopeType) {
052                            portletPreferences.setValue("lfr-scope-type", "layout");
053                    }
054    
055                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
056            }
057    
058    }