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.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    }