You are here

function _oa_core_remove_orphaned_og_roles in Open Atrium Core 7.2

Helper function to remove groups that are using default permissions but still have entries in og_role table

2 calls to _oa_core_remove_orphaned_og_roles()
oa_core_update_7227 in ./oa_core.install
Fix accidentatly given roles.
oa_core_update_7232 in ./oa_core.install
Remove orphaned records in og_role table.

File

./oa_core.install, line 263
Provides update and install hooks to oa_core.

Code

function _oa_core_remove_orphaned_og_roles() {
  $query = db_select('og_role', 'og');
  $query
    ->join('field_data_og_roles_permissions', 'f', "og.gid = f.entity_id AND f.entity_type = 'node'");
  $query
    ->fields('og', array(
    'gid',
  ))
    ->condition('f.og_roles_permissions_value', 0);
  $gids = $query
    ->execute()
    ->fetchCol();
  if (!empty($gids)) {
    db_delete('og_role')
      ->condition('gid', $gids, 'IN')
      ->execute();
  }
}