Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Fix invalid json in params of com_templates after update to 4.3.0 or 4.3.1 caused by PR #38823 #40535

Conversation

richard67
Copy link
Member

@richard67 richard67 commented May 3, 2023

Pull Request for https://forum.joomla.org/viewtopic.php?f=808&p=3690614 (also reported on social media and at other places)

Summary of Changes

When updating from 3.10 or 4.x to 4.3.0 or later, and before the update the value of the params column of com_templates is an empty JSON {] in the #__extensions table in database, you get an error "error decoding JSON data: Syntax error" when you try to go to the template manager in backend.

This is caused by the update SQL script which was introduced with pull request (PR) #38823 , which produces invalid JSON for that special case.

Note that when you have an empty params for com_templates, the template manager is broken when using Joomla 4 with PHP 8.1. Details and fix see PR #40544 . But when you are coming from 3.10 or from 4.0 with PHP 7.4 you won't have noticed any problems with the template manager.

The issue fixed here is for a small part my fault because I have not noticed the problem when having an empty JSON params when having quickly reviewed that PR .

This PR here fixes this by 2 means:

  1. The SQL statement which has caused the problem is removed.
  2. The invalid JSON is fixed with a new update SQL script by replacing it by the values for new installations.

In addition it fixes a typo here, which also was introduced with PR #38823: https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_templates/tmpl/template/default.php#L152 . It should be 'SideBySide'.

The reason for fix number 1 is that we should modify JSON parameters only when there is the need to fix broken functionality, like it is e.g. here: https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_admin/sql/updates/mysql/4.1.0-2021-11-28.sql#L7 . This example is safe and does not do anything when having an empty JSON params.

But in case of PR #38823 it was not necessary, it was only nice to have the side-by-side view switched on after an update.

It's a different thing if we don't modify but completely replace the params value, like e.g. here: https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_admin/sql/updates/mysql/4.0.0-2021-05-30.sql#L3 .

But as said, with string replacement for JSON parts only we have to be careful and avoid that were we can.

The reason for fix number 2 is because when you have the problem, your template manager params were an empty JSON before that update which broke it.

So we could safely set the params to the values for new installations as obviously the params have never been saved in backend.

It would have been easier and maybe better to revert to an empty params value.

But as said before, the template manager is broken in Joomla 4 if you set the params of com_templates to an empty string or an empty json in the extensions table as we can do it safely with other components, see PR #40544 .

For the same reason and because the template manager is not really usable when there are not any allowed file name extensions, the SQL update script introduced with this PR sets the params not only for the broken JSON but also for an empty JSON and an empty string.

Testing Instructions

Test 1: Reproduce the issue

  1. On a 3.10.11 or current 3.10-dev branch, make a new installation.

  2. Set the params value to an empty JSON in database, e.g. with phpMyAdmin:

UPDATE `#__extensions` SET `params` = '{}' WHERE `name` = 'com_templates';
  1. Update to 4.3.1 or a current 4.3.2-dev nightly build.
    Result: See section "Actual result BEFORE applying this Pull Request" below.

Test 2: Test the fix for the issue

Proceed as described in the previous test "Test 1", but this time update to the patched package created by Drone for this PR.

You can find the update package or the custom update URL here:

https://ci.joomla.org/artifacts/joomla/joomla-cms/4.3-dev/40535/downloads/65417/

Result: See section "Expected result AFTER applying this Pull Request" below.

Test 3: Review the other change

Verify that the change here is correct: https://github.com/joomla/joomla-cms/pull/40535/files#diff-190cfe05a7ca67886b08e825520e05421b44ccd8d0bf048b55fc7165f187ea59R152

I.e. compare with the casing of the default value used here:
https://github.com/joomla/joomla-cms/blob/4.3-dev/administrator/components/com_templates/config.xml#L77
And here:
https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L174

Actual result BEFORE applying this Pull Request

Error "error decoding JSON data: Syntax error".

Further symptoms see https://forum.joomla.org/viewtopic.php?f=808&p=3690614 .

Expected result AFTER applying this Pull Request

No error "error decoding JSON data: Syntax error".

