Skip to content

Instantly share code, notes, and snippets.

@ctgraham
Last active September 9, 2022 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctgraham/d21f4153dd95928c740b533a70b3ad94 to your computer and use it in GitHub Desktop.
Save ctgraham/d21f4153dd95928c740b533a70b3ad94 to your computer and use it in GitHub Desktop.
A PKP plugin shim for the CLI

PKP plugin CLI usage

Background

Problem: how do we interact with the PKP Plugin Gallery outside of the UI? The correct way to approach this is to abstract the plugin gallery operations into a service class which would be reusable across the UI and the CLI, but we're not there yet. Instead, let's cheat.

CLI tool

https://github.com/pkp/pkp-lib/blob/stable-3_3_0/tools/plugins.php

This provides a new utility with minimal options:

$ sudo -u apache php lib/pkp/tools/plugins.php help
Plugin Gallery tool
Usage: lib/pkp/tools/plugins.php action [arguments]
  Actions:
        list [search]: show latest compatible plugin(s). Optional "search" text against plugin class
        info path: show detail for plugin identified by "path", such as generic/pln

For example, any plugin with the keyword "article":

$ sudo -u apache php lib/pkp/tools/plugins.php list article
plugins/generic/epubJsViewer https://github.com/EKT/epubJsViewer-ojs/releases/download/v1_0_0-0/epubJsViewer-ojs-v1_0_0-0.tar.gz noInstalledVersion
plugins/generic/hypothesis https://github.com/asmecher/hypothesis/releases/download/v1.0.3-2/hypothesis-v1.0.3-2.tar.gz installedVersionNewest
plugins/generic/coins https://github.com/pkp/coins/releases/download/v1.0.3-2/coins-v1.0.3-2.tar.gz installedVersionNewest
plugins/blocks/keywordCloud https://github.com/lepidus/keywordCloud/releases/download/v1.1.0.5/keywordCloud.tar.gz installedVersionOlder
plugins/generic/texture https://github.com/pkp/texture/releases/download/v2_4_3-3/texture-v2_4_3-3.tar.gz installedVersionNewer
plugins/generic/paperbuzz https://github.com/pkp/paperbuzz/releases/download/v1_0_2-0/paperbuzz-v1_0_2-0.tar.gz installedVersionNewest
plugins/generic/plumAnalytics https://github.com/ulsdevteam/ojs-plum-plugin/releases/download/v1.4.0-0/plumAnalytics-1.4.0-0.tgz installedVersionNewest
plugins/generic/citations https://github.com/RBoelter/citations/releases/download/v3_2_0-3/citations-v3_2_0-3.tar.gz noInstalledVersion
plugins/generic/browseBySection https://github.com/pkp/browseBySection/releases/download/v1_1_0_0/browseBySection-v1_1_0_0.tar.gz installedVersionNewest

Our output will be the plugin path, the latest plugin tarball, and the current status of the plugin (as stolen from the end of the locale keys)

Making some (workaround) magic

Note that these shell scripts are supplied for illustration only. For example, these assume that your webserver user is apache and that you are running as a user able to write to the OJS source, and able to sudo to apache.

You will almost certainly want to change the file permissions on the extracted plugin to match your webserver environment.

Install the latest version of all missing plugins

sudo -u apache php lib/pkp/tools/plugins.php list | grep noInstalledVersion | \
while read plugin
do
  pluginpath=`echo $plugin | cut -d' ' -f1`
  pluginsrc=`echo $plugin | cut -d' ' -f2`
  echo $pluginpath
  if [[ -e $pluginpath ]]
  then
    rm -r $pluginpath
  fi
  wget -q -O /tmp/plugin.tmp.tgz $pluginsrc
  tar -xzf /tmp/plugin.tmp.tgz -C `dirname $pluginpath`
  sudo -u apache php lib/pkp/tools/installPluginVersion.php $pluginpath/version.xml
done

Or, upgrade all plugins:

sudo -u apache php lib/pkp/tools/plugins.php list | grep installedVersionOlder | \
while read plugin
do
  pluginpath=`echo $plugin | cut -d' ' -f1`
  pluginsrc=`echo $plugin | cut -d' ' -f2`
  echo $pluginpath
  rm -r $pluginpath
  wget -q -O /tmp/plugin.tmp.tgz $pluginsrc
  tar -xzf /tmp/plugin.tmp.tgz -C `dirname $pluginpath`
done
sudo -u apache php tools/upgrade.php upgrade
@dunglehome
Copy link

Hello I got error trying to execute the command as instructed above. I have also reported to OJS pkp support forum. https://forum.pkp.sfu.ca/t/plugins-re-installation-after-an-upgrade/67784/8

Thank you for your time.

[root@ojs ojs-3.2.1-4]# pwd
/var/www/html/ojs-3.2.1-4

[root@ojs ojs-3.2.1-4]# sudo -u apache php lib/pkp/tools/pluginGallery.php help
Could not open input file: lib/pkp/tools/pluginGallery.php

Best regards,

Dung.

@ctgraham
Copy link
Author

The following link shows the proposed addition to OJS, which is not yet part of the distributed package:
https://github.com/pkp/pkp-lib/compare/stable-3_1_2...ulsdevteam:pluginGalleryCLI?expand=1

The file itself can be viewed and downloaded here:
https://github.com/ulsdevteam/pkp-lib/blob/8e7d9e5c5fd37bceb621fe65abd51371c0348f8f/tools/pluginGallery.php

@dunglehome
Copy link

Hi @ctgraham, I can confirm the above instruction and script working (I had to use chmod and chown the set permission and ownership on these plugins so they are consistent with the rest of my other files and directories).

Thank you for your excellent work!

@NateWr
Copy link

NateWr commented Nov 3, 2021

This plugin has been merged into the main branch for OJS, OMP and OPS. But the syntax has changed slightly. See more in this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment