Follow-up to #2704023: Fix contact names created from a captured mail message
Problem/Motivation
Steps to reproduce:
1. Enable collect_demo
2. Go to admin/config/system/inmail/paste
3. "Load example" and click "Process email"
4. Repeat the step 3
5. You should get an exception: Recoverable fatal error: Object of class Drupal\Core\TypedData\Plugin\DataType\StringData could not be converted to string in drupal_schema_get_field_value() (line 229 of core/includes/schema.inc).
Proposed resolution
Add tests and ContactMatcher::updateContact()
method, so it handles contact updates properly.
From #21 of #2704023: Fix contact names created from a captured mail message:
As starting point, have a look at \Drupal\Core\Entity\ContentEntityStorageBase::hasFieldValueChanged and the equals method that uses there (except that we'll probably need more like a contains() method, we will need to do something like that I think to figure out if the field changed. But getting that right is going to be complicated and require a ton of test coverage.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff.txt | 15.58 KB | slashrsm |
#16 | 2708357_16.patch | 16.81 KB | slashrsm |
| |||
#12 | 2708357_12.patch | 4.44 KB | slashrsm |
| |||
#10 | contact_updates_are_not-2708357-10.patch | 4.55 KB | mbovan |
#9 | contact_updates_are_not-2708357-9.patch | 4.55 KB | mbovan |
Comments
Comment #2
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedComment #3
miro_dietikerHmm...
Raising to critical. Submitting the same mail twice is my standard test to see activity cumulating.
Now activity can not attach to existing contacts anymore.. :-O
I guess the code attached will trigger the bug.
Comment #5
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedTried to simplify and fix updateContact() as well as tests.
The bug should be fixed now... Tests fails are related to recently committed #2691491: Add name field to the contact entity
Comment #7
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedUpdated the tests with changes made in #2691491: Add name field to the contact entity
Comment #9
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedRerolled based on #12 in #2710733: Update contact matchers with name fields changes.
Comment #10
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedTested locally after #2710733: Update contact matchers with name fields changes was committed. Recreating/uploading for tests.
Comment #12
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedReroll. Will still fail.
Comment #13
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #14
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedRetested, seems to be passing and review-ready.
Comment #15
miro_dietikerYou skip change check and always save. And not as a new revision?
Now it's always updated and a revert no more possible by user...
We need to make it configurable if an update happens or not. And update should not be the default at all on match.
Comment #16
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedWhat about something like this? Also made update configurable.
There is another problem. Due to the structure of data that MailContactMatcher returns for name field will this type of fields always trigger change/save. We could improve this to some extent, but this could result in the loss of data when there will be existing data on name properties that matcher doesn't handle properly (all except give name). We could also hard code special check for name fields and only compare give name to determine if there was an update or not.
Comment #17
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedBy removing "continue" here aren't we getting into possibility to override user_uri (again) in the elseif?
I think we should add a test case when "update_contact" is FALSE, as of now it doesn't seem that we save a new contact when there is a match on existing one and updating is turned off.
Comment #18
miro_dietikerWhy should we create a new entity if update is disabled?
It just means we are not updating matching fields on the entity with values.
BTW independently of the matching values this, we should allow the matched entity to be connected with the User URI.
But we still match and connect the activity to the contact identified.