No Code Attached Yet
avatar luX0r-reload
luX0r-reload
8 Jan 2025

When updating a plugin, the plugin parameters are not updated to what is written in the manifest of the new plugin version.

I developed a plugin for Joomla 5.
I installed version 1.0 and the parameters specified in the manifest were all in the db params field of the #__extensions table.

In version 1.1 I added a parameter to the plugin (radio buttons with two values: 0 and 1. Default value 1).

Updating the plugin from version 1.0 to version 1.1 seems to go smoothly, both with Joomla's update system and with direct ZIP installation.
The new parameter is correctly displayed in the plugin settings, but the plugin does not recognize it and does not work because in the db params field of the #__extensions table the new parameter does not exist.

When I go into the plugin settings and press the Save button (even without changing anything), the new parameter appears in the db params field and the plugin goes back to working as it should.

Joomla! 5.2.3 stable
PHP 8.3.6
Apache/2.4.58

avatar luX0r-reload luX0r-reload - open - 8 Jan 2025
avatar joomla-cms-bot joomla-cms-bot - change - 8 Jan 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 8 Jan 2025
avatar brianteeman
brianteeman - comment - 8 Jan 2025

quick reply
You will need to add a postinstall script to your plugin that updates the paramaters.

When I go into the plugin settings and press the Save button (even without changing anything), the new parameter appears in the db params field and the plugin goes back to working as it should.

This is expected as when you save the plugin the default settings are saved in the database

avatar luX0r-reload
luX0r-reload - comment - 8 Jan 2025

When I first install the plugin, the default parameters are already correctly entered into the database without the need to save.

Why does the update need a post install script?

Are you telling me that the parameters in the manifest file are only needed on the first installation because in updates the new parameters have to be added anyway via post install script?
That seems absurd to me...maybe I misunderstood.

avatar chmst
chmst - comment - 9 Jan 2025

As @brianteeman says. This is the behaviour since many versions.
New fields should always have a default value, so the code works in any case.

avatar luX0r-reload
luX0r-reload - comment - 10 Jan 2025

In fact in the manifest I have the default values. Also for the new field.

<field
	name="com_convertformsform"
	type="radio"
	class="btn-group btn-group-yesno radio"
	default="1"
	label="PLG_SYSTEM_MYPLUGIN_OPTIONS_CONVERTFORMS_FORM_LABLE"
	description="PLG_SYSTEM_MYPLUGIN_OPTIONS_CONVERTFORMS_FORM_DESC">
	<option value="0">JOFF</option>
	<option value="1">JON</option>
</field>

When I do the plugin update, the new field should be entered into the database with the default value, as it is when I do the plugin installation the first time.

Do a post install script to insert the new field into the database?
In my opinion this is something that the plugin developer should not do but Joomla should do it by reading the manifest.

Anyway, I need to solve the problem quickly.

Can you point me to the Joomla documentation where it talks about using the post install script to update the fields on the database from the manifest?

avatar alikon alikon - change - 10 Jan 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-01-10 07:59:41
Closed_By alikon
avatar alikon alikon - close - 10 Jan 2025
avatar luX0r-reload
luX0r-reload - comment - 10 Jan 2025

Thank you, but I already know that document.
I have already done several install scripts.

I wanted to read the documentation it explicitly talks about updating fields from the manifest to the database via install script.

To do such an update script, I have to go through all the fields in the manifest and those on the database to see which ones already exist and which don't, and eventually add the new ones found on the manifest to the database.

I haven't found anything on the net and it continues to seem absurd to me that Joomla's system update doesn't take care of these things.

Is there any specific documentation on this?

Thanks in advance

Translated with DeepL.com (free version)

avatar Fedik
Fedik - comment - 10 Jan 2025

... the parameters in the manifest file are only needed on the first installation because in updates the new parameters have to be added anyway via post install script?

The parameters in manifest file is for plugin configuration form, they does not go in to database untill User push "Save" while editing the parameters of the plugin.

In fact in the manifest I have the default values. Also for the new field.

Make sure you also have default value when reading the parameter in the plugin code.
For your com_convertformsform example it going to be something like:

$myParameter = $this->params->get('com_convertformsform', 1);

Where 1 is default value.
Be aware that this approach does not allows User to save empty value, but for your example it should work fine.

avatar luX0r-reload
luX0r-reload - comment - 10 Jan 2025

The parameters in manifest file is for plugin configuration form, they does not go in to database untill User push "Save" while editing the parameters of the plugin.

No, when I install for the first time the plugin the parameters are stored with its default value in the params field of #__extensions table.
It is not clear because it works for the first install and it does not work for updates.
Would you know the answer to that?
Perhaps a Pull Request is appropriate for this.

Make sure you also have default value when reading the parameter in the plugin code.
For your com_convertformsform example it going to be something like:

I thank you for the suggestion, but I cannot apply it for my plugin, because I get the configuration parameters “dynamically”. It is not easy to explain without seeing the code, but it is so :-)
I could get the default parameters somehow from the manifest, though. We'll see...

avatar Fedik
Fedik - comment - 10 Jan 2025

No, when I install for the first time the plugin the parameters are stored with its default value in the params field of #__extensions table.

Hm, I see, I missed that

$this->extension->params = $this->parent->getParams();

Well, then I do not have good news for you, sorry.
As previous comments said, you have to use Install script
public function update(InstallerAdapter $parent) method, and run custom Query to update plugin params.

I do not have an example to share, maybe someone else can do that.

avatar luX0r-reload
luX0r-reload - comment - 10 Jan 2025

No matter, I solved it by implementing the update function in the install script, something that could be done directly in the framework's PluginAdapter.

Add a Comment

Login with GitHub to post a comment