001    /**
002     * Copyright (c) 2000-2013 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.verify;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.model.Layout;
020    import com.liferay.portal.service.LayoutLocalServiceUtil;
021    
022    import java.util.List;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Kenneth Chang
027     */
028    public class VerifyLayout extends VerifyProcess {
029    
030            @Override
031            protected void doVerify() throws Exception {
032                    verifyFriendlyURL();
033                    verifyUuid();
034            }
035    
036            protected void verifyFriendlyURL() throws Exception {
037                    List<Layout> layouts =
038                            LayoutLocalServiceUtil.getNullFriendlyURLLayouts();
039    
040                    for (Layout layout : layouts) {
041                            String friendlyURL = StringPool.SLASH + layout.getLayoutId();
042    
043                            LayoutLocalServiceUtil.updateFriendlyURL(
044                                    layout.getPlid(), friendlyURL);
045                    }
046            }
047    
048            protected void verifyUuid() throws Exception {
049                    verifyUuid("AssetEntry");
050                    verifyUuid("JournalArticle");
051    
052                    StringBundler sb = new StringBundler(3);
053    
054                    sb.append("update Layout set uuid_ = sourcePrototypeLayoutUuid where ");
055                    sb.append("sourcePrototypeLayoutUuid != '' and ");
056                    sb.append("uuid_ != sourcePrototypeLayoutUuid");
057    
058                    runSQL(sb.toString());
059            }
060    
061            protected void verifyUuid(String tableName) throws Exception {
062                    StringBundler sb = new StringBundler(8);
063    
064                    sb.append("update ");
065                    sb.append(tableName);
066                    sb.append(" set layoutUuid = (select sourcePrototypeLayoutUuid from ");
067                    sb.append("Layout where ");
068                    sb.append(tableName);
069                    sb.append(".layoutUuid = Layout.uuid_ and ");
070                    sb.append("Layout.sourcePrototypeLayoutUuid != '' and ");
071                    sb.append("Layout.uuid_ != Layout.sourcePrototypeLayoutUuid)");
072    
073                    runSQL(sb.toString());
074            }
075    
076    }