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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • CiviCRM OG Sync for OG 7.x.2 branch
Pages: [1]

Author Topic: CiviCRM OG Sync for OG 7.x.2 branch  (Read 1073 times)

kafmil

  • I’m new here
  • *
  • Posts: 12
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: 5.095
  • PHP version: 5.2.17
CiviCRM OG Sync for OG 7.x.2 branch
December 10, 2012, 05:28:14 pm
Hi All,

I was not sure where to put this. There is an issue with the CiviCRM OG Sync module when used with the new OG 7.x-2 branch. It throws this error when creating a new group.
Code: [Select]
Call to undefined function og_get_group() in civicrm_og_sync.module on line 236The new OG does not have a separate gid, it just uses the nid for the group. For this reason the functions og_get_group and og_get_group_ids are no longer used.

Because we won't know which og people are using, I have modified the functions civicrm_og_sync_node_delete, _civicrm_og_sync_node_action and civicrm_og_sync_enable to check if the relevant function exists and if not to use the nid or the 2x branch function as required.

I am not sure how this works in the CiviCRM developer world but the functions are written below for someone to use and change in the next or current release of the module to make sure it works for people as expected if they are using the 2.x branch of og. To be honest I have only actually tested _civicrm_og_sync_node_action as its the only one I need at present, however it is a pretty simple change so these should work.

Code: [Select]
function civicrm_og_sync_node_delete( $node ) {
    if ( !_civicrm_og_sync_check_isvalid( $node ) ) {
        return;
    }
    require_once 'CRM/Bridge/OG/Drupal.php';

    $groupid = 0;
   
    if (function_exists('og_get_group')) {
        if ( $group = og_get_group('node', $node->nid) ) {
            if ( empty($group->gid) ) {
                return;
            }
            $groupid = $group->gid;
        }
    } else {
        $groupid = $node->nid;
    }

    _civicrm_og_sync_skip_process_request(true);

    $params = array( 'name'        => $node->title,
                      'title'       => $node->title,
                      'og_id'       => $groupid );

    CRM_Bridge_OG_Drupal::nodeapi( $params, 'delete' );
}

Code: [Select]
/*
 *Update or Add node
 */
function _civicrm_og_sync_node_action( $node ) {
    if ( !_civicrm_og_sync_check_isvalid( $node ) ) {
        return;
    }

    $title  = trim( $node->title );
   
    $groupid = 0;
   
    if (function_exists('og_get_group')) {
        if ( $group = og_get_group('node', $node->nid) ) {
            if ( empty($group->gid) ) {
                return;
            }
            $groupid = $group->gid;
        }
    } else {
        $groupid = $node->nid;
    }
    $params = array( 'name'        => $title,
                      'title'       => $title,
                      'is_active'   => 1,
                      'og_id'       => $groupid );

    require_once 'CRM/Bridge/OG/Drupal.php';

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

    _civicrm_og_sync_skip_process_request( true );

    // also call the user hook since OG does not for admin       
    $params = array( 'og_id'     => $groupid,
                      'uf_id'     => $node->uid,
                      'is_active' => 1,
                      'is_admin'  => 1,
                      );

    CRM_Bridge_OG_Drupal::og( $params, 'add' );
       
}

Code: [Select]
function civicrm_og_sync_enable() {
    if ( ! civicrm_initialize( ) ) {
        return;
    }
         
    if (function_exists('og_get_group_ids')) {
        $ogGroupIds  =  og_get_group_ids('node');
    } else {
        $ogGroupIds  =  og_get_all_group('node');
    }
   
    // FIX ME
    $subscribers = array( );
    // $subscribers = og_get_group_ids('user');

    foreach( $ogGroupIds as $nid => $gid ) {
        $node = node_load( $nid );
        $title  = trim( $node->title );
        $params = array( 'name'        => substr(trim($title),0,49),// length of 49 so that the admin group can fit ': administrator' afterwards within 64 char field
                         'title'       => $title,
                         'is_active'   => 1,
                         'og_id'       => $gid );
       
        _civicrm_og_sync_skip_process_request( true );

        // add the group
        require_once 'CRM/Bridge/OG/Drupal.php';
        CRM_Bridge_OG_Drupal::nodeapi( $params, 'add' );
       
        // add the subscribers
        foreach($subscribers as $uid ) {
            $is_admin = false;
            if ( $uid == $node->uid ) $is_admin = true;

            $addToGroupParams = array( 'og_id'     => $gid,
                                       'uf_id'     => $uid,
                                       'is_active' => 1,
                                       'is_admin'  => $is_admin,
                                       );
           
            // add contact in group
            CRM_Bridge_OG_Drupal::og( $addToGroupParams, 'add' );
        }
    }
}

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 for OG 7.x.2 branch
December 10, 2012, 05:38:29 pm

hey kafmil:

thanx for the patch. Can you please file an issue at: http://issues.civicrm.org/ and attach a patch (unified diff patch) to the issue please

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

kafmil

  • I’m new here
  • *
  • Posts: 12
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: 5.095
  • PHP version: 5.2.17
Re: CiviCRM OG Sync for OG 7.x.2 branch
December 28, 2012, 01:51:13 pm
Hi Lobo,

I have created the patches and filed issues for 4.1.6 and 4.2.6. I made a mistake and accidentally created the 4.2.6 one twice. And then didn't change the version for the 4.1.6 patch. I have left comments on the issues. They are CRM-11559, CRM-11560 and CRM-11551. Sorry.


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • CiviCRM OG Sync for OG 7.x.2 branch

This forum was archived on 2017-11-26.