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

Issue with Feed Me Plugin in Craft CMS: Assets Not Deleting as Expected #1577

Open
DieterVanhove opened this issue Jan 20, 2025 · 5 comments
Labels

Comments

@DieterVanhove
Copy link

Description

I’m encountering an issue with the Feed Me plugin in Craft CMS, and I’m unsure if it's a mistake on my part or a potential bug. Here’s what’s happening:

Steps to reproduce

1.I have an entry that originally includes multiple assets (for example, 3 assets).
2. I then update the same entry, but this time with only 2 assets. These 2 new assets are different from the first 2 assets.
3. When I update the entry using my feed. The first 2 assets update correctly. However, the third asset, which should be deleted (since it's not part of the new feed), remains in the entry.

Additional info

  • Craft version: 4.8.9
  • PHP version: 8.2
  • Database driver & version: Mysql 5.7
  • Plugins & versions:
  • Feed Me: 5.4.0

It seems that the first 2 assets update correctly, but I’m not sure how to ensure the third asset gets removed as intended.

Does anyone know what might be causing this issue, or what I might be missing to ensure the third asset is deleted properly?

@DieterVanhove
Copy link
Author

Hi @engram-design,

Apologies for tagging you—I've noticed your "recent" work on this plugin, so I’m hoping you’re still maintaining it. I’ve found a solution to my problem and would love to know if it could be merged.

I’ve created a fork and made a commit.

The issue is with the EVENT_BEFORE_PROCESS_FEED event in craft\feedme\services\Process.php (line 133). The existingElements are set at that point, but there is no way to modify the query that deletes the asset entries.

I’ve updated the event to include the form element type and attributes, which will also apply any changes made to them.

One potential concern: I’ve changed the $feed from a FeedModel to an array, which could potentially cause issues for other users. However, since other events send an array of form attributes, I followed the same approach. From my testing, I haven’t encountered any problems with the added functionality for modifying the form attributes in EVENT_BEFORE_PROCESS_FEED.

Let me know what you think! I’m open to feedback or suggestions on how to improve this.

Thanks in advance!

@engram-design
Copy link
Contributor

If by "recent" you mean 6 years ago! I've not had anything to do with Feed Me since then.

Not sure if you're aware of the history of Feed Me, but it was originally from Verbb where I created it, but the Craft team took it over. As such, I'm not across the changes that've been made over the last 6 years, so I might not be best placed to answer things properly.

I don't see an issue with your changes at face value, but best to hassle the Craft team about it and ideally make a PR for it. I'm sure they'd be happy to accept it. But yes, changing the variable type for that event would be considered a breaking change.

@DieterVanhove
Copy link
Author

Hi Josh,

Apologies, I didn’t realize that! Thank you for the clarification and your feedback. I’ve gone ahead and created a PR (#1582).

Thanks again!

@i-just
Copy link
Contributor

i-just commented Feb 6, 2025

Hi, @DieterVanhove; I tested this issue against the latest version of Craft 4 (4.14.4) and Feed Me (5.9.0). If I have an entry with three image assets (let’s say with IDs 11,12,13), and I run a Feed Me import to switch the assets to ones with IDs 14 and 15, then after the feed has run, the updated entry only contains assets 14 and 15.

Can you please update to the latest CMS and Feed Me version and test if this issue still occurs for you?

@DieterVanhove
Copy link
Author

Hi @i-just,

Thanks for the follow-up!

What Element Type are you using? In my case, I used Entry as the Element Type. However, I realised I might have been using Feed Me incorrectly since it doesn’t seem to handle assets the way I expected when working directly with entries. (This way it doesn't seem to delete the assets that are missing)

To address this, I created a separate feed with Asset as the Element Type. While this does handle missing assets by deleting them, I also noticed it deletes all assets within the specified filesystem—even when they are imported into a specific folder.

That’s why I created the PR (#1582). The change allows me to define which existing elements are selected at the start of the process—specifically, to limit it by folder(s). This gives me more control over which assets are included. After uploading the assets, I then attach them to my entry as needed.

Maybe I’m missing a crucial part, but this approach was the only one that worked for me.
Please let me know if you need more information!

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

3 participants