You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I have a number of derived fields which create noise in the issue change log. I'd like to remove these from the log.
I've had a read of https://community.atlassian.com/t5/Jira-questions/Is-it-possible-to-delete-History-records-of-an-issue-like-the/qaq-p/254441 and take note of the warnings. I've also had a look at the code for com.atlassian.jira.issue.changehistory.removeAllChangeItems(Issue issue) in order to understand what it is doing and adapt it to my needs.
I'm wondering if the following code is the correct/safe way to delete change items, without needing to shutdown and restart the service.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.entity.property.JsonEntityPropertyManager
import com.atlassian.jira.entity.Entity
import com.atlassian.jira.entity.property.EntityPropertyType
import com.atlassian.jira.ofbiz.OfBizDelegator
List<String> fieldsToRemove = ["Field Name 1", "Field Name 2", "Field Name 3"]
ChangeHistoryManager changeHistoryManager =
ComponentAccessor.getChangeHistoryManager()
JsonEntityPropertyManager jsonEntityPropertyManager =
ComponentAccessor.getComponent(JsonEntityPropertyManager)
OfBizDelegator ofBizDelegator = ComponentAccessor.getOfBizDelegator()
List<ChangeHistory> history = changeHistoryManager.getChangeHistories(issue)
history.each{ChangeHistory ch ->
Boolean allDeleted = null
ch.changeItems.each {
Long changeItemId = it.get("id")
String field = it.get("field")
if (fieldsToRemove.contains(field)) {
if (allDeleted==null) {
allDeleted = true
}
ofBizDelegator.removeByAnd(Entity.Name.CHANGE_ITEM,
[id: changeItemId].asImmutable())
} else {
allDeleted = false
}
}
if (allDeleted) {
ofBizDelegator.removeByAnd(Entity.Name.CHANGE_GROUP,
[id: ch.id].asImmutable())
jsonEntityPropertyManager.deleteByEntity(
EntityPropertyType.CHANGE_HISTORY_PROPERTY.getDbEntityName(),
ch.id)
}
}
Did this end up working out for you? We're considering something similar and testing of your approach seems fine. I'd love to know if you ran into any issues, though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.