summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--install.php9
-rw-r--r--modules/system/system.install94
2 files changed, 52 insertions, 51 deletions
diff --git a/install.php b/install.php
index b3e2fbcbf..63a0e146f 100644
--- a/install.php
+++ b/install.php
@@ -969,8 +969,13 @@ function install_configure_form_submit($form, &$form_state) {
variable_set('user_email_verification', FALSE);
$form_state['old_values'] = $form_state['values'];
$form_state['values'] = $form_state['values']['account'];
- user_register_submit($form, $form_state);
- db_query("INSERT INTO {users} (uid, name, mail) VALUES(%d, '%s', '%s')", 0, '', '');
+
+ // We precreated user 1 with placeholder values. Let's save the real values.
+ $account = user_load(1);
+ $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1);
+ user_save($account, array_merge($form_state['values'], $merge_data));
+ // Log in the first user.
+ user_authenticate($form_state['values']['name'], trim($form_state['values']['pass']));
$form_state['values'] = $form_state['old_values'];
unset($form_state['old_values']);
variable_set('user_email_verification', TRUE);
diff --git a/modules/system/system.install b/modules/system/system.install
index fea6533a5..29917cab0 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -195,60 +195,42 @@ function system_requirements($phase) {
* Implementation of hook_install().
*/
function system_install() {
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- // As of Drupal 6, users.uid is an auto-incrementing column, but
- // previously it was not. Below, we insert a row with uid 0 to
- // represent user anonymous. By default, mysql treats that as
- // requesting the next sequence value which, of course, is uid
- // 1! This statement turns off that behavior for the duration
- // of the current request, which is all we need.
- //
- // Note that this statement must be run any time the uid column
- // is inserted or altered. That includes loading mysqldump
- // backups, but mysqldump puts this statement in all backups for
- // this exact reason. It also includes any Schema API
- // table-altering operations on the users table.
- db_query("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");
- break;
- case 'pgsql':
- /* create unsigned types */
- db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
- db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
- db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
-
- /* create functions */
- db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
- \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
- LANGUAGE \'sql\''
- );
- db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
- \'SELECT greatest($1, greatest($2, $3));\'
+ if ($GLOBALS['db_type'] == 'pgsql') {
+ /* create unsigned types */
+ db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
+ db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
+ db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
+
+ /* create functions */
+ db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
+ \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
+ LANGUAGE \'sql\''
+ );
+ db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
+ \'SELECT greatest($1, greatest($2, $3));\'
+ LANGUAGE \'sql\''
+ );
+ if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) {
+ db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
+ \'SELECT random();\'
LANGUAGE \'sql\''
);
- if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) {
- db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
- \'SELECT random();\'
- LANGUAGE \'sql\''
- );
- }
+ }
- if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) {
- db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
- \'SELECT $1 || $2;\'
- LANGUAGE \'sql\''
- );
- }
- db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS
- \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
+ if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) {
+ db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
+ \'SELECT $1 || $2;\'
LANGUAGE \'sql\''
);
- db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS
- \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
- LANGUAGE \'sql\''
- );
- break;
+ }
+ db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS
+ \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
+ LANGUAGE \'sql\''
+ );
+ db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS
+ \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
+ LANGUAGE \'sql\''
+ );
}
// Create tables.
@@ -260,6 +242,20 @@ function system_install() {
// Load system theme data appropriately.
system_theme_data();
+ // Inserting uid 0 here confuses MySQL -- the next user might be created as
+ // uid 2 which is not what we want. So we insert the first user here, the
+ // anonymous user. uid is 1 here for now, but very soon it will be changed
+ // to 0.
+ db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');
+ // We need some placeholders here as name and mail are uniques and data is
+ // presumed to be a serialized array. Install will change uid 1 immediately
+ // anyways. So we insert the superuser here, the uid is 2 here for now, but
+ // very soon it will be changed to 1.
+ db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array()));
+ // This sets the above two users to 1 -1 = 0 (anonymous) and
+ // 2- 1 = 1 (superuser). We skip uid 2 but that's not a big problem.
+ db_query('UPDATE {users} SET uid = uid - 1');
+
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');