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    import com.liferay.portlet.blogs.util.LinkbackConsumerUtil;
023    import com.liferay.portlet.messageboards.model.MBDiscussion;
024    import com.liferay.portlet.messageboards.model.MBMessage;
025    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
026    
027    import java.util.List;
028    
029    /**
030     * <p>
031     * This class looks at every blog comment to see if it is a trackback and
032     * verifies that the source URL is a valid URL. Do not run this unless you want
033     * to do this.
034     * </p>
035     *
036     * @author Alexander Chow
037     */
038    public class VerifyBlogsTrackbacks extends VerifyProcess {
039    
040            @Override
041            protected void doVerify() throws Exception {
042                    List<MBDiscussion> discussions =
043                            MBMessageLocalServiceUtil.getDiscussions(
044                                    BlogsEntry.class.getName());
045    
046                    for (MBDiscussion discussion : discussions) {
047                            long entryId = discussion.getClassPK();
048                            long threadId = discussion.getThreadId();
049    
050                            try {
051                                    BlogsEntry entry = BlogsEntryLocalServiceUtil.getBlogsEntry(
052                                            entryId);
053    
054                                    List<MBMessage> messages =
055                                            MBMessageLocalServiceUtil.getThreadMessages(
056                                                    threadId, WorkflowConstants.STATUS_APPROVED);
057    
058                                    for (MBMessage message : messages) {
059                                            LinkbackConsumerUtil.verifyPost(entry, message);
060                                    }
061                            }
062                            catch (Exception e) {
063                                    _log.error(e, e);
064                            }
065                    }
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    VerifyBlogsTrackbacks.class);
070    
071    }