Sit, roll and start flow! Commands in Magnolia CMS

Commands are custom actions executed at pre-defined trigger points. Magnolia CMS uses them to send email, flush cache, take backups, import and export data and many other common duties.

A command can perform virtually any task you can write in Java like send a Tweet or upload a photo to Flickr. You are not limited to features inside the CMS itself.

Here's how commands work. A command definition makes the command available to the system. Below is a definition for the deactivate command. Its purpose is to pull a web page down from the public instance.

As you can see, the command definition has just one property, class, which identifies the Java class that should be executed when the command is called (DeactivationCommand).

Its counterpart command activate is a bit more complicated:

activate is actually a chain of three commands:
  1. version creates a new version of the page.
  2. startFlow starts an activation workflow.
  3. alert sends a workflow notification to the recipient's Magnolia inbox.
When you call the parent command the children are executed one-by-one from top down.

Command definitions can contain other properties besides class. The startFlow command has a property workflowName which identifies the workflow that should be launched. Defining properties rather than hard coding them gives content editors more flexibility. Editors can replace the default approval workflow with a custom one by simply assigning it to the activate command, without having to touch code.

To find more examples of command definitions, sign into the demo (u/p: superuser/superuser) and execute this JCR query in the config repository in AdminCentral > Tools > JCR Queries.

select * from nt:base where jcr:path like '%/commands/%'

You will find the corresponding Java business logic in the SVN repository:

See also: Commands in official documentation