001    /**
002     * Copyright (c) 2000-2013 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.upgrade.BaseUpgradePortletPreferences;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.verify.VerifyUUID;
020    import com.liferay.portlet.PortletPreferencesFactoryUtil;
021    
022    import javax.portlet.PortletPreferences;
023    
024    /**
025     * @author Julio Camarero
026     */
027    public class UpgradeScopes extends BaseUpgradePortletPreferences {
028    
029            @Override
030            protected void doUpgrade() throws Exception {
031                    super.doUpgrade();
032    
033                    VerifyUUID.verifyModel("Layout", "plid");
034            }
035    
036            @Override
037            protected String getUpdatePortletPreferencesWhereClause() {
038                    return "preferences like '%lfr-scope-layout-id%'";
039            }
040    
041            @Override
042            protected String upgradePreferences(
043                            long companyId, long ownerId, int ownerType, long plid,
044                            String portletId, String xml)
045                    throws Exception {
046    
047                    PortletPreferences portletPreferences =
048                            PortletPreferencesFactoryUtil.fromXML(
049                                    companyId, ownerId, ownerType, plid, portletId, xml);
050    
051                    long linkToLayoutId = GetterUtil.getLong(
052                            portletPreferences.getValue("lfr-scope-layout-id", null));
053    
054                    if (linkToLayoutId > 0) {
055                            String uuid = getLayoutUuid(plid, linkToLayoutId);
056    
057                            if (uuid != null) {
058                                    portletPreferences.setValue("lfr-scope-layout-uuid", uuid);
059                            }
060    
061                            portletPreferences.reset("lfr-scope-layout-id");
062                    }
063    
064                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
065            }
066    
067    }