I have a request to Space wide update the hyperlinks for a particular URL. I have a script to replace the text but it did not touch the URL in the hyperlink.
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.core.DefaultSaveContext
def targetSpaceId = 'XXXX'
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def targetSpace = spaceManager.getSpace(targetSpaceId)
def spacePages = pageManager.getPages(targetSpace, true)
spacePages.each{page ->
def pageBody = page.getBodyAsString()
if (pageBody.contains(oldText)){
pageBody = pageBody.replace(oldText, newText)
page.getBodyAsString()
pageManager.saveContentEntity(page, DefaultSaveContext.DEFAULT)
}
}
Is there a way for it to make those changes?
My assumption is that page.getBodyAsString() is not quite right or it needs to be tweaked to pull the storage format.