Bulk assign OG 7 access values

Public

if you forgot to assign the permission field for group content (admin/config/group/fields) you can assign the values like this

Get raw version
php
  1. // if you have lot's of nodes use should consider using queue API
  2. // you can execute this snippet at devel/php if the devel module is enabled
  3. $query = new EntityFieldQuery();
  4. $entities = $query->entityCondition('entity_type', 'node')
  5. ->entityCondition('bundle', 'YOUR_CONTENT_TYPE')
  6. ->propertyCondition('status', 1)
  7. ->execute();
  8.  
  9. $nodes = node_load_multiple(array_keys($entities['node']));
  10.  
  11. foreach ($nodes as $node){
  12. // 0 group default
  13. // 1 public -> (no need to assign)
  14. // private
  15. $node->group_content_access['und'][0]['value'] = 0;
  16. node_save($node);
  17. }