• Purge trash of all users

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #11600  by Catscratch
 
Hi,

is there a way to purge the trash of all users?

And another question: Is the disk space released on purging?

thanks
 #11615  by jllort
 
This kind of operation might be only done by administrator. I'm not sure if can be done by okmAdmin user, test it. If not might be created a process on batch for doing it (might be disabled by default and only execute with supervision ).

When trash is empty, all files are completelly deleted and can not be restored. At midnight there's a process that definitive frees allocated size by these files.
 #11629  by Catscratch
 
Do you have an example for such a batch process?

Or may I only clear the folders on the disk and OpenKM recognizes it?
 #11635  by jllort
 
take a look here http://wiki.openkm.com/index.php/Crontab.

The method involved is
Code: Select all
 OKMRepository.getInstance().purgeTrash(null); 
I've studied in more depth and seems internally it's only prepared to purge the logged user trash
Code: Select all
userTrash = session.getRootNode().getNode(Repository.TRASH + "/" + session.getUserID())
;

Might be done some changes on source code to made what you want, it's easy but must be done.
 #11645  by Catscratch
 
How may I call the method
Code: Select all
OKMRepository.getInstance().purgeTrash(null);
Do you have an example BeanShell script? Afaik BeanShell supports JavaScript. But how to I access the Java method purgeTrash?

Thanks a lot.
 #11660  by Catscratch
 
Code: Select all
com.openkm.api.OKMRepository r = com.openkm.api.OKMRepository.getInstance();
try {
r.purgeTrash(null);
} catch (AccessDeniedException e) {
			log.error(e.getMessage(), e);
			throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMRepositoryService, ErrorCode.CAUSE_AccessDenied), e.getMessage());
		} catch (RepositoryException e ) {
			log.error(e.getMessage(), e);
			throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMRepositoryService, ErrorCode.CAUSE_Repository), e.getMessage());
		} catch (DatabaseException e) {
			log.error(e.getMessage(), e);
			throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMRepositoryService, ErrorCode.CAUSE_DatabaseException), e.getMessage());
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMRepositoryService, ErrorCode.CAUSE_General), e.getMessage());
		}
Ok, this script works, but only purges the trash of the logged in user.
May you modify this script in a way, that it iterates over all users and purges the trash?

Or will it be fixed in a newer OKM version?
 #11681  by pavila
 
This all-users purge operation should only be done is some special situation, and I can't image any of them. You can log as okmAdmin and purge elements from every user trash. If you want a quick way to purge all user trash, try this script: Purge all users trash.
 #11682  by Catscratch
 
Thanks for the script.

I got an error on line 19:
Code: Select all
BaseDocumentModule.purge(session, child.getParent(), child);
Code: Select all
Attempt to resolve method: purge() on undefined variable or class name: BaseDocumentModule : at Line: 19 
What should BaseDocumentModule be?
 #11700  by pavila
 
The script works on OpenKM 5.1.x and should be adapted to work on OpenKM 5.0.x. To do so, take a look at the implementation of DirectDocumentModule.purge() method.
 #11715  by Catscratch
 
OK. I found it. Hopefully the script works right interally.

But this script removes all items in the trash:
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.bean.*;
import com.openkm.module.base.*;
import com.openkm.module.direct.*;

String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
Node trash = session.getRootNode().getNode(Repository.TRASH);
DirectDocumentModule docModule = new DirectDocumentModule();
DirectFolderModule folderModule = new DirectFolderModule();

for (NodeIterator it = trash.getNodes(); it.hasNext(); ) {
    Node userTrash = it.nextNode();
    print("User Trash: " + userTrash.getPath() + "<br/>");

    for (NodeIterator itut = userTrash.getNodes(); itut.hasNext(); ) {
        Node child = itut.nextNode();

        if (child.isNodeType(Document.TYPE)) {
            print("About to delete file: " + child.getPath() + "<br/>");
            docModule.purge(null, child.getPath());
        } else if (child.isNodeType(Folder.TYPE)) {
            print("About to delete folder: " + child.getPath() + "<br/>");
            folderModule.purge(null, child.getPath());
        }
    }

    userTrash.save();
}
Is this script ok? Or could there arise problems in the future when using it weekly?
 #11751  by pavila
 
The result should be the same, but I prefer the wiki purge all user trash because it fastest and does not leave a trace is the activity log table. I have added a link to this forum thread in the wiki to point your modified script adapted to OpenKM 5.0.x.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.