Page 1 of 1
Exporting and importing automation rules
PostPosted:Tue Jan 24, 2017 2:42 pm
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!
Re: Exporting and importing automation rules
PostPosted:Wed Jan 25, 2017 7:46 pm
by jllort
What is your database ?
Re: Exporting and importing automation rules
PostPosted:Thu Jan 26, 2017 10:40 am
by openkm_user
MySQL.
Re: Exporting and importing automation rules
PostPosted:Fri Jan 27, 2017 9:54 pm
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 allOKM_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 allmysqldump -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 allmysql -h localhost -u openkm -p okmdb < OKM_AUTO_RULE.sql
Hope it be useful to you.
Re: Exporting and importing automation rules
PostPosted:Tue Feb 07, 2017 10:12 am
by openkm_user
Thank you very much, this saved a lot of time

.
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!
Re: Exporting and importing automation rules
PostPosted:Thu Feb 09, 2017 7:39 pm
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.
Re: Exporting and importing automation rules
PostPosted:Fri Feb 10, 2017 8:41 am
by openkm_user
Can you please help with both rename event and applying rules on already uploaded documents?
Thanks so much in advance!
Re: Exporting and importing automation rules
PostPosted:Sat Feb 11, 2017 5:25 pm
by jllort
Take a look at DbDocumentModule.java for example the method checkin what fires the event "document update"
Code: Select allpublic 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 allpublic static final String EVENT_DOCUMENT_RENAME = "doc_rename";
Add into the administration list at AutomationServlet.java
And there's nothing much else.
Re: Exporting and importing automation rules
PostPosted:Mon Feb 13, 2017 1:44 pm
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 allOKM_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 allmysqldump -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 allmysql -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 (27.91 KiB) Viewed 4542 times
This error, what is wrong, please help!
Re: Exporting and importing automation rules
PostPosted:Tue Feb 14, 2017 10:40 am
by openkm_user
Also when I click on
Definition, it shows this error,
Capture.JPG (27.19 KiB) Viewed 4540 times
Something didn't go right in SQL table imports?
Re: Exporting and importing automation rules
PostPosted:Wed Feb 15, 2017 4:22 pm
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.
Re: Exporting and importing automation rules
PostPosted:Wed Feb 15, 2017 6:52 pm
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 (14.39 KiB) Viewed 4532 times
Re: Exporting and importing automation rules
PostPosted:Fri Feb 17, 2017 11:16 am
by jllort
Will be necessary to take a look at the catalina.log file for a complete log error.