You are here

function og_update_7200 in Organic groups 7.2

Deprecate OG group entity, and add per-bundle roles.

File

./og.install, line 952
Install, update, and uninstall functions for the Organic groups module.

Code

function og_update_7200() {

  // Delete the old group-audience field. The OG membership is not
  // affected by this.
  foreach (field_info_instances() as $entity_type => $bundles) {
    foreach ($bundles as $bundle => $field_names) {
      if (!empty($field_names['group_audience'])) {
        field_delete_instance($field_names['group_audience']);
      }
    }
  }
  if (!module_enable(array(
    'entityreference',
  ))) {
    throw new DrupalUpdateException('This version of OG requires Entity reference, but it could not be enabled.');
  }
  $column = array(
    'description' => "The group's entity type (e.g. node, comment, etc').",
    'type' => 'varchar',
    'length' => '32',
    'not null' => TRUE,
    'default' => '',
  );
  db_add_field('og_membership', 'group_type', $column);

  // Re-add index.
  db_drop_index('og_membership', 'gid');
  db_add_index('og_membership', 'group', array(
    'gid',
    'group_type',
  ));
  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The group's entity type.",
  );
  db_add_field('og_role', 'group_type', $column);

  // Rename {og_users_roles} to allow easier migration.
  // Re-create a clean {og_users_roles}.
  db_rename_table('og_users_roles', 'temp_og_users_roles');
  $schema = og_schema_7200_info();
  db_create_table('og_users_roles', $schema['og_users_roles']);
  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The group's bundle name.",
  );
  db_add_field('og_role', 'group_bundle', $column);
  $column = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
    'description' => "The name of the field holding the group ID, the OG memebership is associated with.",
  );
  db_add_field('og_membership', 'field_name', $column);

  // Delete OG-migrate's table.
  db_drop_table('og_migrate');

  // Variable cleanup.
  variable_del('og_skip_access');

  // Clear entity cache.
  // See http://drupal.org/node/996236
  entity_info_cache_clear();

  // Temporary variable to indicate we need to migrate OGUR data.
  variable_set('og_7200_ogur_roles', TRUE);
  return t('Enable "Migrate-UI" module to continue the migration of data. Once migration is done you may disable "Migrate" module');
}