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