001    /**
002     * Copyright (c) 2000-present 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_1_1;
016    
017    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.util.LoggingTimer;
019    import com.liferay.portal.kernel.util.StringBundler;
020    
021    import java.sql.PreparedStatement;
022    import java.sql.ResultSet;
023    
024    /**
025     * @author Jorge Ferrer
026     * @author Julio Camarero
027     */
028    public class UpgradeLayoutSet extends UpgradeProcess {
029    
030            @Override
031            protected void doUpgrade() throws Exception {
032                    updateLayoutSets();
033            }
034    
035            protected void updateLayoutSets() throws Exception {
036                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
037                            StringBundler sb = new StringBundler(4);
038    
039                            sb.append("select Group_.groupId, Group_.liveGroupId, ");
040                            sb.append(
041                                    "LayoutSet.layoutSetId from LayoutSet inner join Group_ ");
042                            sb.append("on (LayoutSet.groupId = Group_.groupId and ");
043                            sb.append("Group_.liveGroupId > 0 and LayoutSet.logo = ?)");
044    
045                            try (PreparedStatement ps = connection.prepareStatement(
046                                            sb.toString())) {
047    
048                                    ps.setBoolean(1, true);
049    
050                                    try (ResultSet rs = ps.executeQuery()) {
051                                            while (rs.next()) {
052                                                    long groupId = rs.getLong("Group_.groupId");
053                                                    long layoutSetId = rs.getLong("LayoutSet.layoutSetId");
054    
055                                                    runSQL(
056                                                            "update LayoutSet set logoId = 0 where groupId = " +
057                                                                    groupId + " and layoutSetId = " + layoutSetId);
058                                            }
059                                    }
060                            }
061                    }
062            }
063    
064    }