Page 1 of 1
Purge trash of all users
PostPosted:Wed Jul 20, 2011 9:44 am
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
Re: Purge trash of all users
PostPosted:Fri Jul 22, 2011 10:35 am
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.
Re: Purge trash of all users
PostPosted:Fri Jul 22, 2011 2:07 pm
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?
Re: Purge trash of all users
PostPosted:Sat Jul 23, 2011 6:51 pm
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 alluserTrash = 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.
Re: Purge trash of all users
PostPosted:Mon Jul 25, 2011 8:37 am
by Catscratch
How may I call the method
Code: Select allOKMRepository.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.
Re: Purge trash of all users
PostPosted:Mon Jul 25, 2011 8:24 pm
by pavila
Re: Purge trash of all users
PostPosted:Tue Jul 26, 2011 7:07 am
by Catscratch
Code: Select allcom.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?
Re: Purge trash of all users
PostPosted:Tue Jul 26, 2011 8:08 am
by jllort
Re: Purge trash of all users
PostPosted:Wed Jul 27, 2011 9:24 am
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.
Re: Purge trash of all users
PostPosted:Wed Jul 27, 2011 9:31 am
by Catscratch
Thanks for the script.
I got an error on line 19:
Code: Select allBaseDocumentModule.purge(session, child.getParent(), child);
Code: Select allAttempt to resolve method: purge() on undefined variable or class name: BaseDocumentModule : at Line: 19
What should BaseDocumentModule be?
Re: Purge trash of all users
PostPosted:Sat Jul 30, 2011 4:27 am
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.
Re: Purge trash of all users
PostPosted:Mon Aug 01, 2011 10:12 am
by Catscratch
See next post...
Re: Purge trash of all users
PostPosted:Tue Aug 02, 2011 1:11 pm
by Catscratch
OK. I found it. Hopefully the script works right interally.
But this script removes all items in the trash:
Code: Select allimport 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?
Re: Purge trash of all users
PostPosted:Sat Aug 06, 2011 11:43 am
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.