Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: DOCU-1967

...

  • Independent of the UI
  • Back-end executable
  • Executed by UI (for example by an action), Web services or other modules such as the Workflow and Scheduler

You can write your own custom commands and execute them on-demand or scheduled.

...

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue
Mgnl f
ui-admincentral
 

Mgnl f
commands

 


Mgnl f
default

 

Mgnl n
markAsDeleted

 

Mgnl p
class

info.magnolia.commands.impl.MarkNodeAsDeletedCommand

Mgnl p
enabled

true

Mgnl n
export

 

Mgnl p
class

info.magnolia.importexport.command.JcrExportCommand

Mgnl n
import

 


Mgnl p
class

info.magnolia.importexport.command.JcrImportCommand

Mgnl n
delete

 


Mgnl n
deactivate


Mgnl p
class

info.magnolia.module.activation.commands.DeactivationCommand

Mgnl p
enabled

true

Mgnl n
delete


Mgnl p
class

info.magnolia.commands.impl.DeleteCommand

Mgnl p
enabled

true

Mgnl n
restorePreviousVersion


Mgnl p
class

info.magnolia.commands.impl.RestorePreviousVersionCommand

Mgnl p
enabled

true

Mgnl n
exportYaml


Mgnl p
class

info.magnolia.commands.ExportJcrNodeToYamlCommand

...

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue
Mgnl f
activation
 

Mgnl f
commands

 

Mgnl f
default

 

Mgnl n
activate

 

Mgnl f
versioned

 

Mgnl n
activate

 


Mgnl n
deactivate

 

The advantage of using a catalog is that you can have identically named commands. You might want two activate commands – one for pages and another for assets. To call a command that resides in a catalog, use the catalog name followed by a hyphen, then the command name. For example, you would distinguish the two activate commands by calling one with workflow-activate and the other with default-activate.

...

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue
Mgnl f
activation
 

Mgnl f
commands

 

Mgnl f
default

 

Mgnl n
activate

 

Mgnl p
class

info.magnolia.module.activation.commands.ActivationCommand

Mgnl n
deactivate

 


Mgnl f
versioned

 


Mgnl n
activate

 

Mgnl n
version

 

Mgnl p
class

info.magnolia.commands.impl.VersionCommand

Mgnl p
enabled

true

Mgnl n
activate

 


Mgnl p
class

info.magnolia.commands.DelegateCommand

Mgnl p
commandName

default-activate

Mgnl n
deactivate

 


Executing commands with actions

...

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl f
modules

 


Mgnl f
pages

 

Mgnl f
apps

 

Mgnl n
pages

 

Mgnl n
subApps

 

Mgnl n
browser

 


Mgnl n
actions

 

Mgnl n
activate

 


Mgnl p
catalog

website

Mgnl p
class

info.magnolia.ui.framework.action.ActivationActionDefinition

Mgnl p
command

activate

Mgnl p
icon

icon-publish

...

Advanced Tables - Table Plus
heading0
multiplefalse
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue
Mgnl f
scheduler
 

Mgnl f
config

 


Mgnl f
jobs

 

Mgnl n
demo

 

Mgnl n
params

 

Mgnl p
path

/news

Mgnl p
repository

website

Mgnl p
active

 false

Mgnl p
catalog

 website

Mgnl p
command

 activate

Mgnl p
cron

 0 0 * * * *

Mgnl p
description

 activate each hour the page news.html

...

Use the Groovy console to execute command business logic manually, in ad hoc fashion. This is a quick way to test a custom command before you compile it as a Java class. Both of the two options below publish the page /travel/about/careers .

...

You can test it by making a small change on the careers page, executing the Groovy commands, and viewing the modified history page on the public instance. 

  • Open the Groovy app.
  • Issue the following commands in the console:

    • Option A - Calling the info.magnolia.commands.CommandsManager.executeCommand():

      Code Block
      java
      java
      map  = new java.util.LinkedHashMap<String, String>()
      map.put("path", "/travel/about/careers")
      map.put("repository", "website")
      cm = info.magnolia.commands.CommandsManager.getInstance()
      cm.executeCommand('default','publish',map)
      
    • Option B - Passing a SimpleContextobject to the execute() method:

      Code Block
      java
      java
      cm = info.magnolia.commands.CommandsManager.getInstance()
      command = cm.getCommand('activate')

...

    • 
      command.setRepository('website')

...

    • 
      command.setPath('/travel/about/careers')

...

    • 
      command.setRecursive(true)
      command.execute(

...

This example activates the page /travel/about/careers. You can test it by making a small change on the careers page, executing the Groovy commands, and viewing the modified history page on the public instance.

...

    • new info.magnolia.context.SimpleContext())
      

Executing a command as a Groovy script

...

Advanced Tables - Table Plus
enableHeadingAttributesfalse
enableSortingfalse
classm5-configuration-tree
enableHighlightingfalse
Node nameValue

Mgnl f
modules

 


Mgnl f
myModule

 


Mgnl f
commands

 


Mgnl f
myCatalog

 


Mgnl n
myCommand

 


Mgnl p
class

com.example.modules.acme.commands.MyCommand

...

Code Block
languagejava
titleMyCommand.java
public class MyCommand extends BaseRepositoryCommand {
  public boolean execute(Context context) {
    // Your command logic goes here.
  }
}

See the commands in the  info.magnolia.commands.impl  package for examples.