Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.

This commit is contained in:
Pantheon Automation 2015-11-17 13:42:33 -08:00 committed by Greg Anderson
parent 4afb23bbd3
commit 7784f4c23d
929 changed files with 19798 additions and 5304 deletions

View file

@ -17,7 +17,7 @@ migrate.source.d6_user:
migrate.source.d6_user_picture_file:
type: migrate_source_sql
label: 'Drupal 6 user picure display'
label: 'Drupal 6 user picture display'
mapping:
constants:
type: mapping
@ -29,7 +29,7 @@ migrate.source.d6_user_picture_file:
migrate.source.d6_user_picture_instance:
type: migrate_source_sql
label: 'Drupal 6 user picure display'
label: 'Drupal 6 user picture display'
mapping:
provider:
type: string

View file

@ -27,6 +27,7 @@ class UserRouteProvider implements EntityRouteProviderInterface {
'_entity_view' => 'user.full',
'_title_callback' => 'Drupal\user\Controller\UserController::userTitle',
])
->setRequirement('user', '\d+')
->setRequirement('_entity_access', 'user.view');
$route_collection->add('entity.user.canonical', $route);
@ -36,6 +37,7 @@ class UserRouteProvider implements EntityRouteProviderInterface {
'_title_callback' => 'Drupal\user\Controller\UserController::userTitle',
])
->setOption('_admin_route', TRUE)
->setRequirement('user', '\d+')
->setRequirement('_entity_access', 'user.update');
$route_collection->add('entity.user.edit_form', $route);
@ -45,6 +47,7 @@ class UserRouteProvider implements EntityRouteProviderInterface {
'_entity_form' => 'user.cancel',
])
->setOption('_admin_route', TRUE)
->setRequirement('user', '\d+')
->setRequirement('_entity_access', 'user.delete');
$route_collection->add('entity.user.cancel_form', $route);

View file

@ -168,6 +168,42 @@ class UserSelection extends DefaultSelection {
return $query;
}
/**
* {@inheritdoc}
*/
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$user = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
// In order to create a referenceable user, it needs to be active.
if (!$this->currentUser->hasPermission('administer users')) {
/** @var \Drupal\user\UserInterface $user */
$user->activate();
}
return $user;
}
/**
* {@inheritdoc}
*/
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
// Mirror the conditions checked in buildEntityQuery().
if (!empty($this->configuration['handler_settings']['filter']['role'])) {
$entities = array_filter($entities, function ($user) {
/** @var \Drupal\user\UserInterface $user */
return !empty(array_intersect($user->getRoles(), $this->configuration['handler_settings']['filter']['role']));
});
}
if (!$this->currentUser->hasPermission('administer users')) {
$entities = array_filter($entities, function ($user) {
/** @var \Drupal\user\UserInterface $user */
return $user->isActive();
});
}
return $entities;
}
/**
* {@inheritdoc}
*/

View file

@ -7,8 +7,11 @@
namespace Drupal\user\Plugin\migrate\destination;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem;
use Drupal\Core\Password\PasswordInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateException;
@ -50,11 +53,13 @@ class EntityUser extends EntityContentBase {
* The migrate plugin manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager service.
* @param \Drupal\Core\Password\PasswordInterface $password
* The password service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, PasswordInterface $password) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager);
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
if (isset($configuration['md5_passwords'])) {
$this->password = $password;
}
@ -73,6 +78,7 @@ class EntityUser extends EntityContentBase {
$container->get('entity.manager')->getStorage($entity_type),
array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('password')
);
}
@ -90,6 +96,10 @@ class EntityUser extends EntityContentBase {
throw new MigrateException('Password service has been altered by another module, aborting.');
}
}
// Do not overwrite the root account password.
if ($row->getDestinationProperty('uid') == 1) {
$row->removeDestinationProperty('pass');
}
$ids = parent::import($row, $old_destination_id_values);
if ($this->password) {
$this->password->disableMd5Prefixing();
@ -98,4 +108,28 @@ class EntityUser extends EntityContentBase {
return $ids;
}
/**
* {@inheritdoc}
*/
protected function processStubRow(Row $row) {
parent::processStubRow($row);
// Email address is not defined as required in the base field definition but
// is effectively required by the UserMailRequired constraint. This means
// that Entity::processStubRow() did not populate it - we do it here.
$field_definitions = $this->entityManager
->getFieldDefinitions($this->storage->getEntityTypeId(),
$this->getKey('bundle'));
$mail = EmailItem::generateSampleValue($field_definitions['mail']);
$row->setDestinationProperty('mail', reset($mail));
// @todo Work-around for https://www.drupal.org/node/2602066.
$name = $row->getDestinationProperty('name');
if (is_array($name)) {
$name = reset($name);
}
if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) {
$row->setDestinationProperty('name', Unicode::substr($name, 0, USERNAME_MAX_LENGTH));
}
}
}

View file

