summaryrefslogtreecommitdiff
path: root/database/updates.inc
diff options
context:
space:
mode:
Diffstat (limited to 'database/updates.inc')
-rw-r--r--database/updates.inc56
1 files changed, 56 insertions, 0 deletions
diff --git a/database/updates.inc b/database/updates.inc
index f977fdbde..26f627342 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -1286,3 +1286,59 @@ function system_update_163() {
}
return $ret;
}
+
+function system_update_164() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql('CREATE TABLE {poll_votes} (
+ nid int(10) unsigned NOT NULL,
+ uid int(10) unsigned NOT NULL,
+ hostname varchar(128) NOT NULL,
+ INDEX (nid),
+ INDEX (uid),
+ INDEX (hostname)
+ )');
+ break;
+
+ case 'pgsql':
+ $ret[] = update_sql('CREATE TABLE {poll_votes} (
+ nid int(10) NOT NULL,
+ uid int(10) NOT NULL,
+ hostname varchar(128) NOT NULL
+ )');
+ $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);
+ }
+ }
+ }
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
+ break;
+
+ case 'pgsql':
+ $ret[] = update_sql('ALTER TABLE {poll} RENAME polled TO polled_old');
+ break;
+ }
+
+ return $ret;
+}