You are here

function og_membership_delete_by_group in Organic groups 7.2

Register memberships for deletion.

if the property "skip_og_membership_delete_by_group" exists on the entity, this function will return early, and allow other implementing modules to deal with the deletion logic.

Parameters

$entity_type: The group type.

$entity: The group entity object.

1 call to og_membership_delete_by_group()
og_entity_delete in ./og.module
Implements hook_entity_delete().

File

./og.module, line 1758
Enable users to create and manage groups with roles and permissions.

Code

function og_membership_delete_by_group($entity_type, $entity) {
  if (!empty($entity->skip_og_membership_delete_by_group)) {
    return;
  }
  list($gid) = entity_extract_ids($entity_type, $entity);
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'og_membership')
    ->propertyCondition('group_type', $entity_type, '=')
    ->propertyCondition('gid', $gid, '=')
    ->execute();
  if (empty($result['og_membership'])) {
    return;
  }
  if (variable_get('og_use_queue', FALSE)) {
    $queue = DrupalQueue::get('og_membership_orphans');

    // Add item to the queue.
    $data = array(
      'group_type' => $entity_type,
      'gid' => $gid,
      // Allow implementing modules to determine the disposition (e.g. delete
      // orphan group content).
      'orphans' => array(
        'delete' => isset($entity->og_orphans['delete']) ? $entity->og_orphans['delete'] : variable_get('og_orphans_delete', FALSE),
        'move' => isset($entity->og_orphans['move']) ? $entity->og_orphans['move'] : array(),
      ),
    );

    // Exit now, as the task will be processed via queue.
    return $queue
      ->createItem($data);
  }

  // No scalable solution was chosen, so just delete OG memberships.
  og_membership_delete_multiple(array_keys($result['og_membership']));
}