Same name and namespace in other branches
  1. 4.7.x database/updates.inc \system_update_164()

File

modules/system/system.install, line 2426

Code

function system_update_164() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {poll_votes} (\n          nid int unsigned NOT NULL,\n          uid int unsigned NOT NULL default 0,\n          hostname varchar(128) NOT NULL default '',\n          INDEX (nid),\n          INDEX (uid),\n          INDEX (hostname)\n      )");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {poll_votes} (\n          nid int NOT NULL,\n          uid int NOT NULL default 0,\n          hostname varchar(128) NOT NULL default ''\n      )");
      $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)');
      $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)');
      $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)');
      break;
  }
  $result = db_query('SELECT nid, polled FROM {poll}');
  while ($poll = db_fetch_object($result)) {
    foreach (explode(' ', $poll->polled) as $polled) {
      if ($polled[0] == '_') {

        // $polled is a user id
        db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $poll->nid, substr($polled, 1, -1));
      }
      else {

        // $polled is a host
        db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $poll->nid, $polled);
      }
    }
  }
  $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
  return $ret;
}