kaliop-uk / ezmigrationbundle

This bundle makes it easy to handle eZPlatform / eZPublish5 content upgrades/migrations
GNU General Public License v2.0
53 stars 81 forks source link

ezMatrix parsing problem #250

Closed Rikkers closed 1 year ago

Rikkers commented 2 years ago

Hello,

When running migration containing ezmatrix field, it crashes with

Migration failed! Reason: Error in execution of step 1: Notice: Array to string conversion in file /var/www/vendor/ezsystems/ez-matrix-bundle/FieldType/Matrix/Row.php line 49

Migration that was launched:

-
    type: content
    mode: create
    content_type: shop_settings
    priority: 0
    is_hidden: false
    sort_field: published
    sort_order: DESC
    parent_location: eide_shop_settings_folder
    location_remote_id: eide_shop_settings
    section: 13
    object_states: {  }
    lang: nor-NO
    owner: 14
    always_available: false
    attributes:
        name: 'Shop-Settings Eideforlag'
        delivery_cost_matrix:
            rows:
                - { delivery_country: 'NO', free_freight: 'Yes', delivery_sku: '9789999999991', price: '36', price_inc_vat: '45', vat_group: '1', weight_from: '0', weight_to: '999999999', desc_short: 'Porto Norge', desc: 'Porto Norge', code: norge }
                - { delivery_country: EU, free_freight: '', delivery_sku: '9789999999984', price: '400', price_inc_vat: '500', vat_group: '1', weight_from: '0', weight_to: '999999999', desc_short: 'Porto Utland EU', desc: 'Porto Utland EU', code: utland }
                - { delivery_country: WORLD, free_freight: '', delivery_sku: '9789999999984', price: '800', price_inc_vat: '1000', vat_group: '1', weight_from: '0', weight_to: '999999999', desc_short: 'Porto Utland World', desc: 'Porto Utland World', code: world }
            columns:
                - { id: delivery_country, name: 'Delivery country (Code)', num: '0' }
                - { id: free_freight, name: 'Free freight (Voucher/Discount)', num: '1' }
                - { id: delivery_sku, name: 'ERP SKU', num: '2' }
                - { id: price, name: 'Price without VAT', num: '3' }
                - { id: price_inc_vat, name: 'Price including VAT', num: '4' }
                - { id: vat_group, name: 'VAT Group ', num: '5' }
                - { id: weight_from, name: 'Weigth in gr from', num: '6' }
                - { id: weight_to, name: 'Weigth in gr to', num: '7' }
                - { id: desc_short, name: 'Description short', num: '8' }
                - { id: desc, name: 'Description overviewpage ', num: '9' }
                - { id: code, name: Code, num: '10' }
        vat_matrix:
            rows:
                - { country: 'NO', vat_group: '1', vat: '25' }
            columns:
                - { id: country, name: Country, num: '0' }
                - { id: vat_group, name: 'VAT Group', num: '1' }
                - { id: vat, name: 'Vat in %', num: '2' }
        free_freight:
            rows: {  }
            columns:
                - { id: country, name: Country, num: '0' }
                - { id: free_freight_limit, name: 'Free freight in local currency', num: '1' }

This migration worked fine on PHP 7.3 and kaliop/ezmigrationbundle 5.11.0

Now running on PHP 7.4, ezplatform with ezsystems/ezpublish-kernel v7.5.10, kaliop/ezmigrationbundle 5.5.12 (but I see ezmatrix field handler on dev-master looks the same), ezsystems/ez-matrix-bundle dev-master

From my personal "investigation", it looks like EzMatrix field handler has some issue in hashToFieldValue i.e. part for legacy field type should look like this:

if ($this->usingLegacyFieldType()) {
    $rows = $columns = array();
    foreach($fieldValue['rows'] as $data) {
        $rows[] = new \EzSystems\MatrixBundle\FieldType\Matrix\Row($data);
    }
    foreach($fieldValue['columns'] as $data) {
        $columns[] = new \EzSystems\MatrixBundle\FieldType\Matrix\Column($data);
    }
    return new \EzSystems\MatrixBundle\FieldType\Matrix\Value($rows, $columns);
}

Probably fieldValueToHash would have to be updated, as migration generation of a content containing ezmatrix also fails

gggeek commented 1 year ago

I will take a look. Tbh i find your migration slightly surprising:

My first step will be to check what we get when having the bundle generate a content-type-create and a content-create migrations...

gggeek commented 1 year ago

I think I see what might be going on: on 17/11/2020, I added to the codebase "proper" support for the eZMatrix fieldType, which includes a uniform syntax for content/create - content/update yaml, and works across both the two different bundles implementing ezmatrix (the community and ee ones). That code was first released as part of 5.14.0.

Your migration's yml did work with older versions, but I never tested it properly, nor intended to support it - it just leaves it up to the eZ kernel to transform the array data into Value objects, and as such is not as stable/portable (because of the unfortunate situation with the two bundles).

I think a good way to improve the current situation is to

gggeek commented 1 year ago

More updates (all of the changes will be in upcoming version 6.1):

gggeek commented 1 year ago

Closing as 6.1 has been released. Feel free to open a new ticket if there are still issues

dawidpierzchalski commented 1 year ago

Seems currently it works fine. Thanks.