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.verify;
016    
017    import com.liferay.blogs.kernel.model.BlogsEntry;
018    import com.liferay.blogs.kernel.service.BlogsEntryLocalServiceUtil;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.LoggingTimer;
022    import com.liferay.portal.kernel.workflow.WorkflowConstants;
023    
024    import java.util.List;
025    
026    /**
027     * @author Raymond Aug??
028     */
029    public class VerifyBlogs extends VerifyProcess {
030    
031            @Override
032            protected void doVerify() throws Exception {
033                    updateEntryAssets();
034                    verifyStatus();
035            }
036    
037            protected void updateEntryAssets() throws Exception {
038                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
039                            List<BlogsEntry> entries =
040                                    BlogsEntryLocalServiceUtil.getNoAssetEntries();
041    
042                            if (_log.isDebugEnabled()) {
043                                    _log.debug(
044                                            "Processing " + entries.size() + " entries with no asset");
045                            }
046    
047                            for (BlogsEntry entry : entries) {
048                                    try {
049                                            BlogsEntryLocalServiceUtil.updateAsset(
050                                                    entry.getUserId(), entry, null, null, null, null);
051                                    }
052                                    catch (Exception e) {
053                                            if (_log.isWarnEnabled()) {
054                                                    _log.warn(
055                                                            "Unable to update asset for entry " +
056                                                                    entry.getEntryId() + ": " + e.getMessage());
057                                            }
058                                    }
059                            }
060    
061                            if (_log.isDebugEnabled()) {
062                                    _log.debug("Assets verified for entries");
063                            }
064                    }
065            }
066    
067            protected void verifyStatus() throws Exception {
068                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
069                            runSQL(
070                                    "update BlogsEntry set status = " +
071                                            WorkflowConstants.STATUS_APPROVED +
072                                                    " where status is null");
073                    }
074            }
075    
076            private static final Log _log = LogFactoryUtil.getLog(VerifyBlogs.class);
077    
078    }