001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.verify;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.workflow.WorkflowConstants;
020    import com.liferay.portlet.blogs.model.BlogsEntry;
021    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
022    
023    import java.util.List;
024    
025    /**
026     * @author Raymond Augé
027     */
028    public class VerifyBlogs extends VerifyProcess {
029    
030            @Override
031            protected void doVerify() throws Exception {
032                    updateEntryAssets();
033                    verifyStatus();
034            }
035    
036            protected void updateEntryAssets() throws Exception {
037                    List<BlogsEntry> entries =
038                            BlogsEntryLocalServiceUtil.getNoAssetEntries();
039    
040                    if (_log.isDebugEnabled()) {
041                            _log.debug(
042                                    "Processing " + entries.size() + " entries with no asset");
043                    }
044    
045                    for (BlogsEntry entry : entries) {
046                            try {
047                                    BlogsEntryLocalServiceUtil.updateAsset(
048                                            entry.getUserId(), entry, null, null, null);
049                            }
050                            catch (Exception e) {
051                                    if (_log.isWarnEnabled()) {
052                                            _log.warn(
053                                                    "Unable to update asset for entry " +
054                                                            entry.getEntryId() + ": " + e.getMessage());
055                                    }
056                            }
057                    }
058    
059                    if (_log.isDebugEnabled()) {
060                            _log.debug("Assets verified for entries");
061                    }
062            }
063    
064            protected void verifyStatus() throws Exception {
065                    runSQL(
066                            "update BlogsEntry set status = " +
067                                    WorkflowConstants.STATUS_APPROVED + " where status is null");
068            }
069    
070            private static Log _log = LogFactoryUtil.getLog(VerifyBlogs.class);
071    
072    }