Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,312
Community Members
 
Community Events
165
Community Groups

ScriptRunner for Confluence selective bulk deletion of pages

Hi

We have recently purchased SR for Confluence and  as a non coder I am looking for a script that could help with the bulk deletion of 'selected pages' to help in housekeeping our DC instance.

The selection would be something like 'last updated more than 2 years ago' and then the ability to bulk delete that selection.

A related but side question on the selection - could SR establish a 'last page view'?

Then I could combine these two filters or run them independently before deleting the returned pages

Thanks in advance for help here!

Regards

Gordon

2 answers

2 accepted

0 votes
Answer accepted

Hey @Gordon Rutherford, did you ever get solution? If not, I may be able to come up with something.

Hi Tiffany

Not yet and I am actually getting a price from the Adaptavist Scripting service to write the code - and if it is not to expensive for my limited budget I would proceed with that. I have received a lot of helpful (free) support from your team over the last two years and would be happy to pay for it for once if price is reasonable!

If not I may be raising it out the next champions hour!

Regards

Gordon

Like Tiffany Wortham likes this

Hey Gordon!

Since I didn't get to answer this for Champion Hour, here's a solution that may work for you.

Create a CQL escalation service job that looks like this:
Screen Shot 2022-02-22 at 12.19.50 PM.png
It may seem like a strange choice, but we're using a CQL escalation service job so we can use CQL to select the right pages. I have the cron expression set so far in the future so that it won't run regularly, but if you would like it to run it regularly, of course, you could just use a different cron expression. Since we're selecting the pages through CQL, the script is really simple:

import com.atlassian.confluence.core.DefaultDeleteContext
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator

def pageManager = ComponentLocator.getComponent(PageManager)

hits.each { page ->
pageManager.trashPage(page, DefaultDeleteContext.DEFAULT)
}

In order to see which pages you're about to delete, you can check the hits you get next to the CQL Query field. If you see some pages you don't want to delete, just add a label to them and exclude that label in your CQL query, like "label != 'whatever'"

You can just hit "Run now" to run this once. Hope this helps (:

Like # people like this

Hi Tiffany

I really appreciate you coming back to me with this after the hour yesterday which, as always was great.

Something is not quite working as expected for me and it throws a StackOverflowError when I 'run now', however if you then run it again it works as expected and deletes the page. See my snip for the error

Thanks for your input

Best regards

Gordonstackoevrflow.PNG

Hi Gordon,

I think I remember this happening to me at one point too. I'm not sure why this happens sometimes, but I don't think it actually has anything to do with the script itself. I'd say just ignore it, and try running it again when that happens.

Hi Tiffany

Thanks for coming back to me and yes ignoring error seems to be fine

Cheers

Gordon

0 votes
Answer accepted

Adding @Ravi Sagar _Sparxsys_ 

Maybe he can shoot a tutorial on his youtube vlogs.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Confluence

Confluence: Where work and wellness meet

Feeling overwhelmed by the demands of work and life? With a 25% increase in the prevalence of anxiety and depression worldwide during the pandemic, for most of us, it’s a resounding yes . 🙋‍♀️ ...

1,130 views 22 29
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you