Script - Purge all folders into some parent
That script purges all folders into a parent, without previously moving files to trash.
The purge action is a non recovery action that removes definitely the objects from OpenKM repository. Use it with care.
import org.hibernate.*;
import com.openkm.dao.*;
import com.openkm.dao.bean.NodeFolder;
import java.util.*;
import com.openkm.api.OKMFolder;
Session session = null;
found = true;
try {
String sql = "from NodeFolder nf where nf.parent='aa08b392-0117-4b29-af9a-c4419ba6cab6'";
while (found) {
session = HibernateUtil.getSessionFactory().openSession();
Query q = session.createQuery(sql);
q.setMaxResults(100);
found = false;
List fldList = new ArrayList();
for (NodeFolder fld : q.list()) {
found= true;
fldList.add(fld.getUuid());
}
for (String uuid : fldList) {
try {
OKMFolder.getInstance().purge(null, uuid);
} catch (Exception e) {
print(e.getMessage() + "<br/>");
}
}
}
} catch (Exception e) {
print(e.getMessage());
} finally {
HibernateUtil.close(session);
}