You are here

function og_update_1 in Organic groups 5.7

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

File

./og.install, line 119

Code

function og_update_1() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("ALTER TABLE {og_uid} ADD `og_role` int(1) NOT NULL default '0'");
      db_query("ALTER TABLE {og_uid} ADD `is_active` int(1) default '0'");
      db_query("ALTER TABLE {og_uid} ADD `is_admin` int(1) default '0'");
      break;
    case 'pgsql':
      db_query("ALTER TABLE {og_uid} ADD `og_role` smallint NOT NULL default 0");
      db_query("ALTER TABLE {og_uid} ADD `is_active` smallint default 0");
      db_query("ALTER TABLE {og_uid} ADD `is_admin` smallint default 0");
      break;
  }
  $result = db_query("SELECT * FROM {node_access} WHERE realm = 'og_uid'");
  while ($object = db_fetch_object($result)) {
    og_deleteifpresent_2keys('og_uid', array(
      'nid',
      'gid',
    ), array(
      '%d',
      '%d',
    ), array(
      $object->nid,
      $object->gid,
    ));

    // insert new row.
    $sql = "INSERT INTO {og_uid} (nid, uid, og_role, is_admin, is_active) VALUES (%d, %d, %d, %d, %d)";
    db_query($sql, $object->nid, $object->gid, $object->grant_view + $object->grant_update, $object->grant_update, $object->grant_view);
  }
  $sql = "DELETE FROM {node_access} WHERE realm = 'og_uid'";
  db_query($sql);
  return array();
}