Patch attached with rules action "crm_core_user_sync_contact":
* takes a user argument (required) and contact (optional)
* creates a new CRM Contact if it was not supplied
* creates the relation object to sync the two

It's working ok for me on a few dev sites, but haven't tested yet in production.

Related to #2206859: Creating a user from CRM Contact?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

RoSk0’s picture

Status: Needs review » Needs work
  1. +++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
    @@ -0,0 +1,74 @@
    + * Implements hook_rules_action_info()
    

    Need a dot at the end.

  2. +++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
    @@ -0,0 +1,74 @@
    +    // If contact already exists for this account, ignore whatever input is given.
    

    If contact already exists we should load relation and return both.

  3. +++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
    @@ -0,0 +1,74 @@
    +  $contact->uid = $account->uid;
    

    We should save contact after this.

Patch needs to be restructured and created following Drupal coding standards.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
2.91 KB

Patch re-rolled with one change.

+++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
@@ -0,0 +1,74 @@
+ * Implements hook_rules_action_info()

Need a dot at the end.

Dot added

+++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
@@ -0,0 +1,74 @@
+    // If contact already exists for this account, ignore whatever input is given.

If contact already exists we should load relation and return both.

Yes, I guess we need to deal with an existing contact ... somehow.
If a contact is given as an argument to this action, we cannot just ignore it.
There's no "merge entity" mechanism that I know about - any ideas?

+++ crm_core/modules/crm_core_user_sync/crm_core_user_sync.rules.inc	(revision 122)
@@ -0,0 +1,74 @@
+  $contact->uid = $account->uid;

We should save contact after this.

I disagree here. In general when rules returns a new or existing entity, it's up to the rule builder to add the "entity_save" action. If the rule builder has more work to do on the new entity, it's much more efficient to wait until the work is done before saving. This is how node and user actions work, as well as other entity types, so that's how I've modeled this action.

AaronBauman’s picture

correct patch, wrong name.
renamed and re-uploaded

RoSk0’s picture

Status: Needs review » Needs work

Still brakes coding standards.

Please refer to Coding standards.
I would recommend using Helper Modules.

grahl’s picture

Status: Needs work » Closed (outdated)

Closing outdated issue, please reopen if still relevant.