Example scripts
To homepage
Confluence

Remove Archived Space
App in script

ScriptRunner For Confluence
by Adaptavist
Compatibility

Confluence (7.15 - 8.6)

ScriptRunner For Confluence (7.10.0)
Language |
groovy
import com.atlassian.confluence.core.ContentEntityManager
import com.atlassian.confluence.api.model.pagination.SimplePageRequest
import com.atlassian.confluence.api.model.content.SpaceStatus
import com.atlassian.confluence.api.model.Expansion
import com.atlassian.confluence.api.service.content.SpaceService
import com.atlassian.confluence.core.ContentEntityObject
import com.onresolve.scriptrunner.runner.ScriptRunner
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import java.time.LocalDate
@PluginModule
ScriptRunner scriptRunner
@PluginModule
ContentEntityManager contentEntityManager
SpaceService spaceService = scriptRunner.getBean(SpaceService)
def pageRequest = new SimplePageRequest(0, 1000)
def spaces = spaceService.find(new Expansion('id')).withStatus(SpaceStatus.ARCHIVED).fetchMany(pageRequest)
def today = LocalDate.now()
def days = 365
def diff
spaces.each { space ->
def lastModContent = contentEntityManager.getRecentlyModifiedEntities(space.key, 1)[0] as ContentEntityObject
def lastModDate = lastModContent.getLastModificationDate().toLocalDate()
diff = today - lastModDate
if ( diff > days ) {
log.warn "The Space $space.key hasn't been modified for more than ${days} days and will be deleted."
spaceService.delete(space)
}
}Having an issue with this script?
Report it here