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

Fix comparing arrays with entity references #1237

Closed
wants to merge 3 commits into from

Conversation

boudewijn-zicht
Copy link
Contributor

@boudewijn-zicht boudewijn-zicht commented Feb 13, 2023

When the values are empty arrays we do NOT use Hash::check because that will always return false, hence even when both values are empty arrays the result will still be that the values are different and have to be imported

Fixes #1238

When the values are arrays filled with numbers then they most likely represent references to elements.
Unfortunately these arrays sometimes have non-matching keys, while the values are the same, i.e. reference
the same elements.  In this case, we should determine that the values are the same.
@angrybrad
Copy link
Member

@boudewijn-zicht not sure i'm following this one - could you give an example of the two types of arrays that are being compared here?

ids as "most likely elements" feels a bit weird, too - are there cases where they are legitimate, non-element-id integers?

@boudewijn-zicht
Copy link
Contributor Author

@boudewijn-zicht not sure i'm following this one - could you give an example of the two types of arrays that are being compared here?

ids as "most likely elements" feels a bit weird, too - are there cases where they are legitimate, non-element-id integers?

I will try to clarify with an example:

  1. your Craft installation has two sections, 'Page' and 'Item'. The page has an element field 'Items', i.e. a page can have multiple items.
  2. When you import pages you can also import these relations (i.e. using the item title or whatever).
  3. The import tries to see if a page already has the item relations that it is trying to import/update by comparing $firstValue and $secondValue.
  4. These values are numbers, presumably the element ids of the Items
  5. Unfortunately $firstValue and $secondValue have keys that do not match, i.e. one may be [0=>123, 1=>456] and the other might be [0=123, 2=>456].

This PR checks that all values in both $firstValue and $secondValue are numbers and then normalizes their keys to ensure that the comparison results in 'yes, they are the same'.

@angrybrad
Copy link
Member

angrybrad commented Mar 16, 2023

Resolved in 9c272ab

@angrybrad angrybrad closed this Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants