Empty Trash Bin

Last modified by Vincent Massol on 2018/06/05 10:54

bin_emptyEmpties the trash bin from all deleted documents
Developed by

Jerome

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

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.

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Created by Jerome on 2009/09/25 16:11
     

Get Connected