CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • CiviCRM -> OG sync reverse sync
Pages: [1]

Author Topic: CiviCRM -> OG sync reverse sync  (Read 2663 times)

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
CiviCRM -> OG sync reverse sync
November 02, 2011, 03:18:35 pm
Just thought I'd share this small patch I've added to the module to help with reverse sync:

Apologies for putting it in quote tags instead of code; the code tags won't let me post as it thinks I'm trying to post an external hyperlink??

Quote
function _civicrm_og_user_sync($users) {
        civicrm_initialize();
        require_once 'api/api.php';
        require_once 'api/v2/UFGroup.php';
        foreach ($users as $uid) {
                $account = user_load($uid);
                if(isset($account->uid)) {
                //find the contact record
                $contact = civicrm_uf_match_id_get( $account->uid );
                if(empty($contact)) continue;

                //Get the groups that this user is a member of
                $params = array('version' => 3, 'contact_id' => $contact);
                $groups = civicrm_api('GroupContact', 'Get', $params);
                foreach ($groups['values'] as $group) {
                        require_once 'CRM/Bridge/OG/Utils.php';
                        $group_id = $group['group_id'];
                        while($group_id) {
                        $gid = CRM_Bridge_OG_Utils::ogID ($group_id, false);
                        $is_admin = 0;
                        if ($gid) {
                                $og = og_load($gid);
                                og_group($gid, array('entity'=>$account));
                        }
                        $parent = civicrm_api('GroupNesting', 'Get', array('version' => 3, 'child_group_id' => $group_id));
                        $group_id = $parent['values'][$parent['id']]['parent_group_id'];
                        }
                }
        }
        }
}

function civicrm_og_sync_user_operations() {
        return array(
                'og sync' => array(
                        'label' => t('Sync the selected users OGs'),
                        'callback' => '_civicrm_og_user_sync',
                ),
        );
}

function civicrm_og_sync_user_insert(&$edit, $account, $category) {
        _civicrm_og_user_sync(array($account->uid));
}

« Last Edit: November 04, 2011, 03:24:45 pm by jcasharpe »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM -> OG sync reverse sync
November 02, 2011, 06:03:46 pm

can you attach your changes as a patch file rather than the entire file. Makes it a lot easier to see what u changed

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: CiviCRM -> OG sync reverse sync
November 04, 2011, 03:27:06 pm
Apologies I realised I'd posted the wrong functions - I've updated it with the correct code now.
All the code I've posted is new code to add to the civicrm_og_sync module so I didn't bother with a patch.

The patch adds an option to the user page to sync a given user with the OGs that civi believes the user belongs to. Also likewise when a new user registers it will add them to the groups that civi thinks the user is in.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: CiviCRM -> OG sync reverse sync
November 08, 2011, 05:02:11 pm
Hi - was there meant to be some code with the above or am i looking in the wrong place - or is it the code in the first item?

And did you do anything else to reverse the synch other than adding the above?
« Last Edit: November 08, 2011, 05:14:32 pm by petednz »
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 12:01:05 pm
The code is in the first post, I modified it to be the correct code.

Other than the existing code in CiviCRM 4.0.7, no I didn't do anything else.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 12:37:45 pm
thanks j

maybe you can help me confirm what is expected behaviour and I may be able to provide some documentation for others

