summaryrefslogtreecommitdiff
path: root/database/updates.inc
diff options
context:
space:
mode:
Diffstat (limited to 'database/updates.inc')
-rw-r--r--database/updates.inc222
1 files changed, 89 insertions, 133 deletions
diff --git a/database/updates.inc b/database/updates.inc
index 6bc5a5741..799e57f4d 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -789,17 +789,42 @@ function update_79() {
function update_80() {
+ // Add a 'created' field to the users table:
+ $ret[] = update_sql('ALTER TABLE {users} ADD created INT(11) NOT NULL');
+ $ret[] = update_sql('ALTER TABLE {users} CHANGE timestamp changed INT(11) NOT NULL');
+ // Add some indices to speed up the update process:
+ $ret[] = update_sql('ALTER TABLE {comments} ADD index (timestamp)');
+ $ret[] = update_sql('ALTER TABLE {node} ADD index (created)');
- if ($GLOBALS["db_type"] == "mysql") {
- // Add a 'created' field to the users table:
- $ret[] = update_sql('ALTER TABLE {users} ADD created INT(11) NOT NULL');
- $ret[] = update_sql('ALTER TABLE {users} CHANGE timestamp changed INT(11) NOT NULL');
+ // Assign everyone a created timestamp to begin with:
+ $ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = ''");
+ // Print a status message:"
+ print '<p>Note: this might take a while ...</p>';
+ // Try updating the user records using the comment table:
+ $result = db_query('SELECT DISTINCT(u.uid) FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.timestamp < u.created');
+ while ($account = db_fetch_object($result)) {
+ // Retrieve the proper timestamp:
+ $timestamp = db_result(db_query('SELECT MIN(timestamp) FROM {comments} WHERE uid = %d', $account->uid));
+
+ // Update this user record as well as older records with an older timestamp:
+ db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
+ }
- // Add profile module related tables:
- $ret[] = update_sql("CREATE TABLE {profile_fields} (
+ // Try updating the user records using the node table:
+ $result = db_query('SELECT DISTINCT(u.uid) FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.created < u.created');
+ while ($account = db_fetch_object($result)) {
+ // Retrieve the proper timestamp:
+ $timestamp = db_result(db_query('SELECT MIN(created) FROM {node} WHERE uid = %d', $account->uid));
+
+ // Update this user record as well as older records with an older timestamp:
+ db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
+ }
+
+ // Add profile module related tables:
+ $ret[] = update_sql("CREATE TABLE {profile_fields} (
fid int(10) NOT NULL auto_increment,
title varchar(255) default NULL,
name varchar(128) default NULL,
@@ -814,149 +839,80 @@ function update_80() {
PRIMARY KEY (fid)
);");
- $ret[] = update_sql("CREATE TABLE {profile_values} (
+ $ret[] = update_sql("CREATE TABLE {profile_values} (
fid int(11) unsigned default '0',
uid int(11) unsigned default '0',
value text,
KEY uid (uid),
KEY fid (fid)
);");
- // Add some indices to speed up the update process:
- $ret[] = update_sql('ALTER TABLE {comments} ADD index (timestamp)');
- $ret[] = update_sql('ALTER TABLE {node} ADD index (created)');
- // Assign everyone a created timestamp to begin with:
- $ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = ''");
-
- }
- else {// pgsql
-
- $ret[] = update_sql('ALTER TABLE {users} RENAME timestamp TO changed');
- $ret[] = update_sql('ALTER TABLE {users} ADD created integer');
- $ret[] = update_sql('UPDATE {users} SET created = 0');
- $ret[] = update_sql('ALTER TABLE {users} ALTER COLUMN created SET NOT NULL');
- $ret[] = update_sql('ALTER TABLE {users} ALTER COLUMN created SET DEFAULT 0');
- // Add profile module related tables:
- $ret[] = update_sql("CREATE TABLE {profile_fields} (
- fid serial,
- title varchar(255) default NULL,
- name varchar(128) default NULL,
- explanation TEXT default NULL,
- category varchar(255) default NULL,
- type varchar(128) default NULL,
- weight smallint DEFAULT '0' NOT NULL,
- overview smallint DEFAULT '0' NOT NULL,
- options text,
- UNIQUE (name),
- PRIMARY KEY (fid)
- );");
- $ret[] = update_sql("CREATE INDEX profile_fields_category ON {profile_fields} (category);");
- $ret[] = update_sql("CREATE TABLE {profile_values} (
- fid integer default '0',
- uid integer default '0',
- value text
- );");
- $ret[] = update_sql("CREATE INDEX profile_values_uid ON profile_values (uid);");
- $ret[] = update_sql("CREATE INDEX profile_values_fid ON profile_values (fid);");
-
- // Add some indices to speed up the update process:
- $ret[] = update_sql('CREATE INDEX comments_timestamp ON {comments} (timestamp)');
- $ret[] = update_sql('CREATE INDEX node_created on {node} (created)');
- // Assign everyone a created timestamp to begin with:
- $ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = 0");
- }
-
-
- // Print a status message:"
- print '<p>Note: this might take a while ...</p>';
-
- // Try updating the user records using the comment table:
- $result = db_query('SELECT DISTINCT(u.uid) FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.timestamp < u.created');
+ // Migrate the old profile data to the new scheme:
+ $fields = array(
+ array("Name", "realname", "textfield", NULL, 0),
+ array("Address", "address", "textfield", NULL, 0),
+ array("City", "city", "textfield", NULL, 0),
+ array("State, province or region", "state", "textfield", NULL, 0),
+ array("Zip or postal code", "zip", "textfield", NULL, 0),
+ array("Country", "country", "textfield", NULL, 1),
+ array("Gender", "gender", "selection", "male\nfemale", 1),
+ array("Job title", "job", "textfield", NULL, 0),
+ array("ICQ messenger ID", "icq", "textfield", NULL, 0),
+ array("MSN messenger ID", "msn", "textfield", NULL, 0),
+ array("Yahoo messenger ID", "yahoo", "textfield", NULL, 0),
+ array("AIM messenger ID", "aim", "textfield", NULL, 0),
+ array("URL of homepage", "homepage", "url", NULL, 1),
+ array("Biography", "biography", "textarea", NULL, 0),
+ array("Interests", "interests", "textarea", NULL, 0),
+ array("Public key", "publickey", "textarea", NULL, 0),
+ array("Birthday", "birthday", "date", NULL, 0)
+ );
+
+ // Remove existing data (debug mode):
+ db_query('DELETE FROM {profile_fields}');
+ db_query('DELETE FROM {profile_values}');
+
+ foreach ($fields as $field) {
+ db_query("INSERT INTO {profile_fields} (title, name, type, category, options, overview) VALUES ('%s', '%s', '%s', 'Personal information', '%s', %d)", $field[0], $field[1], $field[2], $field[3], $field[4]);
+ }
+ db_query("ALTER TABLE {users} ADD picture varchar(255) NOT NULL DEFAULT ''");
+
+ $result = db_query("SELECT uid FROM {users}");
while ($account = db_fetch_object($result)) {
- // Retrieve the proper timestamp:
- $timestamp = db_result(db_query('SELECT MIN(timestamp) FROM {comments} WHERE uid = %d', $account->uid));
- // Try updating the user records using the node table:
- $result = db_query('SELECT DISTINCT(u.uid) FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.created < u.created');
- while ($account = db_fetch_object($result)) {
- // Retrieve the proper timestamp:
- $timestamp = db_result(db_query('SELECT MIN(created) FROM {node} WHERE uid = %d', $account->uid));
-
- // Update this user record as well as older records with an older timestamp:
- db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
- }
-
- // Update this user record as well as older records with an older timestamp:
- db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
- }
-
-
- // Migrate the old profile data to the new scheme:
- $fields = array(
- array("Name", "realname", "textfield", NULL, 0),
- array("Address", "address", "textfield", NULL, 0),
- array("City", "city", "textfield", NULL, 0),
- array("State, province or region", "state", "textfield", NULL, 0),
- array("Zip or postal code", "zip", "textfield", NULL, 0),
- array("Country", "country", "textfield", NULL, 1),
- array("Gender", "gender", "selection", "male\nfemale", 1),
- array("Job title", "job", "textfield", NULL, 0),
- array("ICQ messenger ID", "icq", "textfield", NULL, 0),
- array("MSN messenger ID", "msn", "textfield", NULL, 0),
- array("Yahoo messenger ID", "yahoo", "textfield", NULL, 0),
- array("AIM messenger ID", "aim", "textfield", NULL, 0),
- array("URL of homepage", "homepage", "url", NULL, 1),
- array("Biography", "biography", "textarea", NULL, 0),
- array("Interests", "interests", "textarea", NULL, 0),
- array("Public key", "publickey", "textarea", NULL, 0)
- );
-
- // Remove existing data (debug mode):
- db_query('DELETE FROM {profile_fields}');
- db_query('DELETE FROM {profile_values}');
+ // Load the user record:
+ $account = user_load(array('uid' => $account->uid));
+ $edit = array();
+ // Modify the user record:
foreach ($fields as $field) {
- db_query("INSERT INTO {profile_fields} (title, name, type, category, options, overview) VALUES ('%s', '%s', '%s', 'Personal information', '%s', %d)", $field[0], $field[1], $field[2], $field[3], $field[4]);
+ $old = "profile_". $field[1];
+ $new = $field[1];
+ if ($account->$old) {
+ $edit[$new] = $account->$old;
+ }
+ unset($account->$old);
}
- if ($GLOBALS["db_type"] == "mysql") {
- db_query("ALTER TABLE {users} ADD picture varchar(255) NOT NULL DEFAULT ''");
+ // Birthday format change:
+ if ($edit['birthday']) {
+ $edit['birthday'] = array('day' => $edit['birthday'], 'month' => $account->profile_birthmonth, 'year' => $account->profile_birthyear);
+ unset($account->profile_birthmonth);
+ unset($account->profile_birthyear);
}
- else {
- db_query("ALTER TABLE {users} ADD picture varchar(255)");
- db_query("UPDATE {users} SET picture = ''");
- db_query("ALTER TABLE {users} ALTER COLUMN picture SET NOT NULL");
- db_query("ALTER TABLE {users} ALTER COLUMN picture SET DEFAULT ''");
- }
-
- $result = db_query("SELECT uid FROM {users} WHERE uid > 0");
- while ($account = db_fetch_object($result)) {
- // Load the user record:
- $account = user_load(array('uid' => $account->uid));
- $edit = array();
-
- // Modify the user record:
- foreach ($fields as $field) {
- $old = "profile_". $field[1];
- $new = $field[1];
- if ($account->$old) {
- $edit[$new] = $account->$old;
- }
- unset($account->$old);
- }
-
- // Gender specific changes:
- if ($edit['gender'] == 'f') $edit['gender'] = 'female';
- if ($edit['gender'] == 'm') $edit['gender'] = 'male';
- // Avatar specific changes:
- if ($account->profile_avatar) {
- $edit['picture'] = $account->profile_avatar;
- }
- unset($account->profile_avatar);
+ // Gender specific changes:
+ if ($edit['gender'] == 'f') $edit['gender'] = 'female';
+ if ($edit['gender'] == 'm') $edit['gender'] = 'male';
- // Save the update record:
- user_save($account, $edit, 'Personal information');
+ // Avatar specific changes:
+ if ($account->profile_avatar) {
+ $edit['picture'] = $account->profile_avatar;
}
+ unset($account->profile_avatar);
+
+ // Save the update record:
+ user_save($account, $edit);
+ }
return $ret;
}