• Script to lock all files in OpenKM

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
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.
 #40543  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.
 #40551  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.
 #40603  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);
 #40617  by jllort
 
The code you posted, locks all files into the repository based on a recursive call. It's correct.

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.