Empty Trash Bin

Last modified by Vincent Massol on 2025/02/12 12:24

bin_emptyEmpties the trash bin from all deleted documents
TypeSnippet
Category
Developed by

Jerome

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Information

Best used in the Groovy Console

Code

{{groovy}}
def emptybin = 0 // set to 1 if you want to empty the trash bin for the whole wiki

def query = "select distinct ddoc.fullName from XWikiDeletedDocument as ddoc "
query += "where not exists (from XWikiDocument as doc where doc.fullName=ddoc.fullName)"
def trashed = xwiki.search(query)
if(trashed.size() > 0) {
 def deleted = 0
 println "<strong>Trashed documents:</strong>\n"
 for(trash in trashed) {
   println "" + trash + " (" + xwiki.getDeletedDocuments(trash, "").size() + " versions)"
   if (emptybin == 1)
      xwiki.getDeletedDocuments(trash, "").each{
        xwiki.getXWiki().getRecycleBinStore().deleteFromRecycleBin(
            xwiki.getDocument(it.fullName).document,
            it.getId(),
            xcontext.context,
            true);
        deleted++;
       }
  }
 if (emptybin == 1) println "\nDeleted <strong>" + deleted + "</strong> trashed document. Trash bin is now empty."
}
else println "Everything's clean. No trashed document found."
{{/groovy}}

Result

An empty trash bin.

Get Connected