[DOCU-1967] Commands: wrong example of execution through groovy Created: 31/Oct/19  Updated: 06/Nov/19  Resolved: 06/Nov/19

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Jonathan Ayala Assignee: Martin Drápela
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2019-11-06-10-21-38-233.png    
Issue Links:
relation
is related to PUBLISHING-66 Groovy script fails sometimes when pu... Closed
Template:
Acceptance criteria:
Empty
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Epic Link: 2019 mgnl-staff requests

 Description   

The piece of code shown in Executing a command in the Groovy console section leads to errors since the context object used within groovy scope, which is actually a info.magnolia.module.groovy.console.MgnlGroovyContextDecorator object, doesn't work for certain cases like publish. See PUBLISHING-66.

There are some tickets where customers reported wrong behaviour after executing commands this way so we should correct our docs in order to avoid its usage.

The way the should be executed is either calling info.magnolia.commands.CommandsManager.executeCommand() or passing a SimpleContext object to execute() method instead of groovy ctx object. 

Option1
map  = new java.util.LinkedHashMap<String, String>()
map.put("path", "/PATH-TO-PAGE")
map.put("repository", "website")
cm = info.magnolia.commands.CommandsManager.getInstance()
cm.executeCommand('default','publish',map)  
option2
cm = info.magnolia.commands.CommandsManager.getInstance()
command = cm.getCommand('activate')
command.setRepository('website')
command.setPath('/PATH-TO-PAGE')
command.setRecursive(true)
command.execute(new info.magnolia.context.SimpleContext())

Generated at Mon Feb 12 01:22:53 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.