Hello - we are running (server) Confluence with Comala Document Management and Scriptrunner.
There is an archival workflow that manages pages such that after a year of inactivity they are flagged for review and if no action is taken they are then flagged for removal.
Comala Document Management does not have the capability to delete pages. The most I can do is restrict them and add a label "to-be-deleted".
Scriptrunner appears to have to the theoretical ability to run a script, on a schedule, that will look for all pages with a specific label (i.e. to-be-deleted) and delete said pages.
I have a small script in Scriptrunner that will find and return the ids of all pages with a specific label - what I have not been able to find is how to delete pages in a Scriptrunner script.
Hi Jason!
It sounds like you're almost there with your script so I'll just add the snippet displaying how you can send a single page to the trash.
The Page Manager contains the method Trash Page which will accept the ids of the page you have already fetched as well as a Delete Context.
You can view an example of how this is used below:
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.core.DefaultDeleteContext
def pageManager = ComponentLocator.getComponent(PageManager)
def pageToDelete = pageManager.getPage(<page_id>)
pageManager.trashPage(pageToDelete, DefaultDeleteContext.DEFAULT)
Kind regards,
Lee
Lee - as I never said at the time, thanks for this snippet of code.
Moving on - Wow. Blast from the past. This got back-burnered for a long time, as much due to rage-quitting as anything else.
I am stuck at not being able to find a code permutation that will allow for anything other than deleting a page with a specific value for page_id.
My code as this point is:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jason!!
Wow, it sure has been a minute since we last spoke about this! I hope you're doing well 🙂
I believe I've found a pretty efficient way of handling this problem.
Here's the script:
import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.labels.LabelManager
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.core.DefaultDeleteContext
import com.atlassian.confluence.core.ContentEntityObject
import com.atlassian.confluence.pages.AbstractPage
def pageManager = ComponentLocator.getComponent(PageManager)
def labelManager = ComponentLocator.getComponent(LabelManager)
Label label = new Label("delete")
def labeledPages = labelManager.getContentForLabel(0,50,label).getList()
labeledPages.each{ ContentEntityObject page ->
if(page.getClass() == Page){
pageManager.trashPage(page as AbstractPage, DefaultDeleteContext.DEFAULT)
}
}
To give you a rundown of what's happening here, we're using Confluence's in-built getContentForLabel method to fetch all content, i.e. blog pages, space categories and Pages, that have a specified label.
I've set the number of pages to fetch as 50, but feel free to change this. I'd also recommend taking a good look at the Label Manager, as you may find a more suitable method for your particular use case there.
Next up, we're looping through the content returned with that specific label, checking that it's a Page, then moving it to the trash!
As a note, I'd recommend running this on a test instance and ensuring that it is working as expected before running it on production.
I hope this helps, but please let me know if you have any further questions 😁
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.