Language import broken #749

Closed
opened 2021-05-20 08:12:40 +00:00 by TLWebdesign · 3 comments
TLWebdesign commented 2021-05-20 08:12:40 +00:00 (Migrated from github.com)

Steps to reproduce the issue

  • Turn on E-mail Helper Class in the component settings
  • Export language strings of this component
  • Import the same file again.

Expected result

Language strings updated

Actual result

Installation 1:
1062 Duplicate entry '299' for key 'PRIMARY'
Installation 2:
1062 Duplicate entry '512' for key 'PRIMARY'

System information (as much as possible)

  • OS Name & Version:
  • MySql Version: 5.5.5-10.3.29-MariaDB & 5.5.5-10.4.18-MariaDB
  • Apache Version:
  • PHP Version: 7.4 and 7.3
  • Joomla Version: 3.9.27
  • JCB Version: 2.12.9 & second installation i tried it on is staging branch from 19th may 17:20
  • Browser: Safari

Additional comments

I just set up a local environment with mamp pro and default JCB installation and the import worked fine. When i installed my components package and then did the import of the file again it gave me the same duplicate entry 512 altho i'm importing a different file here.

### Steps to reproduce the issue - Turn on E-mail Helper Class in the component settings - Export language strings of this component - Import the same file again. ### Expected result Language strings updated ### Actual result Installation 1: 1062 Duplicate entry '299' for key 'PRIMARY' Installation 2: 1062 Duplicate entry '512' for key 'PRIMARY' ### System information (as much as possible) - OS Name & Version: - MySql Version: 5.5.5-10.3.29-MariaDB & 5.5.5-10.4.18-MariaDB - Apache Version: - PHP Version: 7.4 and 7.3 - Joomla Version: 3.9.27 - JCB Version: 2.12.9 & second installation i tried it on is staging branch from 19th may 17:20 - Browser: Safari ### Additional comments I just set up a local environment with mamp pro and default JCB installation and the import worked fine. When i installed my components package and then did the import of the file again it gave me the same duplicate entry 512 altho i'm importing a different file here.
TLWebdesign commented 2021-05-20 11:10:47 +00:00 (Migrated from github.com)

I'm updating with my conclusion:

When there is an int in the source column the script won't find the record and will try to add it although the record already exists.
NOTE: a language string with just an int gets added when you enable the mailer helper function. a language string with value "25" gets added then.

Here is where it breaks:
d5482d65cb/admin/models/import_language_translations.php (L511)

on the checkString method : ComponentbuilderHelper::checkString($row[$source_key])

When i cast $row[$source_key] to string it works as you'd expect.

A second seperate problem i found is with the language string about DKIM when you add the mailer helper method.

<p>Using the below details, you need to configure your DNS by adding a TXT record on your domain: <b><span id='a_dkim_domain'></span></b></p>
<script>
jQuery(document).ready(function()
{
	// house cleaning
        if( !jQuery('#jform_dkim_domain').val() ) {
            jQuery('#jform_dkim_domain').val(window.location.hostname);
        }
        jQuery('#jform_dkim_key').click(function(){
            jQuery(this).select();
        });
        jQuery('#jform_dkim_value').click(function(){
            jQuery(this).select();
        });
        vdm_dkim();
});

function vdm_dkim() {
        jQuery('#a_dkim_domain').text(jQuery('#jform_dkim_domain').val());
	jQuery('#jform_dkim_key').val(jQuery('#jform_dkim_selector').val() + '._domainkey');
	if( !jQuery('#jform_dkim_public_key').val() ) {
	        jQuery('#jform_dkim_value').val('v=DKIM1;k=rsa;g=*;s=email;h=sha1;t=s;p=PUBLICKEY');
        } else {
	        jQuery('#jform_dkim_value').val('v=DKIM1;k=rsa;g=*;s=email;h=sha1;t=s;p=' + jQuery('#jform_dkim_public_key').val());
        }
}
</script>