- create OG 'Testsynch'>> CiviCRM pair of ACL Groups created - Testsynch and Testsynch Admin = TRUE
- creator of above OG >> added to Testsynch Admin = True
- creator of above OG >> added to Testsynhc = FALSE - is set to Pending "joining these groups is pending confirmation by this contact"
not clear how the contact does the 'confirmation'
- contact dashboard >> nothing obvious there
- create new User >> add to Civi Group get error
Code: [Select]
Fatal error: Unsupported operand types in /sites/aba/sites/all/modules/og/og.module on line 1556 Call Stack: 0.0000 639960 1. {main}() /sites/aba/index.php:0 0.1309 10909256 2. menu_execute_active_handler(???, ???) /sites/aba/index.php:21 0.1312 10910072 3. call_user_func_array(string(14), array(3)) /sites/aba/includes/menu.inc:503 0.1312 10910592 4. civicrm_invoke(string(7), string(4), string(5)) /sites/aba/includes/menu.inc:503 0.1320 11066128 5. CRM_Core_Invoke::invoke(array(4)) /sites/aba/sites/all/modules/civicrm/drupal/civicrm.module:447 0.1967 12952424 6. CRM_Contact_Page_View_GroupContact->run(array(4), null) /sites/aba/sites/all/modules/civicrm/CRM/Core/Invoke.php:224 0.2188 15466848 7. CRM_Contact_Page_View_GroupContact->edit(null, long) /sites/aba/sites/all/modules/civicrm/CRM/Contact/Page/View/GroupContact.php:130 0.2292 15885120 8. CRM_Core_Controller->run() /sites/aba/sites/all/modules/civicrm/CRM/Contact/Page/View/GroupContact.php:87 0.2295 15890304 9. HTML_QuickForm_Page->handle(string(4)) /sites/aba/sites/all/modules/civicrm/CRM/Core/Controller.php:284 0.2295 15890352 10. HTML_QuickForm_Controller->handle(class CRM_Contact_Form_GroupContact, string(4)) /sites/aba/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php:103 0.2295 15890352 11. CRM_Core_QuickForm_Action_Next->perform(class CRM_Contact_Form_GroupContact, string(4)) /sites/aba/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php:203 0.2295 15890480 12. CRM_Core_StateMachine->perform(class CRM_Contact_Form_GroupContact, string(4), string(4)) /sites/aba/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php:64 0.2495 16256752 13. CRM_Core_Form->mainProcess() /sites/aba/sites/all/modules/civicrm/CRM/Core/StateMachine.php:167 0.2495 16256752 14. CRM_Contact_Form_GroupContact->postProcess() /sites/aba/sites/all/modules/civicrm/CRM/Core/Form.php:250 0.2496 16257296 15. CRM_Contact_BAO_GroupContact::addContactsToGroup(array(1), string(2), string(5), ???, ???) /sites/aba/sites/all/modules/civicrm/CRM/Contact/Form/GroupContact.php:165 0.3101 16563696 16. CRM_Utils_Hook::post(string(6), string(12), string(2), array(1)) /sites/aba/sites/all/modules/civicrm/CRM/Contact/BAO/GroupContact.php:203 0.3103 16567072 17. eval(''return CRM_Utils_Hook_Drupal::invoke( 4, $op, $objectName, $objectId, $objectRef, $op, \'civicrm_post\' );'') /sites/aba/sites/all/modules/civicrm/CRM/Utils/Hook.php:87 0.3103 16567440 18. CRM_Utils_Hook_Drupal::invoke(long, string(6), string(12), string(2), array(1), string(6), string(12)) /sites/aba/sites/all/modules/civicrm/CRM/Utils/Hook.php(87) : eval()'d code:1 0.3104 16585472 19. civicrm_og_sync_civicrm_post(string(6), string(12), string(2), array(1)) /sites/aba/sites/all/modules/civicrm/CRM/Utils/Hook/Drupal.php:57 0.3365 16622720 20. CRM_Bridge_OG_CiviCRM::groupContact(string(2), array(1), string(3)) /sites/aba/sites/all/modules/civicrm/drupal/modules/civicrm_og_sync/civicrm_og_sync.module:216 0.3779 19599368 21. og_group(string(1), string(4), class stdClass) /sites/aba/sites/all/modules/civicrm/CRM/Bridge/OG/CiviCRM.php:101but is added to CiviGroup but not to OG
- create new user >> add to OG - added to CiviGroup = FALSE

So am feeling a tad lost as not sure what I am expecting

Can you flesh out
Quote
The patch adds an option to the user page to sync a given user with the OGs that civi believes the user belongs to. Also likewise when a new user registers it will add them to the groups that civi thinks the user is in.

Appreciate your support on this. It would be good to get this more widely known once I figure out what it can do
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 01:11:02 pm
I've just checked and we get the same pending confirmation status within CiviCRM when adding/creating a OG - my use case doesn't allow people to be added from within Drupal; all group membership is done from CiviCRM so this isn't high on my priority list to fix (and also isn't a result of my code - thats the existing core stuff).

Ah the backtrace reminded me I did patch CiviCRM core to update it to the latest OG API:
Code: [Select]
+++ civicrm/CRM/Bridge/OG/CiviCRM.php 2011-10-15 18:49:31.000000000 +0100
@@ -98,7 +98,7 @@
                 $crm_user = user_load($drupalID);
                 
                 if ( $op == 'add' ) {
-                    og_group( $ogID, 'user', $crm_user );
+                    og_group( $ogID, array( entity => $crm_user) );
                 } else {
                     og_ungroup( $ogID, 'user', $crm_user );
                 }
Should I open a JIRA ticket to get that integrated into the mainline code base?

Quote
Can you flesh out
Quote
The patch adds an option to the user page to sync a given user with the OGs that civi believes the user belongs to. Also likewise when a new user registers it will add them to the groups that civi thinks the user is in.
What this does is on the People page adds an extra action to the drop down menu which enables you to sync from CiviCRM group memberships to the existing OG's. This is so that you can sync any existing users to existing OGs that may be setup (or correspond to existing groups in the database; creating an OG with the same name as a group in CiviCRM does this)

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 01:36:40 pm
Thanks for responding - not trying to squeeze some 'can you help me make this work for a different use case' - just trying to nail what the workflow / gotchas are. And am looking for something that works with the group membership kicking off on the Civi side.

So something like this
Step 1 - create Civi Group
Step 2 - create OG with same name
Step 3 - add Civi contact to Civi Group
Step 4 - User can then see the OG as an option on the /user/xxx/edit page?

I patched as per above - did Steps 1 - 3 but still not finding anything at step 4 - maybe my OG config is different but hopefully not. Have tried with both public and private OGs.

Also does this work with Smart Groups or only Standard Groups?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 02:02:02 pm
If you create the Civi group before the OG you need to make sure that in the database that the source field for the group table is linked to the correct OG id. I found I had ended up with the wrong ids in their at some point; I think it was my fault but it may have been something that was fixed by a civicrm update?
Generally we've been not doing step 1 and going straight to step 2 as step 2 does step 1 for you. I'm not sure why step 4 isn't working for you; it certainly works here for the workflow defined above.

I think this will work from CiviCRM -> OG for smart groups and standard groups but only OG -> CiviCRM for standard groups although I might be wrong there. I've also added support for nested groups i.e. if the OG is linked to a parent which has child groups and the user is a member of the child group then the CiviCRM -> OG sync will work.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 02:18:14 pm
Thanks for bearing with me, so

Step 1 - create public OG >> Civi Group and Admin Group created - PASS
Step 2 - find a Contact and add to CiviGroup
Step 3 - login as that User and look around for something

nada - can you confirm I should be seeing something at user/xxx/edit?

I am beginning to suspect this might be an issue related to what Fields are set for the 'User - User Entity' in the OG Field Settings at /admin/config/group/fields - would you be willing to confirm your set up there?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jcasharpe

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 5
    • Woodlands Church
  • CiviCRM version: 4.4.6
  • CMS version: Drupal 7
  • MySQL version: MariaDB 10.0.13
  • PHP version: 5.5
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 02:21:40 pm
Yes you should see a listbox with the groups the user is a member of.

Looking at the fields I just have Groups Audience on the User - User Entity bundle.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: CiviCRM -> OG sync reverse sync
November 09, 2011, 03:26:15 pm
okay - so i thought i was missing the point of you referring to the 'people' page which is why i was seeking confirmation of urls.

So on admin/people there is now an option in the Update Options dropdown box to "Synch the selected users OGs' so that allows for bulk updating, presumably performing the same action as occurs when the user logs in.

Getting closer - thanks.

And I confirm that creating an OG, adding people to the relevant civi group, results in them being added to the OG. GREAT

What I can't confirm is that this works for Smart Groups.

And since we can't start at the OG end for this afaik the steps were

1/ Create Smart Group
2/ Create OG with same name
3/ Confirm there is now a Civi Admin Group with same name which suggests the OG Synch bit is fine.

But of course I had to add the contacts to the Smart Group at the point of making the Smart Group. But I also then added a new User whose criteria matched the Smart Group - and then 'synched' and no joy - and then logged in as them and no joy.

So it would be great if you could confirm you have civi contacts who are dynamically added to Smart Groups showing up in the related OG. Look forward to the good news - or if not - any pointers to how we can progress this.

Or does that come back to the old gotcha about the way Smart Groups are caching and not making contacts available for other tasks (such as we have hit with webforms and the 'assign' group)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • CiviCRM -> OG sync reverse sync

This forum was archived on 2017-11-26.