How to Add a new Column to database schema via plugin in OJS 3.4.0.7

Hi everyone,

I’m working on a plugin for Open Journal Systems (OJS) version 3.4.0.7 and need to add a new column (loaded_review_form_id) to the existing review_forms table. I’d like to handle this schema modification entirely within the plugin, avoiding any direct modifications to core files or manual database edits.

Could anyone provide guidance on how to implement this type of schema change in a plugin? Any recommended approaches or examples would be greatly appreciated.

Thanks in advance for your help!

Hi @bilalelkhouly,

I don’t recommend adding columns to database tables; instead, you can use the review_form_settings table to store your additional items. You should be able to use the reviewformdao::getadditionalfieldnames hook to get the ReviewFormDAO to persist additional settings. It’s called from DAO::getAdditionalFieldNames().

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi @asmecher ,

Thank you for the guidance on using the review_form_settings table instead of adding a new column directly. I understand that the reviewformdao::getAdditionalFieldNames hook can be used to add my custom field, but I’m still a bit unclear on the specifics.

Could you clarify how I would implement this in my plugin? For instance, I want to store an additional field (loaded_review_form_id) in review_form_settings and retrieve it later. I’ve tried creating a function in my plugin that listens to reviewformdao::getAdditionalFieldNames and adds loaded_review_form_id to the list of fields, but I’m unsure if I’m setting it up correctly.

Here’s what I have so far:

  1. I set up a hook listener in my plugin’s register function:
Hook::add('reviewformdao::getAdditionalFieldNames', [$this, 'addAdditionalField']);
  1. In the addAdditionalField function, I add my custom field like this:
public function addAdditionalField($hookName, &$additionalFields) {
    $additionalFields[] = 'loaded_review_form_id';
    return false; 
}

Is this the right approach for using the review_form_settings table to store my custom field, loaded_review_form_id? Any further clarification on how to fully utilize this hook would be greatly appreciated.

Thanks again for your help!

This topic was automatically closed after 23 days. New replies are no longer allowed.