Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default [Done 1.6.0] Insertion of an additional language does not copy existing category/prod

    For ZC1.54 there are new function calls to log admin activity scattered about the admin files.

    In languages.php there is one after the insertion of a new language.

    But, on the following line, the code uses the last insert id as the new language id to auto-populate the new categories and products texts. So now it's using the last insert of the admin activity log instead the languages table!

    So although the category/product descriptions are created, they are linked to a language id of "whatever" ("64" in my test case) and so never display any text.

    $db->Execute("insert into " . TABLE_LANGUAGES . "
    (name, code, image, directory, sort_order)
    values ('" . zen_db_input($name) . "', '" . zen_db_input($code) . "',
    '" . zen_db_input($image) . "', '" . zen_db_input($directory) . "',
    '" . zen_db_input($sort_order) . "')");
    zen_record_admin_activity('Language [' . $code . '] added', 'info');


    $insert_id = $db->Insert_ID();
    and subsequently

    while (!$categories->EOF) {
    $db->Execute("insert into " . TABLE_CATEGORIES_DESCRIPTION . "
    (categories_id, language_id, categories_name,
    categories_description)
    values ('" . (int)$categories->fields['categories_id'] . "', '" . (int)$insert_id . "',
    '" . zen_db_input($categories->fields['categories_name']) . "',
    '" . zen_db_input($categories->fields['categories_description']) . "')");
    $categories->MoveNext();
    }
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Insertion of an additional language does not copy existing category/product texts

    Correct.

    The solution is to reverse these 2 lines:

    /admin/languages.php, at line 30:
    Code:
              zen_record_admin_activity('Language [' . $code . '] added', 'info');
    
    
              $insert_id = $db->Insert_ID();
    becomes:
    Code:
              $insert_id = $db->Insert_ID();
    
              zen_record_admin_activity('Language [' . $code . '] added', 'info');
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jun 2008
    Location
    Bordeaux, France
    Posts
    69
    Plugin Contributions
    6

    Default Re: Insertion of an additional language does not copy existing category/product texts

    I confirm when installing a new language in ZC-v1.5.4-12302014, the language_id reported in order_status, category_description,... is incorrect. Need to publish a small 1.5.4 update as it is an annoying bug.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Insertion of an additional language does not copy existing category/product texts

    Quote Originally Posted by gob33 View Post
    I confirm when installing a new language in ZC-v1.5.4-12302014, the language_id reported in order_status, category_description,... is incorrect. Need to publish a small 1.5.4 update as it is an annoying bug.
    Does this problem occur after applying the fix posted above by Dr. Byte? Meaning, apply fix, install language, make purchase, does problem persist?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default Re: Insertion of an additional language does not copy existing category/product texts

    You cannot apply the fix and try again, you have to revert to the prior database backup, apply the fix and try again.

    As this sort of bug is pretty unexpected at this stage of the game I would imagine that people find this thread after the damage has been been done.
    So while its fine to sit on your high horse (as I usually do) and say, "ok just use the backup you did prior to installing the language" I think it also would be a good thing to offer an sql repair patch to put things back as they were prior to the faulty insert, if that is possible, for those that did not have a recent backup,
    or, probably easier, a patch to set the new language id everywhere to what it should be.

    Remember, for many people the additional language is not additional, its default and essential and this bug is a real show stopper.
    Last edited by torvista; 24 Jan 2015 at 11:01 PM.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  6. #6
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Insertion of an additional language does not copy existing category/product texts

    Quote Originally Posted by torvista View Post
    You cannot apply the fix and try again, you have to revert to the prior database backup, apply the fix and try again.

    As this sort of bug is pretty unexpected at this stage of the game I would imagine that people find this thread after the damage has been been done.
    So while its fine to sit on your high horse (as I usually do) and say, "ok just use the backup you did prior to installing the language" I think it also would be a good thing to offer an sql repair patch to put things back as they were prior to the faulty insert, if that is possible, for those that did not have a recent backup,
    or, probably easier, a patch to set the new language id everywhere to what it should be.

    Remember, for many people the additional language is not additional, its default and essential and this bug is a real show stopper.
    Agree, which is/should be the next step assuming that this thread was "found" in the sequence described... The poster was not clear about the condition of the code when the problem was identified, so was/am unsure if this is the same problem carried through or a new/unrelated problem.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Insertion of an additional language does not copy existing category/product texts

    REPAIR PATCH to CLEAN UP DAMAGED DATA
    Quote Originally Posted by torvista View Post
    I think it also would be a good thing to offer an sql repair patch
    I've considered 2 strategies for that:
    a) Fix the data to what it should have been. But, the downside to this is it that if someone has attempted multiple "adds", then there's junk left that can't be cleaned up so easily.
    b) Just remove anything that doesn't have a matching valid languages_id, and then remove the now-orphaned language entry, effectively resetting it to before any failed attempt to add a language.

    While I have a set of queries for the first one, I've opted for the second one as I think it's cleaner.

    Please test this on your various sites to confirm whether it resets the damage.
    It can be run in phpMyAdmin or the SQL Patch Tool:
    (Be sure to first select a valid language for your current Admin session, and NOT the one you're trying to delete/clean.)
    Code:
    DELETE FROM products_description where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM categories_description where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM meta_tags_products_description where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM meta_tags_categories_description where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM products_options where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM products_options_values where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM manufacturers_info where languages_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM orders_status where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM coupons_description where language_id not in (
    SELECT languages_id 
    FROM languages );
    DELETE FROM languages where languages_id not in (
    SELECT language_id
    FROM orders_status );
    ALTER TABLE languages AUTO_INCREMENT = 1;
    ... and then you can re-install the language you were wanting to install, after applying the patch from my previous post.
    Last edited by DrByte; 8 Feb 2015 at 08:46 PM. Reason: add the auto-increment reset, assuming MyISAM table
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,589
    Plugin Contributions
    30

    Default Re: Insertion of an additional language does not copy existing category/product texts

    This patch worked ok, comparing databases.

    1) Is there no way to reset the auto-increment on the languages table?
    Otherwise this will leave the languages ids as 1 and 3.

    2) I found one oddity in this.
    If you add the language eg. spanish then change the admin language to spanish, then run the sql patch, and re-add spanish, the product descriptions are not generated for the (now) 3rd id.
    So, make sure you are working in english in the admin.

    Best is to restore a backup of course!
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Insertion of an additional language does not copy existing category/product texts

    Good points.
    I've updated my post above with an ALTER TABLE for auto-increment and a note to choose a valid language before running it.

    The ALTER TABLE query is based on the assumption that you're using MyISAM format for the MySQL table (since that's what Zen Cart uses for that table by default). If you've changed the schema to use InnoDB instead, you'll need to change the 1 to the desired number since InnoDB can't autocalculate the next value. One could use a max() calculation too, but there's no need since there's a 0.00001% chance this is even relevant.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10
    Join Date
    Nov 2006
    Location
    Sapin
    Posts
    44
    Plugin Contributions
    0

    Default Re: Insertion of an additional language does not copy existing category/product texts

    Quote Originally Posted by DrByte View Post
    Good points.
    I've updated my post above with an ALTER TABLE for auto-increment and a note to choose a valid language before running it.

    The ALTER TABLE query is based on the assumption that you're using MyISAM format for the MySQL table (since that's what Zen Cart uses for that table by default). If you've changed the schema to use InnoDB instead, you'll need to change the 1 to the desired number since InnoDB can't autocalculate the next value. One could use a max() calculation too, but there's no need since there's a 0.00001% chance this is even relevant.
    thank you very much, it help me

 

 

Similar Threads

  1. Replies: 10
    Last Post: 30 Apr 2010, 04:46 PM
  2. Copy Products to Additional Category
    By pixelkitty in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 7 May 2007, 09:41 AM
  3. Replies: 4
    Last Post: 22 Sep 2006, 06:17 PM
  4. Replies: 3
    Last Post: 23 Jun 2006, 08:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR