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

Allow the use of loop in more parts of the migrations #182

Closed crevillo closed 4 years ago

crevillo commented 5 years ago

I know the title of this issue is not very clear, so let's try to explain it with a use case

so, i was trying something like

-
    type: loop
    repeat: 6
    steps:
        -
            mode: create
            type: content
            parent_location: location_success_cases_folder
            remote_id: success_case_[loop:iteration]
            lang: esl-ES
            content_type: 'success_cases'
            attributes:
                name: Caso [loop:iteration]
                title: faker:sentence(5)
                text: >
                    <?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
                    <para>faker:paragraphs(4)</para></section>
                success_case_header_image: faker:picture(null, 1280, 960)
                featured_text: >
                    <?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
                    <para>faker:sentence(5)</para></section>
                colour_combination: faker:numberBetween(0,3)

-
    type: content
    mode: update
    lang: esl-ES
    match:
        content_remote_id: the_other_content_remote_id
    attributes:
        success_cases_module:
            - success_case_1
            - success_case_2
            - success_case_3
            - success_case_4
            - success_case_5
            - success_case_6

but i looks is not possibe to use loop for the remote_id. executing this migration i have this error

Migration aborted! Reason: Error in execution of step 1: Cache key "ez-content-info-byRemoteId-success_case_[loop:iteration]" contains reserved characters {}()/\@: in file /var/www/html/project/ezpl
atform/vendor/symfony/symfony/src/Symfony/Component/Cache/CacheItem.php line 162

which makes me thing that loop:iteration is not parsed when setting the remote_id. am i right?

so, it's possible to do this in other way? or could be a good feature to add?

(obviously i could get rid of loop and just repeat the content create thing 6 times...)

Cheers

gggeek commented 5 years ago

The first idea that comes to my mind would be to have a reference:append migration step. so you could create a reference as empty array, and add one value to it at every step, the use it in the step where, outside of the loop, you update the content with the relation attribute.

Otoh I think that by using a content/load step, where you manage to load only the 6 contents you just created (by filtering on content type and parent location), you can already create the arary-valued ref that you need... (one nice extension to the current matching mechanism would be to allow to match using LIKE/REGEXP/LT/GT/NE in most places where we match using equality constraints)

crevillo commented 5 years ago

i was trying the content load option too, but i didn't manage to build the reference correctly. any example of that?

gggeek commented 5 years ago
-
    type: content
    mode: load
    match:
        contenttype_identifier: editor_user
    references_type: array
    references:
        -
            identifier: editor_user_ids
            attribute: content_id
crevillo commented 5 years ago

Oh! Missed the references_type part. Brilliant. Thanks!

P.s. do you know anything like 'sequence'? Example, i have a selection field with four options. What i would like with loop is assign 0,1,2,3,0,1 to that field. Is it possible?

gggeek commented 5 years ago

You can use loop to iterate over an array. Not sure I get exactly your new case though ;-)

crevillo commented 5 years ago

I'll explain it properly tomorrow. But what you suggest seems a good start...

gggeek commented 5 years ago

Any update?

gggeek commented 4 years ago

Ping @crevillo : you did not come back with the promised explanation. Is this still valid/relevant, or shall I close it ?

crevillo commented 4 years ago

Close it. I cant remember what was this for :)