function system_update_114 in Drupal 5
Same name and namespace in other branches
- 4 database/updates.inc \system_update_114()
File
- modules/
system/ system.install, line 1264
Code
function system_update_114() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("CREATE TABLE {queue} (\n nid int unsigned NOT NULL,\n uid int unsigned NOT NULL,\n vote int NOT NULL default '0',\n PRIMARY KEY (nid, uid)\n )");
}
else {
if ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql("CREATE TABLE {queue} (\n nid integer NOT NULL default '0',\n uid integer NOT NULL default '0',\n vote integer NOT NULL default '0',\n PRIMARY KEY (nid, uid)\n )");
$ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)");
$ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)");
}
}
$result = db_query("SELECT nid, votes, score, users FROM {node}");
while ($node = db_fetch_object($result)) {
if (isset($node->users)) {
$arr = explode(',', $node->users);
unset($node->users);
foreach ($arr as $value) {
$arr2 = explode('=', trim($value));
if (isset($arr2[0]) && isset($arr2[1])) {
switch ($arr2[1]) {
case '+ 1':
db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int) $arr2[0], 1);
break;
case '- 1':
db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int) $arr2[0], -1);
break;
default:
db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int) $arr2[0], 0);
}
}
}
}
}
if ($GLOBALS['db_type'] == 'mysql') {
// Postgres only supports dropping of columns since 7.4
$ret[] = update_sql("ALTER TABLE {node} DROP votes");
$ret[] = update_sql("ALTER TABLE {node} DROP score");
$ret[] = update_sql("ALTER TABLE {node} DROP users");
}
return $ret;
}