Programmatically enable plugins

Describe the issue or problem
I would like to programmatically enable plugins via a CLI tool. Is there a tool that has already been developed that currently does this?

What application are you using?
For example, OJS 3.3.0-11

Hi @jrmitchell,

I’ve inquired with some of our team members, and, so far as we know, such a utility does not exist. However, we’d be curious about your use case on this and what you would wish to achieve with such a tool?

-Roger
PKP Team

Hi Roger,

I administer several OJS installs (approximately ten production installs) for my academic library, and I pretty much have the deployment process automated for updating and installing plugins. However, I’ve noticed that the installed plugins I manage via automation aren’t enabled in the new OJS version, but they appear to have been enabled in the prior version.

Perhaps, I’m going about the upgrade process the wrong way, but I was hoping to enable the plugin from the command line since that would allow me to manage the upgrade process from beginning to end without needing to log into the web interface.

Does that make sense? If not, let me know, and I can take another whack at explaining how I’d use such a tool.

Thanks,
James

Hi @jrmitchell,

Thanks very much for your explanation. That’s very interesting and I could see how that would be quite useful in that context.

I would suspect that developing such a utility might involve developing something like a script to make changes to the DB that would then update the installation status of the plugin in the DB. Granted, that’s an oversimplification on my part, and it would likely be more involved, as well as have potential pitfalls. @jnugent - curious if you have any thoughts on this?

-Roger
PKP Team

Hi everyone,

There already is a way to install a plugin via the command line, with the installPluginVersion.php CLI tool that comes with OJS. It can be used like:

php lib/pkp/tools/installPluginVersion.php path/to/plugin/version.xml

To actually continue with enabling the plugin, you’d need to set the enabled plugin setting in the plugin_settings table to 1 for the journal_id in question. Some plugin categories have a setEnabled method that you can use for this, but most notably the Generic plugin does not. You may need to wrap the plugin installer with a bit of code that fetches your journal ids in the installation and then updates this value. You could probably do this with a series of MySQL REPLACE statements, which would create the record if it did not already exist or update it if it did.

Best
Jason

1 Like

Hi Jason,

Thanks you for your response.

I have thankfully been able to use the CLI tool installPluginVersion.php for installing plugins programmatically and have found it very helpful. So, thanks to all the developers who did work on this tool.

As for the second part of your response, that makes perfect sense. I assumed there was a value stored in the DB that told OJS whether the plugin was enabled or not, but wasn’t sure.

I will explore my options for enabling plugins via the CLI.

Thanks,
James

If I recall well, some time ago @ctgraham made a script that was able to enable plugins… but I don’t remember where it was published (gist maybe?).

A cli-tool for OJS is a common petition in forum and gitHub.

If the installPluginVersion plugin is not enough, feel free to create a new “Feature Request” in the FR forum.

Hi @jnugent ,
Does this command works for plugin update? I have about 32 OJS installations and the biggest problem I have had is updating plugins.

Hi @dagosalas

No, it won’t update a plugin. It just installs into the database what is currently there, so you’d still need to download it another way.

Best
Jason

1 Like

I’ve updated the gist here:

1 Like

Thanks Clinton (for the update and the script)!

Didn’t remember it was included in core:

More information here:

Sorry to left a little from the focus of the initial post but I think it could be useful for others:

I have 50 installations so my tip for this is create a single folder with the plugins in read-only and symlink them from all my installations. To upgade you have two choices… temporary change from read-only to full access, then upgade and rollback the permissions or (as far as I have a docker based installation with volumes) I set one (restricted) installation with full access rights to manage all the plugins installation and upgrade from a single place.

Said that, Clinton’s script is great and opens the door to automatize repetitive admin tasks. The only missing piece is how to enable the plugins, that till the “enable” feature is implemented (the coding skills are much over my pay grade) I’m planing to go directly to the DB and enable them from there.

1 Like