Index: ./modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.37 diff -u -p -r1.37 system.install --- ./modules/system/system.install 29 Oct 2006 15:13:01 -0000 1.37 +++ ./modules/system/system.install 2 Nov 2006 01:53:01 -0000 @@ -3375,6 +3375,113 @@ function system_update_1014() { return array(); } +function system_update_1015() { + // TODO pgsql is not done yet + // TODO can the functions CONCAT and MD5 be used on pgsql ? + // TODO salt = char 16 ?? not too big ? + // TODO add extra checks ? + // TODO Does the update script check if uid 1 is logged in ? Doesn't that give a problem ? + // TODO How to handle a rerun of the script (add a DROP TABLE {users_new} to make sure it doesn't exist before creating a new one ??) + $ret = array(); + $limit = 50; + + // Multi-part update + if (!isset($_SESSION['system_update_1015'])) { + $_SESSION['system_update_1015'] = 0; + $_SESSION['system_update_1015_max'] = db_result(db_query('SELECT MAX(uid) FROM {users}')); + $_SESSION['system_update_1015_copy_start'] = 0; + $_SESSION['system_update_1015_ret'] = array(); + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {users_new} ( + uid int unsigned NOT NULL default '0', + name varchar(60) NOT NULL default '', + pass varchar(32) NOT NULL default '', + salt varchar(8) NOT NULL default '', + mail varchar(64) default '', + mode tinyint NOT NULL default '0', + sort tinyint default '0', + threshold tinyint default '0', + theme varchar(255) NOT NULL default '', + signature varchar(255) NOT NULL default '', + created int NOT NULL default '0', + access int NOT NULL default '0', + login int NOT NULL default '0', + status tinyint NOT NULL default '0', + timezone varchar(8) default NULL, + language varchar(12) NOT NULL default '', + picture varchar(255) NOT NULL DEFAULT '', + init varchar(64) default '', + data longtext, + PRIMARY KEY (uid), + UNIQUE KEY name (name), + KEY access (access) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {users_new} ( + uid serial CHECK (uid >= 0), + name varchar(60) NOT NULL default '', + pass varchar(32) NOT NULL default '', + salt varchar(8) NOT NULL default '', + mail varchar(64) default '', + mode smallint NOT NULL default '0', + sort smallint default '0', + threshold smallint default '0', + theme varchar(255) NOT NULL default '', + signature varchar(255) NOT NULL default '', + created int NOT NULL default '0', + access int NOT NULL default '0', + login int NOT NULL default '0', + status smallint NOT NULL default '0', + timezone varchar(8) default NULL, + language varchar(12) NOT NULL default '', + picture varchar(255) NOT NULL DEFAULT '', + init varchar(64) default '', + data text, + PRIMARY KEY (uid), + UNIQUE (name) + )"); + break; + } + // uid 0 is the anonymous user (without any password or salt) + $ret[] = update_sql("INSERT INTO {users_new} (uid,name,mail) VALUES(0,'','')"); + } + else { + $ret = $_SESSION['system_update_1015_ret']; + } + + if ($_SESSION['system_update_1015_copy_start'] <= $_SESSION['system_update_1015_max']) { + $range_end = $_SESSION['system_update_1015_copy_start'] + $limit; + db_query("INSERT INTO {users_new} (uid, name, pass, salt, mail, mode, sort, threshold, theme, signature, created, access, login, status, timezone, language, picture, init, data) SELECT uid, name, MD5(CONCAT(SUBSTRING(MD5(created),1,8), pass)), MD5(created), mail, mode, sort, threshold, theme, signature, created, access, login, status, timezone, language, picture, init, data FROM {users} WHERE uid > %d AND uid <= %d", $_SESSION['system_update_1015_copy_start'], $range_end); + $_SESSION['system_update_1015_copy_start'] = $range_end; + $_SESSION['system_update_1015_ret'] = $ret; + // Report percentage finished (make sure we never get 100% in this stage) + return array('#finished' => ($_SESSION['system_update_1015_copy_start'] / ($_SESSION['system_update_1015_max'] + $limit + 1))); + } + else { + // check the user_new table: number of rows OK ? + $count_old = db_result(db_query('SELECT COUNT(uid) FROM {users}')); + $count_new = db_result(db_query('SELECT COUNT(uid) FROM {users_new}')); + if ($count_old == $count_new) { + $ret[] = update_sql('DROP TABLE {users}'); + $ret[] = update_sql('RENAME TABLE {users_new} to {users}'); + unset($_SESSION['system_update_1015']); + unset($_SESSION['system_update_1015_copy_start']); + unset($_SESSION['system_update_1015_max']); + unset($_SESSION['system_update_1015_ret']); + return $ret; + } + else { + $ret[] = array('success' => false, 'query' => t('Adding salt to users table failed - not all rows are copied to temporary table user_new.')); + return $ret; + } + } +} + /** * @} End of "defgroup updates-4.7-to-x.x" * The next series of updates should start at 2000.