You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2007/08/09 15:54:38 UTC
svn commit: r564207 - in /roller/trunk/apps/weblogger:
src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
src/java/org/apache/roller/weblogger/util/MailUtil.java
web/WEB-INF/classes/ApplicationResources.properties
Author: snoopdave
Date: Thu Aug 9 06:54:36 2007
New Revision: 564207
URL: http://svn.apache.org/viewvc?view=rev&rev=564207
Log:
Several fixes here for some old bugs and some new regressions related to the Struts2 upgade:
- When comments are deleted, the entries associated with those comments are re-indexed to remove the comment from the search index.
- When comments are approved, the entries associated with those comments are re-indexed to add the comment to the search index.
- When comments are approved and email notification is enabled, approval emails are sent out to the folks who commented.
Fixes these issues:
Comment cannot be searched after it is approved
http://opensource.atlassian.com/projects/roller/browse/ROL-1523
Deleted entry is still searchable
http://opensource.atlassian.com/projects/roller/browse/ROL-1499
Modified:
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/MailUtil.java
roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties
Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java?view=diff&rev=564207&r1=564206&r2=564207
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java Thu Aug 9 06:54:36 2007
@@ -22,14 +22,18 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.WeblogManager;
+import org.apache.roller.weblogger.business.search.IndexManager;
+import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.WeblogEntry;
import org.apache.roller.weblogger.pojos.WeblogEntryComment;
import org.apache.roller.weblogger.pojos.WeblogPermission;
@@ -37,6 +41,8 @@
import org.apache.roller.weblogger.ui.struts2.util.KeyValueObject;
import org.apache.roller.weblogger.util.cache.CacheManager;
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
+import org.apache.roller.weblogger.util.I18nMessages;
+import org.apache.roller.weblogger.util.MailUtil;
import org.apache.roller.weblogger.util.Utilities;
@@ -62,6 +68,9 @@
// last comment in the list
private WeblogEntryComment lastComment = null;
+ // entry associated with comments or null if none
+ private WeblogEntry queryEntry = null;
+
// indicates number of comments that would be deleted by bulk removal
// a non-zero value here indicates bulk removal is a valid option
private int bulkDeleteCount = 0;
@@ -88,19 +97,17 @@
WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
// lookup weblog entry if necessary
- WeblogEntry queryEntry = null;
if(!StringUtils.isEmpty(getBean().getEntryId())) {
- queryEntry = wmgr.getWeblogEntry(getBean().getEntryId());
+ setQueryEntry(wmgr.getWeblogEntry(getBean().getEntryId()));
}
// query for comments
List rawComments = wmgr.getComments(
getActionWeblog(),
- queryEntry,
+ getQueryEntry(),
getBean().getSearchString(),
getBean().getStartDate(),
- getBean().getEndDate(),
- getBean().getStatus(),
+ getBean().getEndDate(),getBean().getStatus(),
true, // reverse chrono order
getBean().getPage() * COUNT,
COUNT + 1);
@@ -213,6 +220,25 @@
try {
WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
+
+ // if search is enabled, we will need to re-index all entries with
+ // comments that have been deleted, so build a list of those entries
+ Set<WeblogEntry> reindexEntries = new HashSet<WeblogEntry>();
+ if (WebloggerConfig.getBooleanProperty("search.enabled")) {
+ List<WeblogEntryComment> targetted = (List<WeblogEntryComment>)wmgr.getComments(
+ getActionWeblog(),
+ getQueryEntry(),
+ getBean().getSearchString(),
+ getBean().getStartDate(),
+ getBean().getEndDate(),
+ getBean().getStatus(),
+ true,
+ 0, -1);
+ for (WeblogEntryComment comment : targetted) {
+ reindexEntries.add(comment.getWeblogEntry());
+ }
+ }
+
int deleted = wmgr.removeMatchingComments(
getActionWeblog(),
null,
@@ -221,8 +247,15 @@
getBean().getEndDate(),
getBean().getStatus());
- // TODO: i18n
- addMessage("Successfully deleted "+deleted+" comments");
+ // if we've got entries to reindex then do so
+ if (!reindexEntries.isEmpty()) {
+ IndexManager imgr = WebloggerFactory.getWeblogger().getIndexManager();
+ for (WeblogEntry entry : reindexEntries) {
+ imgr.addEntryReIndexOperation(entry);
+ }
+ }
+
+ addMessage("commentManagement.deleteSuccess", Integer.toString(deleted));
// reset form and load fresh comments list
setBean(new CommentsBean());
@@ -248,6 +281,10 @@
WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
List<WeblogEntryComment> flushList = new ArrayList();
+
+ // if search is enabled, we will need to re-index all entries with
+ // comments that have been approved, so build a list of those entries
+ Set<WeblogEntry> reindexList = new HashSet<WeblogEntry>();
// delete all comments with delete box checked
List<String> deletes = Arrays.asList(getBean().getDeleteComments());
@@ -260,8 +297,9 @@
// make sure comment is tied to action weblog
if(getActionWeblog().equals(deleteComment.getWeblogEntry().getWebsite())) {
- wmgr.removeComment(deleteComment);
flushList.add(deleteComment);
+ reindexList.add(deleteComment.getWeblogEntry());
+ wmgr.removeComment(deleteComment);
}
}
}
@@ -301,6 +339,7 @@
wmgr.saveComment(comment);
flushList.add(comment);
+ reindexList.add(comment.getWeblogEntry());
} else if(spamIds.contains(ids[i])) {
log.debug("Marking as spam - "+comment.getId());
@@ -325,7 +364,20 @@
CacheManager.invalidate(comm);
}
-// sendCommentNotifications(request, approvedComments);
+ // send notification for all comments changed
+ if (MailUtil.isMailConfigured()) {
+ I18nMessages resources =
+ I18nMessages.getMessages(getActionWeblog().getLocaleInstance());
+ MailUtil.sendEmailApprovalNotifications(approvedComments, resources);
+ }
+
+ // if we've got entries to reindex then do so
+ if (!reindexList.isEmpty()) {
+ IndexManager imgr = WebloggerFactory.getWeblogger().getIndexManager();
+ for (WeblogEntry entry : reindexList) {
+ imgr.addEntryReIndexOperation(entry);
+ }
+ }
addMessage("commentManagement.updateSuccess");
@@ -411,5 +463,12 @@
public void setPager(CommentsPager pager) {
this.pager = pager;
}
-
+
+ public WeblogEntry getQueryEntry() {
+ return queryEntry;
+ }
+
+ public void setQueryEntry(WeblogEntry queryEntry) {
+ this.queryEntry = queryEntry;
+ }
}
Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/MailUtil.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/MailUtil.java?view=diff&rev=564207&r1=564206&r2=564207
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/MailUtil.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/MailUtil.java Thu Aug 9 06:54:36 2007
@@ -484,6 +484,22 @@
log.debug("Done sending email message");
}
+
+ public static void sendEmailApprovalNotifications(List<WeblogEntryComment> comments,
+ I18nMessages resources)
+ throws MailingException {
+
+ RollerMessages messages = new RollerMessages();
+ for (WeblogEntryComment comment : comments) {
+
+ // Send email notifications because a new comment has been approved
+ sendEmailNotification(comment, messages, resources, true);
+
+ // Send approval notification to author of approved comment
+ sendEmailApprovalNotification(comment, resources);
+ }
+ }
+
/**
* Send message to author of approved comment
@@ -541,7 +557,6 @@
log.debug("Done sending email message");
}
-
// agangolli: Incorporated suggested changes from Ken Blackler.
Modified: roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties?view=diff&rev=564207&r1=564206&r2=564207
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/classes/ApplicationResources.properties Thu Aug 9 06:54:36 2007
@@ -289,6 +289,7 @@
commentManagement.bulkDeletePrompt1=Your query matched {0} comments,
commentManagement.bulkDeletePrompt2=delete them all?
commentManagement.confirmBulkDelete=Are you sure you want to delete all {0} selected by your query?
+commentManagement.deleteSuccess=Successfully deleted {0} comments
commentManagement.pendingStatus=Pending status
commentManagement.onlyPending=Pending only