@ -0,0 +1,116 @@
<?php
/**
* @file
* Contains \Drupal\user\Tests\Migrate\MigrateUserAdminPassTest.
*/
namespace Drupal\user\Tests\Migrate;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Tests\MigrateTestBase;
use Drupal\user\Entity\User;
/**
* Tests preservation of root account password.
*
* @group user
*/
class MigrateUserAdminPassTest extends MigrateTestBase {
/**
* The passwords as retrieved from the account entities before migration.
*
* @var array
*/
protected $originalPasswords = [];
/**
* Modules to enable.
*
* @var string[]
*/
public static $modules = ['user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Make sure the admin user and a regular user are created.
$this->container->get('module_handler')->loadInclude('user', 'install');
$this->installEntitySchema('user');
user_install();
/** @var \Drupal\user\Entity\User $admin_account */
$admin_account = User::load(1);
$admin_account->setPassword('original');
$admin_account->save();
$this->originalPasswords[1] = $admin_account->getPassword();
/** @var \Drupal\user\Entity\User $user_account */
$user_account = User::create([
'uid' => 2,
'name' => 'original_username',
'mail' => 'original_email@example.com',
'pass' => 'original_password',
]);
$user_account->save();
$this->originalPasswords[2] = $user_account->getPassword();
}
/**
* Tests preserving the admin user's password.
*/
public function testAdminPasswordPreserved() {
$user_data_rows = [
[
'id' => '1',
'username' => 'site_admin',
'password' => 'new_password',
'email' => 'site_admin@example.com',
],
[
'id' => '2',
'username' => 'random_user',
'password' => 'random_password',
'email' => 'random_user@example.com',
],
];
$ids = ['id' => ['type' => 'integer']];
$config = [
'id' => 'users',
'migration_tags' => ['Admin password test'],
'source' => [
'plugin' => 'embedded_data',
'data_rows' => $user_data_rows,
'ids' => $ids,
],
'process' => [
'uid' => 'id',
'name' => 'username',
'mail' => 'email',
'pass' => 'password',
],
'destination' => ['plugin' => 'entity:user'],
];
$migration = Migration::create($config);
$this->executeMigration($migration);
// Verify that admin username and email were changed, but password was not.
/** @var \Drupal\user\Entity\User $admin_account */
$admin_account = User::load(1);
$this->assertIdentical($admin_account->getUsername(), 'site_admin');
$this->assertIdentical($admin_account->getEmail(), 'site_admin@example.com');
$this->assertIdentical($admin_account->getPassword(), $this->originalPasswords[1]);
// Verify that everything changed for the regular user.
/** @var \Drupal\user\Entity\User $user_account */
$user_account = User::load(2);
$this->assertIdentical($user_account->getUsername(), 'random_user');
$this->assertIdentical($user_account->getEmail(), 'random_user@example.com');
$this->assertNotIdentical($user_account->getPassword(), $this->originalPasswords[2]);
}
}

View file

@ -0,0 +1,43 @@
<?php
/**
* @file
* Contains \Drupal\user\Tests\Migrate\MigrateUserStubTest.
*/
namespace Drupal\user\Tests\Migrate;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
use Drupal\migrate_drupal\Tests\StubTestTrait;
/**
* Test stub creation for user entities.
*
* @group user
*/
class MigrateUserStubTest extends MigrateDrupalTestBase {
use StubTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installSchema('system', ['sequences']);
}
/**
* Tests creation of user stubs.
*/
public function testStub() {
$this->performStubTest('user');
}
}

View file

@ -119,8 +119,11 @@ class MigrateUserTest extends MigrateDrupal6TestBase {
}
// Use the API to check if the password has been salted and re-hashed to
// conform the Drupal >= 7.
$this->assertTrue(\Drupal::service('password')->check($source->pass_plain, $user->getPassword()));
// conform to Drupal >= 7 for non-admin users.
if ($user->id() != 1) {
$this->assertTrue(\Drupal::service('password')
->check($source->pass_plain, $user->getPassword()));
}
}
// Rollback the migration and make sure everything is deleted but uid 1.
(new MigrateExecutable($this->migration, $this))->rollback();

View file

@ -176,7 +176,7 @@ class UserValidationTest extends KernelTestBase {
$user->roles[1]->target_id = 'unknown_role';
$violations = $user->validate();
$this->assertEqual(count($violations), 1);
$this->assertEqual($violations[0]->getPropertyPath(), 'roles.1');
$this->assertEqual($violations[0]->getPropertyPath(), 'roles.1.target_id');
$this->assertEqual($violations[0]->getMessage(), t('The referenced entity (%entity_type: %name) does not exist.', array('%entity_type' => 'user_role', '%name' => 'unknown_role')));
}

View file

@ -138,6 +138,7 @@ user.cancel_confirm:
hashed_pass: ''
requirements:
_entity_access: 'user.delete'
user: \d+
user.reset:
path: '/user/reset/{uid}/{timestamp}/{hash}'