craftcms / feed-me

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

setEmptyValues causing DataHelper Error when off #1269

Closed alexrubin closed 1 year ago

alexrubin commented 1 year ago

Craft CMS: v4.4.5 FeedMe: v5.1.1.1

I'm receiving an error in the FeedMe logs: "Trying to access array offset on value of type null - DataHelper.php: 182" while trying to import a value that's "" (empty) while having setEmptyValues set to off for the Feed.

https://github.com/craftcms/feed-me/blob/ef158858e755fd6fadfa58402a02dfc12bfbb8ce/src/helpers/DataHelper.php#L182

// If setEmptyValues is enabled allow overwriting existing data
if ($feed !== null && $value === "" && $feed['setEmptyValues']) {
    return $value;
}

// If setEmptyValues is enabled allow overwriting existing data
if ($value === "" && $feed['setEmptyValues']) {
    return $value;
}

The following change resolved my import issue, though I don't have enough test data to confirm if there were unexpected cascading effects: (updated both conditionals since they both reference setEmptyValues though only 182 was needed to fix my import issue)

// If setEmptyValues is enabled allow overwriting existing data
if ($feed !== null && $value === "" && isset($feed['setEmptyValues']) && $feed['setEmptyValues']) {
    return $value;
}

// If setEmptyValues is enabled allow overwriting existing data
if ($value === "" && isset($feed['setEmptyValues']) && $feed['setEmptyValues']) {
    return $value;
}
angrybrad commented 1 year ago

Thanks for the report! Resolved in https://github.com/craftcms/feed-me/commit/ee9237f9d49a8e145a0762c3f0a4d206e0856a85