In this article I’ve explained how you can quickly intercept Magnolia workflow process when users start it. Then, an approval workflow (so-called 4-eyes) is started and unless a publisher say: “ok, approved” your content won’t go online. If you want to know more about how a standard Magnolia workflow works, please have a look here.
Back on topic: how can you intercept the exact moment (just after or just before) when your content is published?
This can cover for example the following use cases:
– you want to populate a stats-table where you can see how many publications you have in a time period, by users, …
– you want to trigger some backend action, like re-indexing content…
– you want to send a message to someone: “Hey, another webpage has just been published!”
– you want to add additional metadata on your article, like a “real” publication date + author + approval + …
The right approach will be to create a 4-eyes workflow + mods from scratch, deploy it, map to Magnolia tasks and.. ok, stop it. We just need a simple and quick hook action.
Let’s do it.
Let me just to recap the overall round, since the lane is not so straight.
Phase 1: workflow starts (in Magnolia world)
- A user clicks on “publish” action
- The publish action executes a Magnolia command, configured right under “pages” app, website-activate under /pages/commands/website/activate
- The website-activate command in pages app in Community Edition simply starts the activation. But on Enteprise Edition it delegates to another command, workflow-activate
- That command starts the workflow with a very important parameter, called “commandName”. This parameter, with a value of “personalizationActivation” will be the final command that Magnolia will execute once back from JBPM rounds, when activation is approved. That value is overwritten by Personalization module (instead of “activate”, in default catalog of activation module
Phase 2: workflow approval round (rounds between Magnolia and JBPM engine)
- A Pulse message appears to users belonging to “publishers” groups
- One (not important who) publisher claims the Task
- That user now clicks on “Approve & publish”
Phase 3: workflow approval round (back to Magnolia)
- The command passed as parameter (commandName) when workflow has been started, now activates the content
Our goal is to intercept the last action of the process. Since the last action is.. yes, a standard Magnolia Command! ..and it is a simple command, we can replace it with a command chain, as following:
moving our ContextLoggerCommand before or after the original “personalizationActivation” command allows our code to be executed before or after the publication of the node. If you want to do something even if the public intance is down (or if activation errors occur) place your logic before. Otherwise, your logic will be executed only when activation succeeded.
Try to approve a workflow with this configuration. In the log files you will see:
2015-05-11 23:53:40,329 INFO info.magnolia.module.scheduler.CommandJob : Starting job [asyncCommand1431348820304]...
2015-05-11 23:53:40,576 INFO info.magnolia.module.activation.BaseSyndicatorImpl: Exchange: activation succeeded [/demo-features/modules]
2015-05-11 23:53:44,081 INFO info.magnolia.commands.MgnlCommand : Logging command parameters:
2015-05-11 23:53:44,081 INFO info.magnolia.commands.MgnlCommand : param repository: website
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param recursive: false
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param path: /demo-features/modules
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param modifiedOnly: false
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param uuid: 7ebc1cf9-ad73-4578-b5c4-5550fc376cb8
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param comment: This is a comment
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param version: 1.1
2015-05-11 23:53:44,082 INFO info.magnolia.commands.MgnlCommand : param requestor: superuser
2015-05-11 23:53:44,082 INFO info.magnolia.module.scheduler.CommandJob : Job executed successfully [asyncCommand1431348820304]
Just a note: in Magnolia CMS, Commands are referenced with 2 values: command catalog and command name. The first is a simple “folder” and it aims to make a sort of order in the overall Magnolia commands bag. Is normal to have more than one command called “activate” (or whatever else..) but on different catalogs. If a command is referenced withoud a catalog, it is implicitly referenced to a command in catalog “default”. And if more than one command is stored with the same pair of values, well.. quite complicated, it depends on the command registry strategy. By default, the first command found wins.
Be First to Comment