How-to: trigger a workflow using the Public API: old vers...
Skip to end of metadata Go to start of metadata
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 7 Next »
The ContentService implemented in Exponential 5.1 has no knowledge of the Legacy workflow engine. This means that all features in the 4.x series that used workflows need a workaround. One of the most common use-cases is pre-publishing approval, for instance of user generated content.
Legacy kernel callbacks
Fortunately, there is a quite simple way to trigger workflows from Exponential 5 code: by using a Legacy Kernel Callback. The overall process is described in the Legacy code and features documentation chapter.
Create with the Public API, publish with the Legacy Kernel
Thanks to this, it is possible to create a draft using native Exponential 5 code, and get this draft pre-approved using the legacy workflow & collaboration systems, including email notifications.
Legacy workflow configuration
Let's take an approval workflow as an example. It needs to be configured the old way, using the backoffice. Create a workflow, add an Approve event to it, and connect it to the content/publish/before trigger.
Create a draft using the public API
This is the the usual way, as extensively covered in the Public API Cookbook. The main different is that we will NOT call ContentService::publishVersion().
Create content using the Public API
Publish a Public API draft using the Legacy Kernel
First, a method must be used to obtain a legacy kernel. This can be used, given that getContainer() returns the Symfony Dependency Injection Container:
Then, you need to use the object to run a Legacy Kernel Callback (e.g. code fragment).
The code above takes a contentId (object ID), and a version number as the argument, and runs the content/publish operation on it. It then returns true if the operation ended successfully, or false if it was aborted by the workflow engine (or if it failed, but it can be improved).
Pay attention to the Repository user
Icon
Public API code is always executed as a user, by default anonymous. Since workflows are often user dependent (Approval is), it is important that this code is executed as an editor, or as a user who will trigger the workflow.
Logging a user in
Of course, this isn't required when using Public API code in controllers, since those will use the currently-logged in user.
Data compatibility
Content created using the Public API does appear as expected
Test script
The code below is a working Command script example that demonstrates the workaround. Just drop it in a bundle and update the namespace: https://gist.github.com/bdunogier/e05ed564770fa6a51e51
- No labels
Contributors
- Bertrand Dunogier Updated
Comments
Add a comment