Comments on Delete Spam Users

Last modified by Denis Gervalle on 2015/10/20 19:36

  • Jerome
    Jerome, 2010/12/08 23:29

    If you have a very large amount of spam users, you might want to delete the XWikiAllGroup document first, or this script is likely to fail with a Heap Space exception. You can restore the XWikiAllGroup with legit users only once you've got rid of spammers using Restore XWikiAllGroup

  • Denis Gervalle
    Denis Gervalle, 2015/10/20 19:35

    Also, if you have a very large farm, and a large amount of users to delete, you may want to speed up the process a lot (from hours to minutes!) if you do not care about cleaning delete users in rights objects and in group members, by dropping the rightsmanager listener during the process, just wrap the above script with:

    {{groovy}}
     public void dropListener(def listener) {
       def observationManager = services.component.componentManager.getInstance(org.xwiki.observation.ObservationManager.class);
       def contextKey = "saved${listener}";
       def listenerInstance = observationManager.getListener(listener);
        xcontext.context.put(contextKey, listenerInstance);
        println "Remove the ${listener} Listener (${listenerInstance})"
        observationManager.removeListener(listener);
     }

     if (request.confirm) {      
        dropListener('rightsmanager');
     }  
    {{/groovy}}

    {{velocity}}
    ...
    {{/
    velocity}}

    {{groovy}}
     public void restoreListener(def listener) {
       def observationManager = services.component.componentManager.getInstance(org.xwiki.observation.ObservationManager.class);
       def contextKey = "saved${listener}";
       def listenerInstance = xcontext.context.get(contextKey);
        println "Installed the ${listener} Listener (${listenerInstance})";
        observationManager.addListener(listenerInstance);
        xcontext.context.remove(contextKey);
     }

     if (request.confirm) {
        restoreListener('rightsmanager');
     }  
    {{/groovy}}

    You may as well drop/restore the activitystream listener, if you want your activity to stay silent.

Get Connected