001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.upgrade.v6_0_3;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.upgrade.BaseUpgradePortletPreferences;
019    import com.liferay.portlet.PortletPreferencesImpl;
020    import com.liferay.portlet.PortletPreferencesSerializer;
021    
022    /**
023     * @author Julio Camarero
024     */
025    public class UpgradeLookAndFeel extends BaseUpgradePortletPreferences {
026    
027            protected String getUpdatePortletPreferencesWhereClause() {
028                    return "preferences like '%portlet-setup-link-to-%'";
029            }
030    
031            protected String upgradePreferences(
032                            long companyId, long ownerId, int ownerType, long plid,
033                            String portletId, String xml)
034                    throws Exception {
035    
036                    PortletPreferencesImpl preferences =
037                            PortletPreferencesSerializer.fromXML(
038                                    companyId, ownerId, ownerType, plid, portletId, xml);
039    
040                    long linkToLayoutId = GetterUtil.getLong(
041                            preferences.getValue("portlet-setup-link-to-layout-id", null));
042    
043                    if (linkToLayoutId <= 0) {
044                            linkToLayoutId = GetterUtil.getLong(
045                                    preferences.getValue("portlet-setup-link-to-plid", null));
046                    }
047    
048                    if (linkToLayoutId > 0) {
049                            String uuid = getLayoutUuid(plid, linkToLayoutId);
050    
051                            if (uuid != null) {
052                                    preferences.setValue("portlet-setup-link-to-layout-uuid", uuid);
053                            }
054    
055                            preferences.reset("portlet-setup-link-to-layout-id");
056                            preferences.reset("portlet-setup-link-to-plid");
057                    }
058    
059                    return PortletPreferencesSerializer.toXML(preferences);
060            }
061    
062    }