Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix content gets overwritten on import #463

Closed
filip-van-hoeckel opened this issue Feb 5, 2019 · 16 comments
Closed

Matrix content gets overwritten on import #463

filip-van-hoeckel opened this issue Feb 5, 2019 · 16 comments
Labels

Comments

@filip-van-hoeckel
Copy link

Description

When updating content in a Matrix field content gets overwritten

Steps to reproduce

  1. Import English content (posts) with a unique key so language versions can be matched, for all sites
  2. Import Dutch content, set to update, match with unique key to determine which post is corresponding translation
  3. All fields are correctly updated, except for the Matrix field: that gets overwritten

Additional info

  • Plugin version: 3.1.2
  • Craft version: 3.1.7
@low
Copy link
Contributor

low commented Jun 18, 2019

I seem to have the same issue: Matrix content gets overwritten for all sites/languages. Other fields work fine.

Craft 3.1.30, Feed Me 4.1.0.

@brandonkelly
Copy link
Member

This happens because Feed Me doesn’t have a way of matching your feed’s blocks with existing entry blocks, so it will always just delete the current entry blocks and recreate them with whatever’s in the feed.

You can work around that by enabling the “Manage blocks on a per-site basis” setting on your Matrix field (under “Advanced”), which will cause each site to have its own unique set of blocks. Then Feed Me will only delete the blocks assigned to the current site, replace them with the feed’s blocks.

We are considering adding a Unique Identifier setting for Matrix fields within the feed settings, which would give you a way of matching incoming blocks with existing ones.

@amityweb
Copy link

amityweb commented Jun 24, 2019

About this "so it will always just delete the current entry blocks and recreate them with whatever’s in the feed." - but can it not do that for just the group or the site importing into? Why does it do it for all sites? If I am importing content for say just German, why does it have to overwrite the field in all the other sites? Needs to only overwrite it for that site or group. If its only for the site, then that will be OK providing we can set the matrix block to translate per group.

@amityweb
Copy link

amityweb commented Jun 24, 2019

What happens if you set the matrix field as "Manage blocks on a per-site basis", import all the sites content, then disable "Manage blocks on a per-site basis"?

Because with this setting currently disabled, if I edit a block field that is translatable per group, it does maintain that content within the group sites only. So editing German does not update US. So I am curious what happens when its unchecked, do the blocks all link back up again but with the imported content kept (and therefore linked within each group as now)? Or will it delete all blocks from all sites and re-copy the default site blocks? If its the former then that may work.

Edit: Tried it but doesn't work. Once I switch back to not manage blocks on a per site basis, then edit and save an entry, that entry on every site turned the language I saved it in, even though on subsequent saves of that entry it did allow me to have different content. If only on that first save it did not copy across that content to all sites but just the group, and re-saved the content that was in there, then this process should work.

@brandonkelly
Copy link
Member

We just released Craft 3.2 RC1, which replace’s Matrix’s “Manage blocks on a per-site basis” setting with a new “Propagation Method” setting, with the following options:

  • Only save blocks to the site they were created in – same behavior as before, if “Manage blocks on a per-site basis” was enabled.
  • Save blocks to other sites in the same site group – when saving an entry, all of its blocks will be saved to any other sites that are in the same site group as the current site.
  • Save blocks to other sites with the same language – when saving an entry, all of its blocks will be saved to any other sites that have the same language.
  • Save blocks to all sites the owner element is saved in – same behavior as before, if “Manage blocks on a per-site basis” was not enabled.

I’m posting that here because it can serve as a workaround for this issue. For example if you set your Matrix field’s propagation method to “Save blocks to other sites with the same language”, and then import your English feed, only English sites will have their current blocks deleted, and new blocks created based on the feed. Other sites’ blocks will be left alone.

It’s not a complete fix for this issue, but it was a lot cleaner than the alternative Feed Me enhancements we are considering, so it’s a good first step.

@amityweb
Copy link

amityweb commented Jun 26, 2019

Thanks Brandon, I will give this a try and its a great step forward for matrix and multi-sites.

I am experiencing a few strange issues, which I guess may be due to the data I had already imported, and one of the issues prevents me deleting it to start again too. I will open a new Github thread on it here craftcms/cms#4450

therealpecus added a commit to therealpecus/feed-me that referenced this issue Nov 25, 2020
Add multi-site reference to issue craftcms#463
@urbantrout
Copy link
Contributor

I am using a similar setup. Except that I don't import anything into the matrix field. But on import all blocks inside the matrix field get deleted.

Here is what I would like to do:

  1. Import events via feed-me (daily import). The only fields I get from the external API are ID, title and date.
  2. Manually add content via Craft CMS matrix field (page builder)

An option to ignore the matrix field on import would be really nice!

@urbantrout
Copy link
Contributor

OMG. There is a config setting for this: skipUpdateFieldHandle

@urbantrout
Copy link
Contributor

Unfortunately this setting is used to not update the whole element. Not only a specific field…

@urbantrout
Copy link
Contributor

Maybe my PR helps…

@elivz
Copy link

elivz commented Dec 21, 2021

I just ran into this again. Used Feed Me to import some content into existing entries in secondary sites. We have a content-builder Matrix field set to "Only save blocks to the site they were created in" and I had all the Matrix fields set to "Don't Import" in my Feed Me import config. And that Matrix field was completely emptied for all the entries in the site was importing to.

Whether or not this is "expected" from a programmatic standpoint, it's definitely not what I would expect as a user – even one who is pretty familiar with Craft's internals. Seems like at the very least it would warrant a big red warning on the feed config page to avoid content loss.

@jamesmacwhite
Copy link
Contributor

The scenario where a matrix field is not mapped at all in a feed but each feed run nukes the matrix content entirely seems quite dangerous with no warning or prompt it will happen and the fact this has been open for several years with no resolution makes me sad.

Same as: #734.

@maxpdesign
Copy link

Any update on this? I am experiencing a similar issue as @jamesmacwhite describes. My matrix field gets nuked on import while it is not mapped. But it only happens if the matrix field contains a super table field.

@pdaleramirez
Copy link
Contributor

I will close this ticket because the original issue has been resolved. For the recent case, please refer to #734

@jamesmacwhite
Copy link
Contributor

And yet this issue has remained broken for years... It is very destructive with no warning and the docs don't make any mention to the fact unmapped matrix content can be completely nuked, no warning, no reference. I find that a bit irresponsible given how long both respective issues have been around.

Considering this is now first party plugin since taken over from Verbb. I have to say, its development has been worse, which is unfortunate.

@samlising
Copy link

Will there be a method in the future to import matrix block data by mapping to a unique identifier or handle in order to add language data to a matching element? Creating unique elements for each site ease the import process but increase the amount of work for creating matrix blocks manually. For example if a matrix block has a field for adding image assets and text in different languages, if in one language you add 10 images and need the same images in the other languages, a content manager would have to painfully add those 10 images for each language just to translate the text. This is extremely inefficient for sites that need to use the same matrix block for importing data and manually creating data.

Will this will be addressed or will it be an ongoing problem?

Thanks.
Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants