craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
289 stars 139 forks source link

Translatable fields in Matrix are set for all languages. #1537

Open stefanfriedrich opened 1 month ago

stefanfriedrich commented 1 month ago

Description

When I have a translatable field in a matrix-block feed-me will overwrite the content of this field for all languages. When importing content to matrix-blocks, feed-me doesn't seem to check for the chosen target site. (Matrix-Block Propagation Method: "Save entries to all sites the owner element is saved in")

Steps to reproduce

  1. Create matrix field
  2. Add translatable field (e.g. text) to the matrix field
  3. Add feed-me jobs for the different languages
  4. Import content via job into the translatable field
  5. Field will be set for all languages and will overwrite content for other languages

Additional info

Logs from database:

Job for site=craftDe: {"Match existing element with data {"idorig":"65"}."} {"Existing element [#41] (https://craft.test/cmsadm/entries/sectionWebsite/41-freie-stellen?site=craftDe) found."} {"Data to update for matrixContent: {"new1":{"type":"headline","enabled":true,"collapsed":false,"fields":{"headline":"Freie Stellen"}}}."} {"Data ready to import {"title":"Freie Stellen","matrixContent":{"new1":{"type":"headline","enabled":true,"collapsed":false,"fields":{"headline":"Freie Stellen"}}},"idorig":"65","headline":"Freie Stellen"}."} {"Entry [#41] (https://craft.test/cmsadm/entries/sectionWebsite/41-freie-stellen?site=craftDe) updated successfully."}

Job for site=craftEn: {"Match existing element with data {"idorig":"65"}."} {"Existing element [#41] (https://craft.test/cmsadm/entries/sectionWebsite/41-freie-stellen?site=craftEn) found."} {"Data to update for matrixContent: {"new1":{"type":"headline","enabled":true,"collapsed":false,"fields":{"headline":"Vacancies"}}}."} {"Data ready to import {"title":"Vacancies","matrixContent":{"new1":{"type":"headline","enabled":true,"collapsed":false,"fields":{"headline":"Vacancies"}}},"idorig":"65","headline":"Vacancies"}."} {"Entry [#41] (https://craft.test/cmsadm/entries/sectionWebsite/41-freie-stellen?site=craftEn) updated successfully."}

Guess as matrix-blocks are more or less entries by itself they also have to be checked for siteId.

brandonkelly commented 2 weeks ago

This has come up a couple times before (#463, #634). It’s currently working as expected, as Feed Me doesn’t have a way of identifying existing nested Matrix entries. So it will wipe out all existing nested entries for the field on each import, and recreate them based on the import data.

The way to work around that is to set your Matrix field’s Propagation Method to “Only save entries to the site they were created in”, so only the current site’s entries get removed/recreated during the import.

That said, we’re going to look into making it possible to import nested entries directly via their own import job, via new “Field” and “Owner Element” entry import settings. That way you’ll be able to match incoming nested entry data against existing entries, and update them if they already exist, like any other entry import.

stefanfriedrich commented 2 weeks ago

Hmm. Is there no way to check for a site Id on a nested entry? As normal text fields do this?

brandonkelly commented 2 weeks ago

It already does only re-import the nested entries based on the site ID.

However, if the Matrix field’s propagation method is set to “Save blocks to all sites the owner element is saved in”, then all sites share the same set of nested entries. So when Feed Me deletes the existing nested entries so new ones can be imported, those nested entries will get deleted for all the sites they belong to.

Which is why the current solution here is that you change your propagation method to “Only save entries to the site they were created in”. Then, when Feed Me deletes the existing nested entries, it’s only deleting them for that one site, leaving the other sites’ nested entries in-tact.

stefanfriedrich commented 2 weeks ago

“Save blocks to all sites the owner element is saved in” would lead to: the user has to upload every picture, every cta, every not-translatable matrix field multiple times - for every language. Maybe I can import the data with “Save blocks to all sites the owner element is saved in” and switch it back to "Save entries to all sites the owner element is saved in" afterwards.