Archive Structures That Haven’t Been Accessed in 3 Months

This article is for Data Center. Visit Cloud

Archive Structures That Haven’t Been Accessed in 3 Months

Tracking access time for structures only become available with Structure 8.2. This means the earliest tracking available occurs shortly after the first upgrade to 8.2 or higher. If a structure hasn't been accessed since that update, it is considered never accessed.

import java.time.Duration import com.almworks.jira.structure.api.StructureComponents import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.almworks.jira.structure.sync.AOBasedSyncManager import com.almworks.jira.structure.api.permissions.PermissionLevel @WithPlugin('com.almworks.jira.structure') @PluginModule StructureComponents sc def sm = sc.getStructureManager() def sps = sc.getStructurePropertyService() def syncM = sc.getSyncManager() def currentTime = System.currentTimeMillis() def structures = sm.getAllStructures(PermissionLevel.VIEW) def oldStructures = structures.findAll { structure ->   def lastPolledMillis = sps.getLong(structure.id, "lastPolledMillis", 0)   return Duration.ofMillis(currentTime - lastPolledMillis).toDays() > 90 } // In this part we archive the structures oldStructures.each { oldStructure ->   oldStructure.setArchived(true).saveChanges()    ((AOBasedSyncManager)syncM).disableSynchronizers(oldStructure.id) }