Page 1 of 1

Script to lock all files in OpenKM

PostPosted:Wed Sep 16, 2015 3:11 pm
by hariharan.gopal
Hi,

I am using OpenKM 5.1.8.
I need to lock all the files using script. (which ever format it is. For Eg., txt or pdf or xls). It should all the files. So please help me on this.

Can you help me with a script.
Thanks in Advance.

Re: Script to lock all files in OpenKM

PostPosted:Fri Sep 18, 2015 7:16 am
by jllort
I suggest upgrade to 6.3 version, you're using an older OpenKM version. Will not be more easy change security rather lock document ?

Take a look at this script http://wiki.openkm.com/index.php/Script ... _traversal ( should run on version 5.x too )
Code: Select all
for (Document doc : OKMDocument.getInstance().getChildren(null, path)) {
     // Add lock 
     OKMDocument.getInstance().lock(null,path);
}
I think you should remove the Logger log = LoggerFactory.getLogger("com.openkm.scripting"); ( I'm not sure about it, but I think is not supported on 5.x ).

Take in mind you're using a very old version, what we consider deprecated.

Re: Script to lock all files in OpenKM

PostPosted:Tue Sep 22, 2015 5:39 pm
by hariharan.gopal
Hi,

Actually there are few old files which was not locked. So I want to lock those existing files.

FYI: I am able to lock the newly created files.

Thanks in Advance.

Re: Script to lock all files in OpenKM

PostPosted:Wed Sep 23, 2015 12:14 pm
by hariharan.gopal
Hi,

Below code helps to lock all files, including the files under subfolder.
Code: Select all
import com.openkm.api.*;
import com.openkm.bean.*;
String testPath = "/okm:root/Test/";
int MAX_DEPTH = 15;
 void nodeTask(String path, int depth) {
    for (Document doc : OKMDocument.getInstance().getChilds(null, path)) {
             if (!OKMDocument.getInstance().isLocked(null, doc.getPath())) {
                     OKMDocument.getInstance().lock(null,doc.getPath());
             }
    }
    
    for (Folder fld : OKMFolder.getInstance().getChilds(null, path)) {
        if (depth < MAX_DEPTH) {
            nodeTask(fld.getPath(), depth + 1);
        }
    }
}
nodeTask(testPath, 0);

Re: Script to lock all files in OpenKM

PostPosted:Thu Sep 24, 2015 6:27 pm
by jllort
The code you posted, locks all files into the repository based on a recursive call. It's correct.