craftcms / feed-me

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

Feed Option "setEmptyValues" incompatible with boolean false, integer 0 and float 0.0 #1329

Closed ymilin closed 1 year ago

ymilin commented 1 year ago

Description

Due to the use of PHP empty(), the Feed Option setEmptyValues, when inactive, considers the the following values as empty:

I think the expected behavior for this feature is to only consider a value to be empty for empty strings and null. (If this assumption is wrong, we could at least add a note that empty values are checked with PHP's emtpy() method)

This is problematic for:

Here is where the check is made in the Process class:

https://github.com/craftcms/feed-me/blob/b0c9c9e25bb021876b37e25556e157f57d417de1/src/services/Process.php#LL398C9-L408C10

I'll gladly make a PR when/if we agree on a solution.

Steps to reproduce

  1. Create a mapping with setEmptyValues = 0
  2. Process a Feed that tries to update a boolean field (craft\fields\Lightswitch) from true to false
  3. The field value is ignored because it is considered empty in craft\feedme\services\Process on line 403

Additional info

bryantAXS commented 1 year ago

I'm running into this issue on Lightswitch fields. No way of setting true => false.

i-just commented 1 year ago

Hi, thanks for reporting! I raised a PR for this.

For the time being, if you use strings, the import should work as expected (e.g. "false" instead of false, "0.00" instead of 0.00)

angrybrad commented 1 year ago

Just released 5.1.4 with a fix for this! https://github.com/craftcms/feed-me/releases/tag/5.1.4

maxpdesign commented 10 months ago

Hi, we are still experiencing the same problem running Craft Pro 3.8.13 and Feed Me 4.7.0. Is it possible to also apply this fix for this version?