How to make plugin settings register only with context_id=0

Hey,
while developing the Fidus Writer plugin [1], I’ve had a bit of difficulty udnerstanding how to ensure that the plugin is only ever applied to the entire site and no specific contexts. This is important, as this plugin contains a gateway plugin that won’t work be registered unless it’s enabled on a sitewide basis.

I first had the problem of the gateway not being registered locally. I thought I had fixed it by setting sitewide to 1 in the version.xml file and it was working locally for me. But when installing on the server, I found the same problem as what I had experienced locally. Looking into the database, I noticed the plugin had been enabled but with the contex_id of a journal (1). I spent some hours on this without getting closer to a solution yesterday.

This morning I noticed that the link to the site settings was missing on the server which had only one journal registered. I then registered a second journal. Now the link to the sitewide settings showed up. The gateway still didn’t work immediately, but by clicking around on the page and monitoring the plugin_settings table, it suddenly worked. There are now three settings enabling it: for context_id 0, 1 and 2.

The question is: How does one make sure that a plugin can only be enabled for context_id 0? And how does one get the site wide plugin settings to show when there is only one journal registered?

[1] GitHub - fiduswriter/ojs-fiduswriter: A Open Journal Systems (OJS) plugin to connect to Fidus Writer

Hi @Johannes_Wilm,

Is this work for OJS 3.x or 2.x?

In general, the Plugin::isSitePlugin() function should inform OJS that the plugin is site-wide if you return true. More specifically, you might find that some plugin contexts don’t expect site-wide plugins yet – thinking in particular of the GatewayPlugin base class. It might be necessary to look at the GatewayHandler that invokes these plugins to see if it’s prepared to handle a sitewide plugin. (I don’t think we’ve used this case ourselves yet.)

Clinton (@ctgraham) has been working on the general case a little recently, so might have some advice to provide.

Regards,
Alec Smecher
Public Knowledge Project Team

Hey @asmecher,

Sorry, all OJS 3.0. It may also apply in 2.x, but we have only ever tried 3.x .

As far as I can tell, we are returning that already.

The plugins (both generic and gateway), seem to work fine, as long as they are enabled correctly with context_id=0 in the plugin_settings table. It’s just that I can’t find a way to ensure that whenever a user enables it, it is only with context_id=0. This would probably mean that I would need to find a way to:

  • Hide the settings for the plugin when the user is looking at the settings of one specific journal.

  • Ensure that there is a link to the global settings, even if just one journal is registered.

I may be wrong and there may be some other way that this should work. The main important part is just to get the context_id==0.

Hi @Johannes_Wilm,

You might want to take a look at issue #1923 (scheduled for OJS 3.1). That might resolve the issue in general – but OTOH in the meantime (and take with a grain of salt, I’m currently on vacation) you might be able to resolve it by overriding the functions that get/set the enabled status of the plugin.

Note that there are a few peculiarities that might help to explain the current behavior (and bug entry linked above): we’ve tried to make the system behave intuitively for both single-journal installations, and multi-journal installations, each of which has different requirements. For single-journal installations, it doesn’t make sense to have both site configuration areas and journal-specific configuration areas; in that case, we’ve tried to collapse them together into a unified configuration area (with a few exceptions, such as permitting the administrator to create/delete journals).

Regards,
Alec Smecher
Public Knowledge Project Team

Oh sorry. I didn’t expect you to put in extra hours for this. We can wait until later. For now, we’ll just have to add to the instructions something like “Make sure to create at least 2 journals on your OJS instance. Then navigate to […] to enable the plugin globally. Ignore the plugin being mentioned in any other settings.” This should be OK for now. I was just wondering if we did something wrong.

Issue #1923 looks like it will solve it.

seems that @asmecher has a weird definition for being on vacation.

1 Like

Hi all,

Guilty.

Regards,
Alec Smecher
Public Knowledge Project Team