You are here

function og_subgroups_migrate in Subgroups for Organic groups 5

Same name and namespace in other branches
  1. 5.4 og_subgroups.install \og_subgroups_migrate()

Helper function migrate users with og_subgroups 5.x-3 to 5.x-4.

Parameters

$clean_only: When enabled new records will not be written, only deleted from {og_ancestry}.

3 calls to og_subgroups_migrate()
og_subgroups_install in ./og_subgroups.install
og_subgroups_update_1 in ./og_subgroups.install
Update path for versions prior to 5.x-4.
og_subgroups_update_2 in ./og_subgroups.install
Remove old records from {og_ancestry}.

File

./og_subgroups.install, line 49

Code

function og_subgroups_migrate($clean_only = FALSE) {

  // Get all nodes from og_ancestry that nid and group_nid are both group nodes.
  $all_groups = db_query("SELECT oga.nid AS gid, oga.group_nid AS parent FROM {og_ancestry} oga INNER JOIN {og} og ON og.nid = oga.nid");
  $migrate = FALSE;
  while ($group = db_fetch_object($all_groups)) {
    $migrate = TRUE;

    // Don't insert new records, only clean older records.
    if (!$clean_only) {
      db_query('INSERT INTO {og_subgroups} (gid, parent) VALUES (%d, %d)', $group->gid, $group->parent);
    }
    db_query('DELETE FROM {og_ancestry} WHERE nid = %d AND group_nid = %d', $group->gid, $group->parent);
  }
  if ($migrate) {
    $ret = array(
      'query' => t('Groups from versions prior to 5.x-4 were migrated, and old records from the {og_ancestry} were removed.'),
      'success' => TRUE,
    );
  }
  else {
    $ret = array(
      'query' => t('OG Subgroups didn\'t migrate older records from {og_ancestry} since there were none.'),
      'success' => TRUE,
    );
  }
  return $ret;
}