CRM-5248 Creating an OG causes an error during syncing to CiviCRM groups

    Details

      Description

      When an OG is created, it should create two corresponding CiviCRM groups. The OG is created, but an error occurs which does not create the CiviCRM groups.

      Backtrace:

      /usr/home/debxxxxx/domains/covs.org/public_html/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 256
      /usr/home/debxxxxx/domains/covs.org/public_html/sites/all/modules/civicrm/CRM/Bridge/OG/Utils.php, fatal, 111
      /usr/home/debxxxxx/domains/covs.org/public_html/sites/all/modules/civicrm/CRM/Bridge/OG/Drupal.php, groupID, 196
      /usr/home/debxxxxx/domains/covs.org/public_html/sites/all/modules/civicrm/drupal/modules/civicrm_og_sync/civicrm_og_sync.module, og, 119
      , civicrm_og_sync_og,
      /usr/home/debxxxxx/domains/covs.org/public_html/includes/module.inc, call_user_func_array, 471
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/og/og.module, module_invoke_all, 637
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/og/og.module, og_save_subscription, 1224
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/node/node.module, og_nodeapi, 673
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/node/node.module, node_invoke_nodeapi, 929
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/node/node.pages.inc, node_save, 456
      /usr/home/debxxxxx/domains/covs.org/public_html/includes/form.inc, node_form_submit, 774
      /usr/home/debxxxxx/domains/covs.org/public_html/includes/form.inc, form_execute_handlers, 414
      /usr/home/debxxxxx/domains/covs.org/public_html/includes/form.inc, drupal_process_form, 119
      /usr/home/debxxxxx/domains/covs.org/public_html/modules/node/node.pages.inc, drupal_get_form, 58
      , node_add,
      /usr/home/debxxxxx/domains/covs.org/public_html/includes/menu.inc, call_user_func_array, 348
      /usr/home/debxxxxx/domains/covs.org/public_html/index.php, menu_execute_active_handler, 18

        Attachments

          Activity

          [CRM-5248] Creating an OG causes an error during syncing to CiviCRM groups
          Donald A. Lobo added a comment -

          Would be great if you can investigate and submit a patch. we'll try to take a look at this before the 3.1 release

          Ed van Leeuwen added a comment -

          I have tried to solve this, but I think I do not have the proper skills to do so. This is wahat I have done so far, to get a workaround which suits me.

          I saw that a call is made to the groupID-function:

          (Drupal.php, line 194)

          // get the group id of this OG
          $groupID = CRM_Bridge_OG_Utils::groupID( CRM_Bridge_OG_Utils::ogSyncName( $params['og_id'] ),
          null, true );

          When the groupID is not found, a fatal error is thrown. However, during creation I think that there could not yet be a groupID, so it would always fail. Therefor, I tried to comment out the fatal error.

          (Utils.php, line 108)

          $groupID = CRM_Core_DAO::singleValueQuery( $query, $params );
          if ( $abort &&
          ! $groupID )

          { //CRM_Core_Error::fatal( ); }

          After this, I get errors on the part trying to add GroupContacts. As I am only interested in groups for now, I commented this section out as well:

          (Utils.php, line 201)

          /*
          require_once 'api/v2/GroupContact.php';
          if ( $op == 'add' )

          { $groupParams['status'] = $params['is_active'] ? 'Added' : 'Pending'; civicrm_group_contact_add( $groupParams ); }

          else

          { $groupParams['status'] = 'Removed'; civicrm_group_contact_remove( $groupParams ); }

          if ( CRM_Bridge_OG_Utils::aclEnabled( ) &&
          $params['is_admin'] !== null ) {
          // get the group ID of the acl group
          $groupID = CRM_Bridge_OG_Utils::groupID( CRM_Bridge_OG_Utils::ogSyncACLName( $params['og_id'] ),
          null, true );

          $groupParams = array( 'contact_id' => $contactID,
          'group_id' => $groupID ,
          'status' => $params['is_admin'] ? 'Added' : 'Removed' );

          if ( $params['is_admin'] )

          { civicrm_group_contact_add( $groupParams ); }

          else

          { civicrm_group_contact_remove( $groupParams ); }

          }
          */

          This seems to be working: I am able to create groups in Drupal which are synced in CiviCRM and an additional Administror-group is added in CiviCRM. For now, this is what I want. Perhaps another one could look into this more in detail.

          Yashodha Chaku added a comment -

          assigning for 3.1 verification

          Rahul Bile added a comment -

          Checked in r- 25215

          Eric Orton added a comment -

          I spent a while in my debugger and found that the fix for this issue broke the synchronisation of users from og for me. The added code is missing a call to

          _civicrm_og_sync_set_context( 'drupal' )

          prior to the new

          CRM_Bridge_OG_Drupal::nodeapi( $params, 'add' );

          Without it, the nodeapi add will eventually call back into civicrm_og_sync via hook_civicrm_post whereby civicrm_og_sync fires it's group edit logic, set's the context to 'civicrm' and updates the group.

          Finally, when civicrm_og_sync then tries to set the context to 'drupal' so that it can add the new user to the civicrm group, it can't.

          Adding the call to correctly set the context before we do the nodeapi add fixes this problem. I'm a bit skeptical about the original fix however. I think it would be better for it to not be fatal error if a civi group doesn't exist matching the og group instead of enforcing that there's always a 1-1 match of groups.

          Locally I have disabled the methods in CRM_Bridge_OG_CiviCRM for adding and deleting og groups, and I've modified CRM_Bridge_OG_Drupal as follows:

          Line 195:
          // get the group id of this OG
          $groupID = CRM_Bridge_OG_Utils::groupID( CRM_Bridge_OG_Utils::ogSyncName( $params['og_id'] ),
          null, false );

          if (!$groupID)

          { return; }

            People

            • Assignee:
              Rahul Bile
              Reporter:
              Ed van Leeuwen

              Dates

              • Created:
                Updated:
                Resolved: