Hi,
I want to delete all comments of a page for my plugin. My implementation only deletes the oldest.
Here's my code:
private void deleteComments(AbstractPage page) {
List<Comment> comments = page.getComments();
for(Comment comment : comments) {
commentManager.removeCommentFromObject(comment.getId());
// only removes first because event? is fired
}
}
All i found out is that the execution is interuptet after the first iteration by "SingleParameterMethodListenerInvoker".
I can't find a reason why the removeCommentFromObject method isn't invoked for all comments.
Thanks for help
I've got it running!
The problem was that I tried to iterate the page-comments list directly. This failed because this list was modified by the removeCommentFromObject method, which caused a java.util.ConcurrentModificationException
The solution is to simply use a copy of the list:
List<Comment> comments = new ArrayList<>(page.getComments());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.