The params value of com_templates in the #__extensions table is equal to the value used for new installations e.g. here: https://github.com/joomla/joomla-cms/blob/4.3-dev/installation/sql/mysql/base.sql#L174 ,

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed

  • No documentation changes for manual.joomla.org needed

@richard67 richard67 changed the title [4.3] [WiP] Fix invalid json in params of com_templates after update to 4.3.0 or 4.3.1 cause by PR #38823 [4.3] [WiP] Fix invalid json in params of com_templates after update to 4.3.0 or 4.3.1 caused by PR #38823 May 3, 2023
@richard67 richard67 changed the title [4.3] [WiP] Fix invalid json in params of com_templates after update to 4.3.0 or 4.3.1 caused by PR #38823 [4.3] Fix invalid json in params of com_templates after update to 4.3.0 or 4.3.1 caused by PR #38823 May 5, 2023
@richard67 richard67 marked this pull request as ready for review May 5, 2023 12:02
@richard67 richard67 added the bug label May 5, 2023
@degobbis
Copy link
Contributor

degobbis commented May 7, 2023

I have tested this item ✅ successfully on e10d7d7

After the update the params remain empty {}


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@TheWhykiki
Copy link

I have tested this item ✅ successfully on e10d7d7

After update error is fixed. The column "params" in #__extensions -> com_template holds an empty JSON {}.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@richard67
Copy link
Member Author

@degobbis @TheWhykiki Sorry, my mistake. It should not be an empty JSON. I will provide a fix in a minute.

@richard67
Copy link
Member Author

@degobbis @TheWhykiki Could you test again with the latest changes? I've updated the link to the prebuilt packages in the description. The params should not be an empty JSON but the values used for a new installation. I've updated the expected result accordingly. Thanks in advance, and thanks for testing before.

@degobbis
Copy link
Contributor

degobbis commented May 7, 2023

I have tested this item 🔴 unsuccessfully on 1c85bb0

Tested again:
from 3.10.11 to this -> params are entered, all OK
from 4.3.1 with json Error (params in DB = {,"difference":"SideBySide"}) to this, not possible

Testet with Updateserver URL and both packages.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@TheWhykiki
Copy link

I have tested this item 🔴 unsuccessfully on 1c85bb0

Can confirm @degobbis :

from 3.10.11 to this -> params are entered, all OK
from 4.3.1 with json Error (params in DB = {,"difference":"SideBySide"}) to this, not possible

Testet with Updateserver URL and both packages.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@richard67
Copy link
Member Author

from 4.3.1 with json Error (params in DB = {,"difference":"SideBySide"}) to this, not possible

@degobbis @TheWhykiki There is nothing I can change on that. When people have the invalid JSON after an update from 3.10, the update component will not work anymore. They have to apply the SQL change manually to fix their broken installation. It might need an FAQ document for that. This PR here can only fix make it not happen anymore when updating from 3.10.

@degobbis
Copy link
Contributor

degobbis commented May 7, 2023

I have tested this item ✅ successfully on 1c85bb0

OK, then I can confirm:

from 3.10.11 to this -> params are entered, all OK

PS: it would be enough to simply save the options in the configuration for templates again


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@richard67
Copy link
Member Author

PS: it would be enough to simply save the options in the configuration for templates again

@degobbis Not really, because when you have the problem with the invalid JSON you can't go to the template manager anymore to save the options.

@TheWhykiki
Copy link

I have tested this item ✅ successfully on 1c85bb0

I can also confirm:

from 3.10.11 to this -> params are entered, all OK


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@richard67
Copy link
Member Author

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40535.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label May 7, 2023
@obuisard obuisard added this to the Joomla! 4.3.2 milestone May 7, 2023
@obuisard obuisard merged commit 5a90e3e into joomla:4.3-dev May 7, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 7, 2023
@obuisard
Copy link
Contributor

obuisard commented May 7, 2023

Thank you for the fix Richard @richard67. And thank you for the extended explanations, it really helped understand the issue at hand. Also, thank for the comments in the code, it will help keep a trace of the issue.

@richard67 richard67 deleted the 4.3-dev-fix-invalid-json-params-from-pr-38823 branch May 7, 2023 19:39
@richard67
Copy link
Member Author

Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants