• Exporting and importing automation rules

  • 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.
 #43073  by openkm_user
 
Hi,

I have written 50 automation rules in Administration -> Automation, the same rules are needed in development and staging environments, instead of creating those 50 again is there any way to export and import? Or if we can get data from database tables and insert it in right places will it work?

Thanks!
 #43112  by jllort
 
In this case you must export few database tables and then import again in destination. You might be interested in these tables:
Code: Select all
OKM_AUTO_RULE
OKM_AUTO_ACTION
OKM_AUTO_VALIDATION
OKM_AUTO_ACTION_PARAMS
OKM_AUTO_VALIDATION_PARAMS
The specific mysqldump you must use for extracting a single table ( only inserts, without database creation ) should be ( repeat for each table ):
Code: Select all
mysqldump -t -h localhost -u openkm -p --no-create-db --no-create-info --extended-insert=FALSE okmdb OKM_AUTO_RULE > OKM_AUTO_RULE.sql
From destination database you should do something like ( repeat for each table )
Code: Select all
mysql -h localhost -u openkm -p okmdb < OKM_AUTO_RULE.sql
Hope it be useful to you.
 #43182  by openkm_user
 
Thank you very much, this saved a lot of time :D.

Now I have written these rules for "while creating file", is there any way I can write something that will apply the rules for already imported/uploaded file?

Also there is no way i can add automation rule to a file when it gets renamed, or is there any way?

Thanks!
 #43195  by jllort
 
Rules only take effect when the event is raised. When the document is created it raises "document creation" event. In your case should create an script, follow across all the repository and make something ( if you want I can try to share with you some url for the starting point ).

About rename event, is not implemented in community, but I can guide to you about what classes must be changed for it.
 #43203  by openkm_user
 
Can you please help with both rename event and applying rules on already uploaded documents?

Thanks so much in advance!
 #43213  by jllort
 
Take a look at DbDocumentModule.java for example the method checkin what fires the event "document update"
Code: Select all
public Version checkin(String token, String docId, InputStream is, long size, String comment, String userId, int increment)
See this piece of code:
Code: Select all
// AUTOMATION - PRE
NodeDocument docNode = NodeDocumentDAO.getInstance().findByPk(docUuid);
Map<String, Object> env = new HashMap<String, Object>();
env.put(AutomationUtils.DOCUMENT_NODE, docNode);
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_DOCUMENT_UPDATE, AutomationRule.AT_PRE, env);
docNode = (NodeDocument) env.get(AutomationUtils.DOCUMENT_NODE);

NodeDocumentVersion newDocVersion = NodeDocumentVersionDAO.getInstance().checkin(userId, comment, docUuid, is, size, increment);
version = BaseModule.getProperties(newDocVersion);

// AUTOMATION - POST
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_DOCUMENT_UPDATE, AutomationRule.AT_POST, env);
You must do something similar with rename method ( in the map probably you are interesed to set the previous name and the new name into vars ). I suggest take a look at AutomationUtils.java class for better understanding about the env map.

Into AutomationRule.jaave create the new event
Code: Select all
public static final String EVENT_DOCUMENT_RENAME = "doc_rename";
Add into the administration list at AutomationServlet.java

And there's nothing much else.
 #43216  by openkm_user
 
jllort wrote:In this case you must export few database tables and then import again in destination. You might be interested in these tables:
Code: Select all
OKM_AUTO_RULE
OKM_AUTO_ACTION
OKM_AUTO_VALIDATION
OKM_AUTO_ACTION_PARAMS
OKM_AUTO_VALIDATION_PARAMS
The specific mysqldump you must use for extracting a single table ( only inserts, without database creation ) should be ( repeat for each table ):
Code: Select all
mysqldump -t -h localhost -u openkm -p --no-create-db --no-create-info --extended-insert=FALSE okmdb OKM_AUTO_RULE > OKM_AUTO_RULE.sql
From destination database you should do something like ( repeat for each table )
Code: Select all
mysql -h localhost -u openkm -p okmdb < OKM_AUTO_RULE.sql
Hope it be useful to you.
After this automation change, I am not able to import/upload documents, it shows,
Capture.JPG
Capture.JPG (27.91 KiB) Viewed 4017 times
This error, what is wrong, please help!
 #43219  by openkm_user
 
Also when I click on Definition, it shows this error,
Capture.JPG
Capture.JPG (27.19 KiB) Viewed 4015 times
Something didn't go right in SQL table imports?
 #43226  by jllort
 
The problem is the UUID of the folder has been changed when you have imported the data ( you have not checked the option, maintaining UUID ) and now there's a rules with a non existing UUID. Basically this is the problem. You should remove the validations what containing missing folders and you should set them again.
 #43228  by openkm_user
 
For all validations same UUID is set, so what I did is created a new Automation Rule (so a new UUID generated for this), updated old records (SQL records I exported before) with new UUID and it worked fine in my local environment, but it is showing following error in another installation.
null.JPG
null.JPG (14.39 KiB) Viewed 4007 times

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.