Closed artfulrobot closed 3 years ago
Count me in on the "love this" side, definitely thought about doing something similar before. Thanks! 🙇
I agree with the idea, and we do that, too. (We just wrap it in a transaction and roll back if the a new contact has been created, i.e. if the returned contact ID is greater than the previous max contact ID.
What I don't like about this, is that it breaks the "contract" with the API, which is: you'll get a contact ID no matter what.
How do you feel about putting this into a different API action, like match
? It could still use the same engine/code, but it's much clearer from the outside point of view.
@bjendres I don't mind a separate Action, but for the sake of discussion:
I don't see it is breaking the contract because it throws an exception if it can't fulfill it. That's a standard contract get-out. You still always get a contact ID back - if you get anything back.
Also match
isn't quite right because it may alter data and match
sounds like a read only operation. I suppose a separate action could be getexisting
if you feel strongly?
I think if it were a separate action then I'd be tempted to go the whole way and do a Contact.createifnotexists
which might have the match_only
param, as in this PR, but would return something different to the normal method: it would return:
contact_id
(integer or NULL if match_only
failed; no exception thrown)new
(0 means nope, contact was found, 1 means yep, contact had to be created)I've often needed to know if the contact was newly created.
Thoughts?
I don't see it is breaking the contract because it throws an exception if it can't fulfill it. That's a standard contract get-out. You still always get a contact ID back - if you get anything back.
You do have a point there. I still think it's clearer to have a separate API - but if you don't think it's worth it, that's also ok.
Also
match
isn't quite right because it may alter data andmatch
sounds like a read only operation. I suppose a separate action could begetexisting
if you feel strongly?
Sounds great.
I think if it were a separate action then I'd be tempted to go the whole way and do a
Contact.createifnotexists
which might have thematch_only
param, as in this PR, but would return something different to the normal method [...]
That also sounds good, go ahead! Thanks!
Closing in favour of https://github.com/systopia/de.systopia.xcm/pull/75
Well, you're either going to love this or reject it outright!
I have often wanted to harness the power and configuration of XCM to see if we can find a contact, but if not, take some action other than creating a contact.
This PR adds a
match_only
parameter. See README diff for explanation.Example use-case: I have names and three possible emails for a contact, and maybe an address. I want to use XCM to find the person given the first email, but if it fails, I want to try the other emails before giving up and creating a contact.