Fork me on GitHub

Thrash purger

All in one time. Without questions.

package com.onresolve.confluence.scripts

import com.atlassian.confluence.pages.TrashManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.spaces.SpacesQuery
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.spring.container.ContainerManager
import org.apache.log4j.Logger

def trashManager = ContainerManager.getComponent("trashManager") as TrashManager
def spaceManager = ContainerManager.getComponent("spaceManager") as SpaceManager

def spacesQuery = SpacesQuery.newQuery().forUser(AuthenticatedUserThreadLocal.getUser()).build()
def allSpaces = spaceManager.getAllSpaces(spacesQuery)
allSpaces.each {space ->
    println("Empty trash from space: ${space.name}")
    trashManager.emptyTrash(space)
}

println("Emptied trash from ${allSpaces.size()} spaces.")