You are here

function _og_orphans_delete in Organic groups 7.2

Helper function to delete orphan group-content.

Parameters

$ids: Array of OG membership IDs.

See also

og_membership_delete_by_group_worker()

1 call to _og_orphans_delete()
og_membership_orphans_worker in ./og.module
Queue worker; Process a queue item.

File

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

Code

function _og_orphans_delete($ids) {

  // Get all the group-content that is now orphan.
  $orphans = array();
  $og_memberships = og_membership_load_multiple($ids);
  foreach ($og_memberships as $og_membership) {
    $entity_type = $og_membership->entity_type;
    $id = $og_membership->etid;

    // Don't delete users.
    if ($entity_type == 'user') {
      continue;
    }
    $entity_groups = og_get_entity_groups($entity_type, $id);

    // Orphan node can be relate to only one type of entity group.
    if (count($entity_groups) == 1) {
      $gids = reset($entity_groups);

      // Orphan node can be relate to only one node.
      if (count($gids) > 1) {
        continue;
      }
    }
    $orphans[$entity_type][] = $id;
  }
  if ($orphans) {
    foreach ($orphans as $entity_type => $orphan_ids) {
      entity_delete_multiple($entity_type, $orphan_ids);
    }
  }

  // Delete the OG memberships.
  og_membership_delete_multiple($ids);
}