Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner for Confluence selective bulk deletion of pages

Gordon Rutherford
Contributor
July 8, 2021

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

3 answers

3 accepted

0 votes
Answer accepted
Jessie Wang_ScriptRunner_The Adaptavist Group
Atlassian Partner
September 28, 2022

Hi all, this script is now available in our Script Library for ScriptRunner for Confluence Server/DC (tested by our engineers).

Feel free to copy or customise it as you wish https://library.adaptavist.com/entity/automate-the-removal-of-old-or-inactive-content

Gordon Rutherford
Contributor
September 28, 2022

Nice - thanks for update

0 votes
Answer accepted
Tiffany Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2022

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

Gordon Rutherford
Contributor
February 7, 2022

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
Tiffany Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2022

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
Gordon Rutherford
Contributor
February 23, 2022

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

Tiffany Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2022

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.

Gordon Rutherford
Contributor
March 8, 2022

Hi Tiffany

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

Cheers

Gordon

0 votes
Answer accepted
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2022

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
AUG Leaders

Atlassian Community Events