Update comment author

Hello,

I am trying to update comments for users that have been migrated from the internal Jira user database to a directory database. The code snippet I am using currently in a proof of concept is a groovy script with scriptrunner:

                    comments.each { comment ->
                        MutableComment mutableComment = commentManager.getMutableComment(comment.getId())
                        CommentService.CommentParameters commentParameters = new CommentService.CommentParameters.CommentParametersBuilder().author(userId).body(comment.getBody()).build()
                        CommentService.CommentUpdateValidationResult commentUpdateValidationResult = commentService.validateCommentUpdate(currentUser,mutableComment.getId(),commentParameters)
                        if (commentUpdateValidationResult.getWarningCollection().hasAnyWarnings()) {
                            log.debug "Comment Warnings: " + commentUpdateValidationResult.getWarningCollection().hasAnyWarnings()
                        }
                        if (commentUpdateValidationResult.getErrorCollection().hasAnyErrors()) {
                            log.debug "Comment Errors: " + commentUpdateValidationResult.getErrorCollection().hasAnyErrors()
                        }
                        if (commentUpdateValidationResult.isValid()) {
                            log.debug "Updating user comment ${comment.getId()} for issue ${comment.getIssue()} for user ${user.getKey()} to ${userId.getName()}"
                            commentService.update(currentUser, commentUpdateValidationResult, false)

The script compiles and runs without issues. It reports that the comment(s) are properly updated. But they are not. There is no error message or indication what might be wrong. Do you see any issue with the approach? Is there a working way?

Thank you and best regards,

Nico

The only way I have found in groovy

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.comments.CommentManager;

userUtil = ComponentAccessor.getUserUtil();
CM = ComponentAccessor.getComponent(CommentManager.class);

oldUser = userUtil.getUserByName("oldUser") 
newUser = userUtil.getUserByName("newUser")

// make a loop for issue
cmnts = CM.getCommentsForUser(issue, oldUser)

cmnts.each {
  CM.create(issue,newUser,newUser,it.getBody(),it.getGroupLevel(),it.getRoleLevelId(),it.getCreated(),it.getUpdated(),false)
  CM.delete(it);
}

update the Author does not work

Thank you @yann,

I tried the outlined way on Jira 7.13.2 and it did not work either. I will now leave this issue as it is and argue that the revision safety of the system is responsible for that. :wink:

Best regards,
Nico

1 Like