I'd like to use the "Bulk delete comments from one or more pages" canned script on all pages of a specific space running as a script job and deteting page comments older than 60 days.
However, this script has a few user params defined and wants the user to select a page.
Not 100% sure on how to approach this? Do I build a custom 'Script CQL function' and then use the 'CQL escalation service' script job type?
Hi Thomas,
I think the best approach would be to get a list of the current pages for a space using the SpaceManager and PageManagers that are built-in to the Confluence API. You can then use these to call the built-in space.
I have taken the liberty of putting an example script together:
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.canned.confluence.admin.BulkDeleteComments
import groovy.json.JsonBuilder
def spaceMgr = ComponentLocator.getComponent(SpaceManager.class)
def pageMgr = ComponentLocator.getComponent(PageManager.class)
// The canned script we want to use...
def canned = new BulkDeleteComments()
// Let's grab the space
def space = spaceMgr.getSpace("ds")
def ids = pageMgr.getPages(space, true).collect{ it.idAsString }
// Build the params
def scriptParams = [
"FIELD_PAGE": new JsonBuilder(ids).toString(),
"FIELD_AGE": "60",
]
// Run the script
def response = canned.doScript(scriptParams)
response["output"] // <- Return the response - don't need to do this for a built-in job but you might want to log it.
TODO: Where I do spaceMgr.getSpace("ds") you need to swap that for your desired spaces key.
If you want to test this out you can run it from a script console first. Otherwise put it into a script job to run at your desired frequency.
If you have any questions just let me know.
I hope this helps!
Steve
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.