2

On Magnolia, I've created a Groovy script to delete unused users. When I run the Groovy script directly from the "DEV > Groovy scripts" interface (on the admin central), it works fine.

Now, I'm trying to schedule the execution of that script. So I've configured a Command and a Scheduler.

The command : scheduler > config > commands > default > groovyDeleteUsers with attributes: - class = my.commandes.GroovyDeleteAllPublicUsersCommand

The Scheduler : scheduler > config > jobs > deleteUsersJob with attributes:

  • active=true
  • catalog=default
  • command=groovyDeleteUsers
  • cron=0 0 8 * * * *

Here is how my Groovy script is structured :

package my.commands;

import info.magnolia.commands.*;
import info.magnolia.context.MgnlContext;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

public class GroovyDeleteAllPublicUsersCommand extends MgnlCommand {

    public boolean execute(Context ctx) {

    ....
    }
}

The problem is that the scheduler job is not able to see my command.

Magnolia Can't find command [groovyDeleteUsers] for job in catalog [{default}]

I've try the JCR query : "select * from nt:base where jcr:path like '%/commands/%'" as specified in the documentation, and my newly created command is in the result.

[EDIT] It seems the problem come from the command. When I try defining a command with an existing class like info.magnolia.commands.impl.ImportCommand the command is well registred by the applicaation. But when I try with my my.commandes.GroovyDeleteAllPublicUsersCommand the application doesn't registrer my newly created command.

So do you have any idea?

Thanks for helping, Regards, Jimmy

Dekx
  • 402
  • 2
  • 15

2 Answers2

2

Your problem is not about the setup which is totally correct except the command is not in correct place. Try to put your command definitions right under the module rather than config e.g. put it to ui-admincentral/commands

Edit: Apparently yet another problem was about the groovy command vs java one.

For more information and examples: this page should be sufficient.

Cheers,

Ducaz035
  • 3,054
  • 2
  • 25
  • 45
  • I've made the update. My command is now here : `/modules/ui-admincentral/commands/default/groovyDeleteUsers` but I still have the same issue. – Dekx May 24 '18 at 08:36
  • it still can't find the command? Because that works for me still :S – Ducaz035 May 24 '18 at 09:37
  • Ok, seems I have an error while creating the commands entry. The logs display an error : ```can't resolve class for node /modules/ui-admincentral/commands/default/deleteAllPublicUsers java.lang.ClassNotFoundException: Could not compile my.commands.GroovyDeleteAllPublicUsersCommand with Groovy``` – Dekx May 24 '18 at 09:57
  • `Invalid duplicate class definition of class my.commands.GroovyDeleteAllPublicUsersCommand : The source magnolia-repository://scripts/my/commands/GroovyDeleteAllPublicUsersCommand contains at least two definitions of the class my.commands.GroovyDeleteAllPublicUsersCommand.` – Dekx May 24 '18 at 09:57
  • I fixed the duplicate class definition. But my command is still not registred. When editing my command, I have logs : `Adding new command [restorePreviousVersion] to already registered catalog [default]... Adding new command [export] to already registered catalog [default]... Adding new command [import] to already registered catalog [default]... Adding new command [markAsDeleted] to already registered catalog [default]... Adding new command [delete] to already registered catalog [default]... Adding new command [sendMail] to already registered catalog [default]... ` but mine is not there – Dekx May 24 '18 at 10:25
  • 1
    I've try to change the class attribute to an other existing but not Groovy class, and my command is registred (ex. `info.magnolia.commands.impl.ImportCommand`). So the problem comes from my Groovy command class. – Dekx May 24 '18 at 10:46
  • I've added theses informations in the [EDIT] section of the main post for more visibility. – Dekx May 24 '18 at 12:14
  • ah alright because i tried usual java one, didn't know you were looking for groovy but now it's all good, right? – Ducaz035 May 24 '18 at 12:42
  • Hi @Dekx, I'm having the exactly the same problem with you when trying to create a command class using Groovy Script. I quite don't understand your solution, changing `public class GroovyDeleteAllPublicUsersCommand extends MgnlCommand` to extends `info.magnolia.commands.impl.ImportCommand` insteads ? How do I `change the class attribute to an other existing but not Groovy class` ?, thanks – ThangLeQuoc Feb 15 '19 at 12:11
  • So the idea to create a command class with Groovy Script and schedule it doesn't work ? A command class must be in pure Java, so the application redeployment is required, is this correct ? Thanks – ThangLeQuoc Feb 15 '19 at 12:45
  • 1
    Hi, I had to having my Groovy script in Java. The reason why it was not working was because both my Java className and Goovy script name were the same. Change your Goovy script name to make it work. – Dekx Feb 15 '19 at 16:28
0

As far as I know the catalog name must be unique in the system. "default" already exists in ui-admincentral/commands.

Marc Johnen
  • 379
  • 3
  • 11
  • 2
    That was not a problem. The problem was from the commandName. The Groovy Class Name and the Groovy file/command name MUST be differents. Because Magnolia try to create a Command name from the class name. If il already exist, it fail to register. So can't be scheduled. – Dekx Jul 10 '18 at 13:09