Commit 902098c7 authored by alexpott's avatar alexpott

Issue #2249113 by tstoeckler, jessebeach: Use an entity save instead of...

Issue #2249113 by tstoeckler, jessebeach: Use an entity save instead of db_insert() in user_install().
parent 177b86ec
......@@ -965,7 +965,7 @@ function install_base_system(&$install_state) {
// Enable the user module so that sessions can be recorded during the
// upcoming bootstrap step.
\Drupal::moduleHandler()->install(array('user'), FALSE);
\Drupal::moduleHandler()->install(array('field', 'user'), FALSE);
// Save the list of other modules to install for the upcoming tasks.
// State can be set to the database now that system.module is installed.
......
......@@ -19,7 +19,7 @@ class UserInstallTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('user');
public static $modules = array('field', 'user');
/**
* {@inheritdoc}
......@@ -51,11 +51,15 @@ public function testUserInstall() {
$this->assertFalse(empty($anon->uuid), 'Anon user has a UUID');
$this->assertFalse(empty($admin->uuid), 'Admin user has a UUID');
$this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id, 'Anon user language is the default.');
$this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id, 'Admin user language is the default.');
// Test that the anonymous and administrators languages are equal to the
// site's default language.
$this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id);
$this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id);
$this->assertEqual($admin->status, 1, 'Admin user is active.');
$this->assertEqual($anon->status, 0, 'Anon user is blocked.');
// Test that the administrator is active.
$this->assertEqual($admin->status, 1);
// Test that the anonymous user is blocked.
$this->assertEqual($anon->status, 0);
}
}
......@@ -99,7 +99,9 @@ function mapFromStorageRecords(array $records) {
* {@inheritdoc}
*/
public function save(EntityInterface $entity) {
if (!$entity->id()) {
// The anonymous user account is saved with the fixed user ID of 0.
// Therefore we need to check for NULL explicitly.
if ($entity->id() === NULL) {
$entity->uid->value = $this->database->nextId($this->database->query('SELECT MAX(uid) FROM {users}')->fetchField());
$entity->enforceIsNew();
}
......
......@@ -6,3 +6,7 @@ version: VERSION
core: 8.x
required: true
configure: user.admin_index
# @todo Remove this field dependency
# @see https://drupal.org/node/2116363
dependencies:
- field
......@@ -220,28 +220,27 @@ function user_schema() {
* Implements hook_install().
*/
function user_install() {
$storage = \Drupal::entityManager()->getStorage('user');
// @todo Rely on the default value for langcode in
// https://drupal.org/node/1966436
$langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
// Insert a row for the anonymous user.
db_insert('users')
->fields(array(
$storage
->create(array(
'uid' => 0,
'uuid' => \Drupal::service('uuid')->generate(),
'name' => '',
'mail' => '',
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,
'status' => 0,
'langcode' => $langcode,
))
->execute();
->save();
// We need some placeholders here as name and mail are uniques.
// This will be changed by the settings form in the installer.
db_insert('users')
->fields(array(
$storage
->create(array(
'uid' => 1,
'uuid' => \Drupal::service('uuid')->generate(),
'name' => 'placeholder-for-uid-1',
'mail' => 'placeholder-for-uid-1',
'created' => REQUEST_TIME,
'status' => 1,
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,
'langcode' => $langcode,
))
->execute();
->save();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment