Page MenuHomeIn-Portal Phabricator

INP-1817 - Change engine for storing export user presets
ClosedPublic

Authored by erik on Jul 4 2022, 12:57 PM.

Details

Summary

changed export user presets emgine

Test Plan

Plan for an upgrade

IMPORTANT: It's fine to ignore Admin Skin patching error, that happens on CentOS with SeLinux enabled only.
  1. Install 5.2.2-B1 version
  2. Login as administrative user to the adm.console
  3. Go to E-CommerceOrders section, Search tab
  4. Press Export button it the toolbar
  5. Move first 7 fields from "Available Columns" to "Export Columns"
  6. Check "Save/Update Export Preset" checkbox
  7. Input "7 fields" in the "Export Preset Title" field
  8. Input "test" in the "Export Filename" field
  9. Press "Save" button in toolbar
  10. Close "Orders Export" window
  11. Press Export button it the toolbar, confirm that "7 fields" preset exists in the "Export Preset" dropdown
  12. Upgrade to 5.2.2-B3 version
  13. Login as administrative user to the adm.console
  14. Go to E-CommerceOrders section, Search tab
  15. Press Export button it the toolbar, confirm that "7 fields" preset exists in the "Export Preset" dropdown
  16. Select "7 fields" preset exists in the "Export Preset" dropdown
  17. Press "Delete" button
  18. Close "Orders Export" window
  19. Press Export button it the toolbar, confirm that "7 fields" preset is removed from "Export Preset" dropdown

Plan for a clean install

IMPORTANT: To overcome SQL error in Products table escape Virtual field/index name (3 places) in the modules/in-commerce/install/install_schema.sql file by applying D403.
  1. Install 5.2.2-B3 version
  2. Login as administrative user to the adm.console
  3. Go to E-CommerceOrders section, Search tab
  4. Press Export button it the toolbar
  5. Move first 7 fields from "Available Columns" to "Export Columns"
  6. Check "Save/Update Export Preset" checkbox
  7. Input "7 fields" in the "Export Preset Title" field
  8. Input "test" in the "Export Filename" field
  9. Press "Save" button in toolbar
  10. Close "Orders Export" window
  11. Press Export button it the toolbar, confirm that "7 fields" preset exists in the "Export Preset" dropdown
  12. Testing removal:
    • select export preset
    • press delete button next to preset name
    • confirm, the removal in the dialog that is shown
    • confirm, that preset was removed
    • close "Orders Export" window
    • press Export button it the toolbar
    • confirm, that previously removed preset is absent

Plan for a reinstall

  1. open .../core/install.php URL in the web browser (the "..." is replaced with In-Portal base URL)
  2. select Reinstall In-Portal option and type user/password of the root user
  3. press Continue button
  4. proceed until you've reached Step 5 - Database Configuration step
  5. confirm, that all In-Portal related tables from the database were removed

Diff Detail

Repository
rINP In-Portal
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

erik created this revision.Jul 4 2022, 12:57 PM
erik requested review of this revision.Jul 4 2022, 12:57 PM
alex requested changes to this revision.Jul 4 2022, 3:07 PM
alex added inline comments.
core/install/install_schema.sql
1435 ↗(On Diff #1039)

delete

1440 ↗(On Diff #1039)

make this a primary key instead of the Id column


usage of REPLACE SQL in this table will result in a constant Id field increase

1441 ↗(On Diff #1039)

delete

core/install/upgrades.php
2371–2399 ↗(On Diff #1039)
  1. please extract this into a new migrateExportUserPresets protected method
  2. call this only, when $mode === 'after

this is also a 3rd mode and we need migration to be executed only once during an upgrade

modules/in-commerce/admin_templates/orders/export/export.tpl
113 ↗(On Diff #1039)

Is the code populating/using the delete_preset_name hidden field needed at all?


I've noticed, that the OnDeleteExportPreset event should get all form data anyway and can extract chosen export user preset name from there.

123 ↗(On Diff #1039)

add condition to prevent removal of 1st option, which is empty in 100% cases

124 ↗(On Diff #1039)

if presets.remove(i); does the same, then use it instead

This revision now requires changes to proceed.Jul 4 2022, 3:07 PM
alex added inline comments.Jul 5 2022, 2:04 AM
core/install/install_schema.sql
1440 ↗(On Diff #1039)

Also reduce the length of columns used in the index (pick the length you think will work best considering possible data in these columns), because currently, this SQL ends with an error:

ERROR: Specified key was too long; max key length is 1000 bytes
alex added inline comments.Jul 5 2022, 3:34 AM
core/kernel/db/db_event_handler.php
3084–3088 ↗(On Diff #1039)

Please replace with:

$delete_preset_name = $this->Application->GetVar('delete_preset_name');

if ( !$delete_preset_name ) {
    return;
}
3093 ↗(On Diff #1039)

Please replace with:

'PresetName = ' . $this->Conn->qstr($delete_preset_name),
modules/in-commerce/admin_templates/orders/export/export.tpl
100–101 ↗(On Diff #1039)

delete this

112–128 ↗(On Diff #1039)

Replace this with jQuery $.post code:

$.post(
    '<inp2:m_Link template="index" no_amp="1" js_escape="1"/>',
    {
        'events[ord.export]': 'OnDeleteExportPreset',
        delete_preset_name: delete_preset_name
    },
    function () {
        presets = document.getElementById('<inp2:ord.export_InputName field="ExportPresets"/>');

        for ( var i = 0; i < presets.options.length; i++ ) {
            if ( presets.options[i].selected ) {
                presets.options[i].remove();
            }
        }

        presets.options[0].selected = true;
    }
);
113 ↗(On Diff #1039)

False alarm. My apologies.

While testing the code I figured out why this was needed.

123 ↗(On Diff #1039)

ignore this


I see, that added condition at the method beginning already covers this.

124 ↗(On Diff #1039)

ignore this


The PhpStorm doesn't like this code, so I guess it won't work as well.

erik updated this revision to Diff 1040.Jul 5 2022, 6:03 AM

Made all requested improvements

erik updated this revision to Diff 1041.Jul 5 2022, 10:01 AM

Changed install schema due Jenkins message - all primary key fields must be without null values

alex requested changes to this revision.Jul 6 2022, 3:25 AM

The 15. Press Export button it the toolbar, confirm that "7 fields" preset exists in the "Export Preset" dropdown step fails for me with this SQL error in the export popup:

RuntimeException: Table 'alex_inportal_upgrade.51x_ExportUserPresets' doesn't exist (1146)
SQL:
    SELECT PresetData, PresetName
    FROM 51x_ExportUserPresets
    WHERE (ItemPrefix = 'ord') AND (PortalUserId = 1)  in ...\core\kernel\utility\logger.php on line 916
This revision now requires changes to proceed.Jul 6 2022, 3:25 AM
alex edited the test plan for this revision. (Show Details)Jul 6 2022, 3:58 AM
erik updated this revision to Diff 1042.Jul 6 2022, 10:45 AM

Added missing table creation on in-portal upgrade

alex accepted this revision.Jul 8 2022, 3:04 AM
This revision is now accepted and ready to land.Jul 8 2022, 3:04 AM
alex edited the test plan for this revision. (Show Details)Jul 8 2022, 8:43 AM
This revision was landed with ongoing or failed builds.Nov 22 2023, 3:14 AM
This revision was automatically updated to reflect the committed changes.