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

feed-me 4.4.1 breaks import of entries with assets #1067

Closed
dgsiegel opened this issue Dec 6, 2021 · 5 comments
Closed

feed-me 4.4.1 breaks import of entries with assets #1067

dgsiegel opened this issue Dec 6, 2021 · 5 comments
Labels

Comments

@dgsiegel
Copy link

dgsiegel commented Dec 6, 2021

Description

This commit breaks import of entries with assets: 704d511

I have defined an import of entries in which assets are used. During the import, you'll get the following error message:

Error: mb_strlen(): Argument #1 ($string) must be of type string, array given - DataHelper.php: 319.

Looking at the passed variables, I can see that in fact an array is passed for $firstValue and $secondValue, e.g.

$key: "objectImages"
$firstValue:  ["49864"]
$secondValue:  ["49864"]

Steps to reproduce

  1. Create an import of entries
  2. Map a field to an asset field
  3. Import

Additional info

  • Craft CMS version: 3.7.24
  • Feed Me version: 4.4.1
  • PHP version: 8.0
@dgsiegel dgsiegel added the bug label Dec 6, 2021
@sparkalow
Copy link

I'm see the same issue unrelated to asset importing. The bug occurs for me when importing matrix or array data or anything other than simple strings.

The below in helpers/DataHelper.php is comparing string values with mb_strlen but the data sent to this method is not guaranteed to be a string.

 return Hash::check($fields, $key) && ($firstValue == $secondValue && mb_strlen($firstValue) === mb_strlen($secondValue));

@angrybrad
Copy link
Member

@sparkalow @dgsiegel

Can you vendor/craftcms/feed-me/src/helpers/DataHelper.php, find _compareSimpleValues, replace it with this and verify that fixes it for you?

private static function _compareSimpleValues($fields, $key, $firstValue, $secondValue): bool
{
    /** @noinspection TypeUnsafeComparisonInspection */
    // Should probably do a strict check, but doing this for backwards compatibility.
    if (Hash::check($fields, $key) && ($firstValue == $secondValue)) {
        // If this is a string, check the lengths
        if (is_string($firstValue) && is_string($secondValue)) {
            // String length comparison to take into account "637" and "0637"
            if (mb_strlen($firstValue) == mb_strlen($secondValue)) {
                return true;
            }

            return false;
        }

        // An array, but loosely equal
        return true;
    }

    // Didn't match
    return false;
}

@sparkalow
Copy link

@angrybrad I can confirm that fix works for my case.

angrybrad added a commit that referenced this issue Dec 7, 2021
Fixed a PHP error that could occur when importing some feeds.
@angrybrad
Copy link
Member

Thanks for the feedback... just cut a 4.4.1.1 release with this fix.

@green17
Copy link

green17 commented Dec 7, 2021

@angrybrad perfect thanks so much for the quick fix, I can confirm that works for us too.

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

4 participants