Skip to content

Instantly share code, notes, and snippets.

@tenken
Created March 14, 2012 20:35
Show Gist options
  • Save tenken/2039318 to your computer and use it in GitHub Desktop.
Save tenken/2039318 to your computer and use it in GitHub Desktop.
sample file to assign nodes to be owned by groups for OG 1.x (~1 year ago) under Drupal 7.
<?php
# @author webdev@id.ucsb.edu
$entity_groups = entity_load('group', FALSE);
#
# The Group Entities were created in the order the D6 DomainAccess site had the
# subdomain id's stored in the database. We can simply iterate through the
# Entity list we get back and look for nodes in that DA/GID "id" value and
# subscribe that node to that same group.
#
# We will then have to look for the default site nodes for Administrative stuff
# and set them to gid = 17.
#
foreach ($entity_groups as $e) {
if ($e->gid != 17) {
$gid = $e->gid;
$area = $e->label;
$domain_result = db_query('select nid from {z_da_access} zda where zda.gid = :domain_id', array(':domain_id' => $gid));
print "\nGID is $gid\n";
foreach ($domain_result as $da_record) {
print "\n".$da_record->nid;
$node = node_load($da_record->nid);
$values = array('entity type' => 'node', 'entity' => $node, 'state' => OG_STATE_ACTIVE);
og_group($e->gid, $values);
print " -- assigned to GID ".$e->gid." -- saved. \n";
node_save($node);
}
}
}
#
# Look for the old default Drupal site stuff (administration).
#
$default = db_query('select nid from {z_da_access} zda where zda.gid = 0');
$default_admin_group_gid = 17;
foreach ($default as $da_default_record) {
$node = node_load($da_default_record->nid);
$values = array('entity type' => 'node', 'entity' => $node, 'state' => OG_STATE_ACTIVE);
og_group($default_admin_group_gid, $values);
node_save($node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment