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_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    
032                    // UUID
033    
034                    VerifyUUID.verifyModel("Layout", "plid");
035    
036                    // PortletPreferences
037    
038                    updatePortletPreferences();
039            }
040    
041            @Override
042            protected String getUpdatePortletPreferencesWhereClause() {
043                    return "preferences like '%lfr-scope-layout-id%'";
044            }
045    
046            @Override
047            protected String upgradePreferences(
048                            long companyId, long ownerId, int ownerType, long plid,
049                            String portletId, String xml)
050                    throws Exception {
051    
052                    PortletPreferences portletPreferences =
053                            PortletPreferencesFactoryUtil.fromXML(
054                                    companyId, ownerId, ownerType, plid, portletId, xml);
055    
056                    long linkToLayoutId = GetterUtil.getLong(
057                            portletPreferences.getValue("lfr-scope-layout-id", null));
058    
059                    if (linkToLayoutId > 0) {
060                            String uuid = getLayoutUuid(plid, linkToLayoutId);
061    
062                            if (uuid != null) {
063                                    portletPreferences.setValue("lfr-scope-layout-uuid", uuid);
064                            }
065    
066                            portletPreferences.reset("lfr-scope-layout-id");
067                    }
068    
069                    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
070            }
071    
072    }