Issue #2673960 by Jo Fitzgerald, hussainweb, phenaproxima, mikeryan, quietone, vasi: Unable to migrate D7 User cck fields

8.3.x
Alex Pott 2017-01-17 11:22:02 +00:00
parent 05b64e0748
commit b84471234f
6 changed files with 156 additions and 14 deletions

View File

@ -4485,6 +4485,18 @@ $connection->insert('field_data_field_file')
'field_file_display' => '1',
'field_file_description' => 'file desc',
))
->values(array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'field_file_fid' => '2',
'field_file_display' => '1',
'field_file_description' => 'file desc',
))
->execute();
$connection->schema()->createTable('field_data_field_float', array(
@ -6674,6 +6686,18 @@ $connection->insert('field_revision_field_file')
'field_file_display' => '1',
'field_file_description' => 'file desc',
))
->values(array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'field_file_fid' => '2',
'field_file_display' => '1',
'field_file_description' => 'file desc',
))
->execute();
$connection->schema()->createTable('field_revision_field_float', array(
@ -8307,6 +8331,16 @@ $connection->insert('file_managed')
'status' => '1',
'timestamp' => '1421727515',
))
->values(array(
'fid' => '2',
'uid' => '1',
'filename' => 'ds9.txt',
'uri' => 'public://ds9.txt',
'filemime' => 'text/plain',
'filesize' => '4720',
'status' => '1',
'timestamp' => '1421727516',
))
->execute();
$connection->schema()->createTable('file_usage', array(
@ -8375,6 +8409,13 @@ $connection->insert('file_usage')
'id' => '1',
'count' => '1',
))
->values(array(
'fid' => '2',
'module' => 'file',
'type' => 'user',
'id' => '2',
'count' => '1',
))
->execute();
$connection->schema()->createTable('filter', array(

View File

@ -45,7 +45,7 @@ class MigrateUpgrade7Test extends MigrateUpgradeTestBase {
'editor' => 2,
'field_config' => 49,
'field_storage_config' => 37,
'file' => 1,
'file' => 2,
'filter_format' => 7,
'image_style' => 6,
'language_content_settings' => 2,

View File

@ -0,0 +1,79 @@
__ ___ ___
,' ,' | | `. `.
,' ,' |===| `. `.
/ // |___| \\ \
/ // |___| \\ \
//// |___| \\\\
/ / || || \ \
/ / || || \ \
/| | || || | |\
|| | | : o : | | ||
| \| | .===. | |/ |
| |\ /| (___) |\ /| |
|__||.\ .-. // /,_._,\ \\ .-. /.||__|
|__||_.\ `-.\ //_ [:(|):] _\\ /.-' /._||__|
__/| ||___`._____ ___\\__/___/_ ||| _\___\__//___ _____.'___||_ |\__
/___//__________/.-/_____________|.-.|_____________\-.\__________\\___\
\___\\__\\\_____\`-\__\\\\__\____|_-_|____/_//_____/-'/__//______//__//
\|__||__..' // \ _ \__|||__/ _ / \\ `..__||__|/
|__||_./ .-'/ \\ |(|)| // \`-. \..||__|
| || / `-' \\ \'/ // `-' \ || |
| |/ \| :(-): |/ \| |
| /| | : o : | |\ |
|| | | |___| | | ||
\| | || || | |/
\ \ || || / /
\ \ ||___|| / /
\\\\ |___| ////
\ \\ |___| // /
\ \\ | | // /
`. `. |===| ,' ,'
`._`. |___| ,'_,'
_ _
_____---' \_n_/ `---_____
_ / ... ----------- ... \ _
( )-' . '::.\__ V __/.::' . `-( )
_ .-' ':::. ____ \ / ____ .:::' `-. _
,-'.`' __.--' \ | | / `--.__ `'.`-.
/ ''::.. \ || || / ..::'' \
/ ..... ,'\,' ||_|| `./`. ..... \
/ :::::' ,' | | `. '::::: \
| '::: ,' | | `. :::' |
_/ :: / |___| \ :: \_
(/ / ,-' `-. \ \)
_/ `. ,-' ooo oo `-. ,' \_
| /`./ ,-'\ /`-. \.'\ |
| .: / / \ \_ __.---.__ _/ / \ \ :. |
.' :;: | _ / o \[ ' \ / ` ]/ \ _ | ::: `.
| ':: | ( `-. / | | \ ,-' ) | ::' |
|: ': | `-./ / ___ \ \,-' | :' :|
.':: ' | | / `-. .-' . `-. .-' \ o | | ' ::`.
| ::. | | o ,| `-. / \`_|_'/ \ .-' |. o | | .:: |
\ |_ |____| | ` / \ ' | |____| _| /
(| _] ]____[ |- ( (O) ) -| ]____[ [_ |)
/.: | | | | . \_ _/ . | | | | :.\
| :' | | o `|-,-' \ /..|..\ / `-.-|' o | |. ': |
`. :: | | o \ .-' `-.___.-' `-. / o | | :: .'
| .:: | _.\ \| | | \/ /._ | ::. |
| ': | _.-' \ o \ | | / o / `-._ | :' |
`. __ |__.-'_ _.\ /[_.__ | | __._]\ o /._ _`-.__| __ .'
| \ \_.--''.' .-' \ / / `---' \ \ / `-. `.``--__/ / |
|_\ __ ,',-' `-./ o \,-' `-.`. __ /_|
\\ / .',' `-. oo .-. oo ,-' `.`. \ //
(\\ \ \ `-._| |_,-' / / //)
\\ ) \ (_) / ( //
/ \/ `. ,' \/ \
\ .::. `. ,' .::: /
\ ':::. `-./`. .'\.-' '''''' /
\ ''' /_ _ _\ ::.. /
`-.'::' `--.______| |______.--' ,-'
`-'`-._ .. .: .: _,-'`'
(_)-. ::. '':::: :::::: : ,-(_)
\_____ '' _ _ ' _____/
---._/ u \_.---
Used with permission from:
Orbital Space Station (Terok Nor - Deep Space 9) - Joe Reiss
https://startrekasciiart.blogspot.co.uk/2011/05/deep-space-nine.html

View File

@ -48,6 +48,7 @@ migration_dependencies:
required:
- d7_user_role
optional:
- d7_field_instance
- d7_file
- language
- default_language

View File

@ -3,19 +3,12 @@
namespace Drupal\user\Plugin\migrate;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\Migration;
use Drupal\migrate_drupal\Plugin\migrate\CckMigration;
/**
* Plugin class for Drupal 7 user migrations dealing with fields and profiles.
*/
class User extends Migration {
/**
* Flag indicating whether the CCK data has been filled already.
*
* @var bool
*/
protected $init = FALSE;
class User extends CckMigration {
/**
* {@inheritdoc}
@ -33,7 +26,21 @@ class User extends Migration {
$field_migration = $this->migrationPluginManager->createStubMigration($definition);
foreach ($field_migration->getSourcePlugin() as $row) {
$field_name = $row->getSourceProperty('field_name');
$this->process[$field_name] = $field_name;
$field_type = $row->getSourceProperty('type');
if (empty($field_type)) {
continue;
}
if ($this->cckPluginManager->hasDefinition($field_type)) {
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
}
$info = $row->getSource();
$this->cckPluginCache[$field_type]
->processCckFieldValues($this, $field_name, $info);
}
else {
$this->process[$field_name] = $field_name;
}
}
}
try {

View File

@ -109,10 +109,12 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
* Role IDs the user account is expected to have.
* @param int $field_integer
* The value of the integer field.
* @param int|false $field_file_target_id
* (optional) The target ID of the file field.
* @param bool $has_picture
* Whether the user is expected to have a picture attached.
* (optional) Whether the user is expected to have a picture attached.
*/
protected function assertEntity($id, $label, $mail, $password, $created, $access, $login, $blocked, $langcode, $timezone, $init, $roles, $field_integer, $has_picture = FALSE) {
protected function assertEntity($id, $label, $mail, $password, $created, $access, $login, $blocked, $langcode, $timezone, $init, $roles, $field_integer, $field_file_target_id = FALSE, $has_picture = FALSE) {
/** @var \Drupal\user\UserInterface $user */
$user = User::load($id);
$this->assertTrue($user instanceof UserInterface);
@ -155,6 +157,10 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
$this->assertTrue($user->hasField('field_integer'));
$this->assertEquals($field_integer[0], $user->field_integer->value);
}
if (!empty($field_file_target_id)) {
$this->assertTrue($user->hasField('field_file'));
$this->assertSame($field_file_target_id, $user->field_file->target_id);
}
}
/**
@ -190,6 +196,13 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
->fetchCol();
$field_integer = !empty($field_integer) ? $field_integer : NULL;
$field_file = Database::getConnection('default', 'migrate')
->select('field_data_field_file', 'ff')
->fields('ff', ['field_file_fid'])
->condition('ff.entity_id', $source->uid)
->execute()
->fetchField();
$this->assertEntity(
$source->uid,
$source->name,
@ -203,7 +216,8 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
$source->timezone,
$source->init,
$roles,
$field_integer
$field_integer,
$field_file
);
// Ensure that the user can authenticate.