You are here

function og_update_5 in Organic groups 5.8

Same name and namespace in other branches
  1. 5 og.install \og_update_5()
  2. 5.2 og.install \og_update_5()
  3. 5.3 og.install \og_update_5()
  4. 5.7 og.install \og_update_5()

feb 19, 2006 add a row for each combination of public node and group. needed to make public nodes show up in group homepage for non subscribers

File

./og.install, line 185

Code

function og_update_5() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    case 'pgsql':
      $sql = "SELECT DISTINCT(nid) as nid FROM {node_access} WHERE realm = 'og_group' AND gid = 0";
      $result = db_query($sql);
      while ($row = db_fetch_object($result)) {
        $sql = "SELECT gid FROM {node_access} WHERE nid = %d AND realm = 'og_group' AND gid != 0";
        $result2 = db_query($sql, $row->nid);
        while ($row2 = db_fetch_object($result2)) {
          og_deleteifpresent_2keys('node_access', array(
            'nid',
            'gid',
          ), array(
            '%d',
            '%d',
          ), array(
            $row->nid,
            $row->gid,
          ));
          $sql = "INSERT INTO {node_access} (nid, realm, gid, grant_view) VALUES (%d, 'og_public', 0, %d)";
          db_query($sql, $row->nid, $row2->gid);
        }
      }

      // change all former public node grants to 'og_all' realm
      $sql = "UPDATE {node_access} SET realm = 'og_all' WHERE realm = 'og_group' AND gid = 0 AND grant_view = 1";
      db_query($sql);

      // change all nodes in groups to new 'og_subscriber' realm
      $sql = "UPDATE {node_access} SET realm = 'og_subscriber' WHERE realm = 'og_group' AND gid != 0";
      db_query($sql);

      // these records are no longer used. we've migrated them to new grant scheme
      $sql = "DELETE FROM {node_access} WHERE realm = 'og_group'";
      db_query($sql);
  }
  return array();
}