diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/actions.test | 6 | ||||
-rw-r--r-- | modules/simpletest/tests/database_test.test | 27 | ||||
-rw-r--r-- | modules/system/system.install | 67 | ||||
-rw-r--r-- | modules/trigger/trigger.test | 7 | ||||
-rw-r--r-- | modules/user/user.install | 3 | ||||
-rw-r--r-- | modules/user/user.module | 5 |
6 files changed, 76 insertions, 39 deletions
diff --git a/modules/simpletest/tests/actions.test b/modules/simpletest/tests/actions.test index 12a97cc5f..7cc06b558 100644 --- a/modules/simpletest/tests/actions.test +++ b/modules/simpletest/tests/actions.test @@ -37,11 +37,13 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { // Make another POST request to the action edit page. $this->clickLink(t('configure')); + preg_match('|admin/config/system/actions/configure/(\d+)|', $this->getUrl(), $matches); + $aid = $matches[1]; $edit = array(); $new_action_label = $this->randomName(); $edit['actions_label'] = $new_action_label; $edit['url'] = 'admin'; - $this->drupalPost('admin/config/system/actions/configure/1', $edit, t('Save')); + $this->drupalPost(NULL, $edit, t('Save')); // Make sure that the action updated properly. $this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action.")); @@ -51,7 +53,7 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { // Make sure that deletions work properly. $this->clickLink(t('delete')); $edit = array(); - $this->drupalPost('admin/config/system/actions/delete/1', $edit, t('Delete')); + $this->drupalPost("admin/config/system/actions/delete/$aid", $edit, t('Delete')); // Make sure that the action was actually deleted. $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), t('Make sure that we get a delete confirmation message.')); diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 8d400e68c..d64ee9ed0 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -2981,3 +2981,30 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase { } + +/** + * Check the sequences API. + */ +class DatabaseNextIdCase extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Sequences API'), + 'description' => t('Test the secondary sequences API.'), + 'group' => t('Database'), + ); + } + + /** + * Test that the sequences API work. + */ + function testDbNextId() { + $first = db_next_id(); + $second = db_next_id(); + // We can test for exact increase in here because we know there is no + // other process operating on these tables -- normally we could only + // expect $second > $first. + $this->assertEqual($first + 1, $second, t('The second call from a sequence provides a number increased by one.')); + $result = db_next_id(1000); + $this->assertEqual($result, 1001, t('Sequence provides a larger number than the existing ID.')); + } +} diff --git a/modules/system/system.install b/modules/system/system.install index 97f8e6724..4e5496f90 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -352,23 +352,19 @@ function system_install() { // Load system theme data appropriately. system_rebuild_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_insert('users') ->fields(array( + 'uid' => 0, 'name' => '', 'mail' => '', )) ->execute(); // 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. - + // presumed to be a serialized array. This will be changed by the settings + // form. db_insert('users') ->fields(array( + 'uid' => 1, 'name' => 'placeholder-for-uid-1', 'mail' => 'placeholder-for-uid-1', 'created' => REQUEST_TIME, @@ -376,19 +372,6 @@ function system_install() { 'data' => serialize(array()), )) ->execute(); - // This sets the above two users uid 0 (anonymous). We avoid an explicit 0 - // otherwise MySQL might insert the next auto_increment value. - db_update('users') - ->expression('uid', 'uid - uid') - ->condition('name', '') - ->execute(); - - // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem. - db_update('users') - ->fields(array('uid' => 1)) - ->condition('name', 'placeholder-for-uid-1') - ->execute(); - // Built-in roles. $rid_anonymous = db_insert('role') ->fields(array('name' => 'anonymous user')) @@ -615,19 +598,6 @@ function system_schema() { 'primary key' => array('aid'), ); - $schema['actions_aid'] = array( - 'description' => 'Stores action IDs for non-default actions.', - 'fields' => array( - 'aid' => array( - 'description' => 'Primary Key: Unique actions ID.', - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, - ), - ), - 'primary key' => array('aid'), - ); - $schema['batch'] = array( 'description' => 'Stores details about batches (processes that run in multiple HTTP requests).', 'fields' => array( @@ -1451,6 +1421,19 @@ function system_schema() { 'primary key' => array('name'), ); + $schema['sequences'] = array( + 'description' => 'Stores IDs.', + 'fields' => array( + 'value' => array( + 'description' => 'The value of the sequence.', + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + ), + 'primary key' => array('value'), + ); + $schema['sessions'] = array( 'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.", 'fields' => array( @@ -2866,6 +2849,22 @@ function system_update_7043() { } /** + * Reuse the actions_aid table as sequences. + */ +function system_update_7043() { + db_drop_primary_key('actions_aid'); + db_change_field('actions_aid', 'aid', 'value', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('value'))); + db_rename_table('actions_aid', 'sequences'); + $max = db_query('SELECT MAX(value) FROM {sequences}')->fetchField(); + $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField(); + if ($max_uid > $max) { + db_update('sequences')->fields(array('value' => $max_uid))->execute(); + } + $max = db_query('SELECT MAX(value) FROM {sequences}')->fetchField(); + db_delete('sequences')->condition('value', $max, '<'); +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */ diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 7204dc395..d7732fe02 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -151,7 +151,10 @@ class TriggerCronTestCase extends DrupalWebTestCase { 'subject' => $action_label, ); $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save')); - $edit = array('aid' => md5('1')); + $aid = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'trigger_test_system_cron_conf_action'))->fetchField(); + // $aid is likely 3 but if we add more uses for the sequences table in + // core it might break, so it is easier to get the value from the database. + $edit = array('aid' => md5($aid)); $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign')); // Add a second configurable action to the cron trigger. @@ -161,7 +164,7 @@ class TriggerCronTestCase extends DrupalWebTestCase { 'subject' => $action_label, ); $this->drupalPost('admin/config/system/actions/configure/' . $hash, $edit, t('Save')); - $edit = array('aid' => md5('2')); + $edit = array('aid' => md5($aid + 1)); $this->drupalPost('admin/structure/trigger/system', $edit, t('Assign')); // Force a cron run. diff --git a/modules/user/user.install b/modules/user/user.install index 610d3d566..2b93e4e68 100644 --- a/modules/user/user.install +++ b/modules/user/user.install @@ -102,10 +102,11 @@ function user_schema() { 'description' => 'Stores user data.', 'fields' => array( 'uid' => array( - 'type' => 'serial', + 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: Unique user ID.', + 'default' => 0, ), 'name' => array( 'type' => 'varchar', diff --git a/modules/user/user.module b/modules/user/user.module index fe75f1c7b..48140a862 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -448,6 +448,11 @@ function user_save($account, $edit = array(), $category = 'account') { user_module_invoke('update', $edit, $user, $category); } else { + // Allow 'uid' to be set by the caller. There is no danger of writing an + // existing user as drupal_write_record will do an INSERT. + if (empty($edit['uid'])) { + $edit['uid'] = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); + } // Allow 'created' to be set by the caller. if (!isset($edit['created'])) { $edit['created'] = REQUEST_TIME; |