TOPIC: Building a workflow engine. Tips and information
Building a workflow engine. Tips and information
4 days 17 hours ago #70386
Thank you received: 8
For the past year I have been working on a workflow solution and I wanted to share some of my findings for others so that they don't need to go through the same as I have.
Don't use the before save logic hook,
I went to use this hook initially as the name implies, it would be a more efficient to make changes to a record before it saves instead of after and triggering it to save again (using a static Boolean or something to prevent a rerun)
Most situations there isn't a problem but
It turns out that if you create a record and save it within a before save logic hook of another record, if there is a relationship between the two modules, the new record will implicitly be related to the record that was being saved in the workflow, and as there is no information as to what link to use, the first or default link to be defined will be used for the relationship potentially overwriting other links between records. I imagine that suite expects anything newly created during an update to a record has to be related to the one being saved and possibly is part of suites implementation for this so if you want to so anything with relationships use the after save method and handle aborting a rerun.
A static array for your Dao's/beans isn't entirely necessary.
Suite keeps all the beans it loads in a static array and all the bean factory methods use it. So if you want to keep track of records between processes, suite already does this for you.
Dates are best set with format YYYY-MM-DD
If you are manipulating any date information, put it in the above format, in my experience not sure if it's the query builder or the ORM's fault but suite prefers dates are saved programmatically in the above format and does not handle the conversion before hitting the database for you.
Don't log sugar beans
If you try a var_export one of suites Dao objects, you will get back all of its internals including vardefs, query builder, and your log files will grow very quickly.
PHP will complain about circular references too so I find it better to extract what you want to log and log it separately.
The administrator has disabled public write access.