This code doesn't get translated correctly by PHPSpreadsheet in the model where the$data['array'] is created:
d5482d65cb/admin/models/import_language_translations.php (L445)

When i vardump the line of the row that contains the above mentioned language string it only returns this:

array(8) {
  ["A"]=>
  int(323)
  ["B"]=>
  string(1055) "
Using the below details, you need to configure your DNS by adding a TXT record on your domain: 


"
  ["C"]=>
  NULL
  ["D"]=>
  NULL
  ["E"]=>
  NULL
  ["F"]=>
  NULL
  ["G"]=>
  NULL
  ["H"]=>
  NULL
}
I'm updating with my conclusion: When there is an int in the source column the script won't find the record and will try to add it although the record already exists. NOTE: a language string with just an int gets added when you enable the mailer helper function. a language string with value "25" gets added then. Here is where it breaks: https://github.com/vdm-io/Joomla-Component-Builder/blob/d5482d65cb1df921d2e1aeada4bd0894c5825e0d/admin/models/import_language_translations.php#L511 on the checkString method : ComponentbuilderHelper::checkString($row[$source_key]) When i cast $row[$source_key] to string it works as you'd expect. A second seperate problem i found is with the language string about DKIM when you add the mailer helper method. ``` <p>Using the below details, you need to configure your DNS by adding a TXT record on your domain: <b><span id='a_dkim_domain'></span></b></p> <script> jQuery(document).ready(function() { // house cleaning if( !jQuery('#jform_dkim_domain').val() ) { jQuery('#jform_dkim_domain').val(window.location.hostname); } jQuery('#jform_dkim_key').click(function(){ jQuery(this).select(); }); jQuery('#jform_dkim_value').click(function(){ jQuery(this).select(); }); vdm_dkim(); }); function vdm_dkim() { jQuery('#a_dkim_domain').text(jQuery('#jform_dkim_domain').val()); jQuery('#jform_dkim_key').val(jQuery('#jform_dkim_selector').val() + '._domainkey'); if( !jQuery('#jform_dkim_public_key').val() ) { jQuery('#jform_dkim_value').val('v=DKIM1;k=rsa;g=*;s=email;h=sha1;t=s;p=PUBLICKEY'); } else { jQuery('#jform_dkim_value').val('v=DKIM1;k=rsa;g=*;s=email;h=sha1;t=s;p=' + jQuery('#jform_dkim_public_key').val()); } } </script> ``` This code doesn't get translated correctly by PHPSpreadsheet in the model where the$data['array'] is created: https://github.com/vdm-io/Joomla-Component-Builder/blob/d5482d65cb1df921d2e1aeada4bd0894c5825e0d/admin/models/import_language_translations.php#L445 When i vardump the line of the row that contains the above mentioned language string it only returns this: ``` array(8) { ["A"]=> int(323) ["B"]=> string(1055) " Using the below details, you need to configure your DNS by adding a TXT record on your domain: " ["C"]=> NULL ["D"]=> NULL ["E"]=> NULL ["F"]=> NULL ["G"]=> NULL ["H"]=> NULL } ```

About the bad practice JS in the translation string, I can only say 😏

We should remove this, and add a custom field to load the JS, this will be best practice.

As for the number being added, wow I have never had this issue... I will look into that part to see what can be done.

Making the import function more resilient is good, so we can do a little more to catch these kind of edge cases.

About the **bad** practice JS in the translation string, I can only say :smirk: We should remove this, and add a custom field to load the JS, this will be best practice. As for the number being added, wow I have never had this issue... I will look into that part to see what can be done. Making the import function more resilient is good, so we can do a little more to catch these kind of edge cases.
TLWebdesign commented 2021-05-21 12:54:25 +00:00 (Migrated from github.com)

Awesome. do you want me to test it without the JS in that string to make sure it works?

Awesome. do you want me to test it without the JS in that string to make sure it works?
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#749
No description provided.