Commit 2d9a0b9c authored by webchick's avatar webchick

Issue #2414651 by phenaproxima, quietone, miguelc303, mikeryan, benjy:...

Issue #2414651 by phenaproxima, quietone, miguelc303, mikeryan, benjy: Migration Files for Drupal 7 Users
parent b302b657
......@@ -31,6 +31,15 @@ public function query() {
->condition('fc.storage_active', 1);
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
// Optionally filter by entity type and bundle.
if (isset($this->configuration['entity_type'])) {
$query->condition('entity_type', $this->configuration['entity_type']);
if (isset($this->configuration['bundle'])) {
$query->condition('bundle', $this->configuration['bundle']);
}
}
return $query;
}
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Base class for D7 source plugins which need to collect field values from
* the Field API.
*/
abstract class FieldableEntity extends DrupalSqlBase {
/**
* Returns all non-deleted field instances attached to a specific entity type.
*
* @param string $entity_type
* The entity type ID.
* @param string|NULL $bundle
* (optional) The bundle.
*
* @return array[]
* The field instances, keyed by field name.
*/
protected function getFields($entity_type, $bundle = NULL) {
return $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('entity_type', $entity_type)
->condition('bundle', isset($bundle) ? $bundle : $entity_type)
->condition('deleted', 0)
->execute()
->fetchAllAssoc('field_name');
}
/**
* Retrieves field values for a single field of a single entity.
*
* @param string $entity_type
* The entity type.
* @param string $field
* The field name.
* @param int $entity_id
* The entity ID.
* @param int|null $revision_id
* (optional) The entity revision ID.
*
* @return array
* The raw field values, keyed by delta.
*
* @todo Support multilingual field values.
*/
protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL) {
$table = (isset($revision_id) ? 'field_revision_' : 'field_data_') . $field;
$query = $this->select($table, 't')
->fields('t')
->condition('entity_type', $entity_type)
->condition('entity_id', $entity_id)
->condition('deleted', 0);
if (isset($revision_id)) {
$query->condition('revision_id', $revision_id);
}
$values = [];
foreach ($query->execute() as $row) {
foreach ($row as $key => $value) {
$delta = $row['delta'];
if (strpos($key, $field) === 0) {
$column = substr($key, strlen($field) + 1);
$values[$delta][$column] = $value;
}
}
}
return $values;
}
}
......@@ -140,8 +140,25 @@ public function load() {
'init',
'data',
))
->execute();
->values(array(
'uid' => '2',
'name' => 'Odo',
'pass' => '$S$DZ4P7zZOh92vgrgZDBbv8Pu6lQB337OJ1wsOy21602G4A5F7.M9K',
'mail' => 'odo@local.host',
'theme' => '',
'signature' => '',
'signature_format' => 'filtered_html',
'created' => '1440532218',
'access' => '0',
'login' => '0',
'status' => '1',
'timezone' => 'America/Chicago',
'language' => '',
'picture' => '0',
'init' => 'odo@local.host',
'data' => 'a:1:{s:7:"contact";i:1;}',
))->execute();
}
}
#c4f52bf31f5fe27b4742639dea21039a
#b33078324746c718e26c067131e97dcd
......@@ -123,7 +123,7 @@ public function load() {
'value' => 's:43:"_vWFj-dRR2rNoHDwl7N__J9uZNutDcLz3w4tlPJzRAM";',
))->values(array(
'name' => 'cron_last',
'value' => 'i:1432653550;',
'value' => 'i:1440523817;',
))->values(array(
'name' => 'css_js_query_string',
'value' => 's:6:"nihmmw";',
......@@ -150,7 +150,7 @@ public function load() {
'value' => 's:43:"9eRJWxrMwQ5CufYJjXBZbPGz_t8vPIYRQr18PamdKmM";',
))->values(array(
'name' => 'email__active_tab',
'value' => 's:25:"edit-email-password-reset";',
'value' => 's:27:"edit-email-pending-approval";',
))->values(array(
'name' => 'field_bundle_settings_comment__comment_node_test_content_type',
'value' => 'a:2:{s:10:"view_modes";a:0:{}s:12:"extra_fields";a:2:{s:4:"form";a:2:{s:6:"author";a:1:{s:6:"weight";s:2:"-2";}s:7:"subject";a:1:{s:6:"weight";s:2:"-1";}}s:7:"display";a:0:{}}}',
......@@ -393,61 +393,61 @@ public function load() {
'value' => 'i:86400;',
))->values(array(
'name' => 'user_mail_cancel_confirm_body',
'value' => "s:381:\"[user:name],\r\n\r\nA request to cancel your account has been made at [site:name].\r\n\r\nYou may now cancel your account on [site:url-brief] by clicking this link or copying and pasting it into your browser:\r\n\r\n[user:cancel-url]\r\n\r\nNOTE: The cancellation of your account is not reversible.\r\n\r\nThis link expires in one day and nothing will happen if it is not used.\r\n\r\n-- [site:name] team\";",
'value' => 's:55:"A little birdie said you wanted to cancel your account.";',
))->values(array(
'name' => 'user_mail_cancel_confirm_subject',
'value' => 's:59:"Account cancellation request for [user:name] at [site:name]";',
'value' => 's:13:"Are you sure?";',
))->values(array(
'name' => 'user_mail_password_reset_body',
'value' => "s:407:\"[user:name],\r\n\r\nA request to reset the password for your account has been made at [site:name].\r\n\r\nYou may now log in by clicking this link or copying and pasting it to your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.\r\n\r\n-- [site:name] team\";",
'value' => "s:32:\"Nope! You're locked out forever.\";",
))->values(array(
'name' => 'user_mail_password_reset_subject',
'value' => 's:60:"Replacement login information for [user:name] at [site:name]";',
'value' => 's:17:"Fix your password";',
))->values(array(
'name' => 'user_mail_register_admin_created_body',
'value' => "s:476:\"[user:name],\r\n\r\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password.\r\n\r\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\r\n\r\nusername: [user:name]\r\npassword: Your password\r\n\r\n-- [site:name] team\";",
'value' => 's:30:"...and she could take it away.";',
))->values(array(
'name' => 'user_mail_register_admin_created_subject',
'value' => 's:58:"An administrator created an account for you at [site:name]";',
'value' => 's:24:"Gawd made you an account";',
))->values(array(
'name' => 'user_mail_register_no_approval_required_body',
'value' => "s:450:\"[user:name],\r\n\r\nThank you for registering at [site:name]. You may now log in by clicking this link or copying and pasting it to your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password.\r\n\r\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\r\n\r\nusername: [user:name]\r\npassword: Your password\r\n\r\n-- [site:name] team\";",
'value' => 's:59:"You can now log in if you can figure out how to use Drupal!";',
))->values(array(
'name' => 'user_mail_register_no_approval_required_subject',
'value' => 's:46:"Account details for [user:name] at [site:name]";',
'value' => 's:8:"Welcome!";',
))->values(array(
'name' => 'user_mail_register_pending_approval_body',
'value' => "s:287:\"[user:name],\r\n\r\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\r\n\r\n\r\n-- [site:name] team\";",
'value' => 's:61:"...you will join our Circle. Let the Drupal flow through you.";',
))->values(array(
'name' => 'user_mail_register_pending_approval_subject',
'value' => 's:71:"Account details for [user:name] at [site:name] (pending admin approval)";',
'value' => 's:7:"Soon...";',
))->values(array(
'name' => 'user_mail_status_activated_body',
'value' => "s:461:\"[user:name],\r\n\r\nYour account at [site:name] has been activated.\r\n\r\nYou may now log in by clicking this link or copying and pasting it into your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password.\r\n\r\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\r\n\r\nusername: [user:name]\r\npassword: Your password\r\n\r\n-- [site:name] team\";",
'value' => 's:57:"Your account was activated, and there was much rejoicing.";',
))->values(array(
'name' => 'user_mail_status_activated_notify',
'value' => 'i:1;',
))->values(array(
'name' => 'user_mail_status_activated_subject',
'value' => 's:57:"Account details for [user:name] at [site:name] (approved)";',
'value' => 's:25:"Your account is approved!";',
))->values(array(
'name' => 'user_mail_status_blocked_body',
'value' => "s:85:\"[user:name],\r\n\r\nYour account on [site:name] has been blocked.\r\n\r\n-- [site:name] team\";",
'value' => 's:72:"You no longer please the robot overlords. Go to your room and chill out.";',
))->values(array(
'name' => 'user_mail_status_blocked_notify',
'value' => 'i:0;',
'value' => 'i:1;',
))->values(array(
'name' => 'user_mail_status_blocked_subject',
'value' => 's:56:"Account details for [user:name] at [site:name] (blocked)";',
'value' => 's:7:"BEGONE!";',
))->values(array(
'name' => 'user_mail_status_canceled_body',
'value' => "s:86:\"[user:name],\r\n\r\nYour account on [site:name] has been canceled.\r\n\r\n-- [site:name] team\";",
'value' => 's:75:"The gates of Drupal are closed to you. Now you will work in the salt mines.";',
))->values(array(
'name' => 'user_mail_status_canceled_notify',
'value' => 'i:0;',
'value' => 'i:1;',
))->values(array(
'name' => 'user_mail_status_canceled_subject',
'value' => 's:57:"Account details for [user:name] at [site:name] (canceled)";',
'value' => 's:12:"So long, bub";',
))->values(array(
'name' => 'user_pictures',
'value' => 'i:1;',
......@@ -479,4 +479,4 @@ public function load() {
}
}
#dbc0f593050ff48cc18dfa4fed47daaf
#502534c5e998ee5c14f5a2d510b9dc85
......@@ -139,14 +139,14 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'd6_url_alias',
'd6_user_mail',
'd6_user_contact_settings',
'd6_user_profile_field_instance',
'd6_user_profile_entity_display',
'd6_user_profile_entity_form_display',
'd6_user_profile_field',
'd6_user_picture_entity_display',
'd6_user_picture_entity_form_display',
'd6_user_picture_field_instance',
'd6_user_picture_field',
'user_profile_field_instance',
'user_profile_entity_display',
'user_profile_entity_form_display',
'user_profile_field',
'user_picture_entity_display',
'user_picture_entity_form_display',
'user_picture_field_instance',
'user_picture_field',
'd6_user_picture_file',
'd6_user_role',
'd6_user_settings',
......
......@@ -38,9 +38,9 @@ migrate.source.d6_user_picture_instance:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d6_profile_field:
migrate.source.profile_field:
type: migrate_source_sql
label: 'Drupal 6 profile field'
label: 'Profile field'
mapping:
constants:
type: migrate_entity_constant
......
......@@ -15,6 +15,6 @@ destination:
migration_dependencies:
required:
- d6_user
- d6_user_profile_field_instance
- d6_user_profile_entity_display
- d6_user_profile_entity_form_display
- user_profile_field_instance
- user_profile_entity_display
- user_profile_entity_form_display
id: d6_user_mail
label: Drupal 6 user mail configuration
label: User mail configuration
migration_tags:
- Drupal 6
source:
......
id: d7_user
label: Drupal 7 user accounts
migration_tags:
- Drupal 7
builder:
plugin: d7_user
source:
plugin: d7_user
process:
uid: uid
name: name
pass: pass
mail: mail
created: created
access: access
login: login
status: status
timezone: timezone
langcode: language
preferred_langcode: language
preferred_admin_langcode: language
init: init
roles:
plugin: migration
migration: d7_user_role
source: roles
user_picture: picture
destination:
plugin: entity:user
migration_dependencies:
required:
- d7_user_role
optional:
- d7_file
- user_picture_field_instance
- user_picture_entity_display
- user_picture_entity_form_display
id: d7_user_flood
migration_tags:
- Drupal 7
source:
plugin: variable
variables:
- user_failed_login_identifier_uid_only
- user_failed_login_ip_limit
- user_failed_login_ip_window
- user_failed_login_user_window
- user_failed_login_user_limit
process:
uid_only: user_failed_login_identifier_uid_only
ip_limit: user_failed_login_ip_limit
ip_window: user_failed_login_ip_window
user_limit: user_failed_login_user_limit
user_window: user_failed_login_user_window
destination:
plugin: config
config_name: user.flood
id: d7_user_mail
label: User mail configuration
migration_tags:
- Drupal 7
source:
plugin: variable
variables:
- user_mail_status_activated_subject
- user_mail_status_activated_body
- user_mail_password_reset_subject
- user_mail_password_reset_body
- user_mail_status_canceled_subject
- user_mail_status_canceled_body
- user_mail_register_admin_created_subject
- user_mail_register_admin_created_body
- user_mail_register_no_approval_required_subject
- user_mail_register_no_approval_required_body
- user_mail_register_pending_approval_subject
- user_mail_register_pending_approval_body
- user_mail_status_blocked_subject
- user_mail_status_blocked_body
process:
'status_activated/subject': user_mail_status_activated_subject
'status_activated/body': user_mail_status_activated_body
'password_reset/subject': user_mail_password_reset_subject
'password_reset/body': user_mail_password_reset_body
'cancel_confirm/subject': user_mail_status_canceled_subject
'cancel_confirm/body': user_mail_status_canceled_body
'register_admin_created/subject': user_mail_register_admin_created_subject
'register_admin_created/body': user_mail_register_admin_created_body
'register_no_approval_required/subject': user_mail_register_no_approval_required_subject
'register_no_approval_required/body': user_mail_register_no_approval_required_body
'register_pending_approval/subject': user_mail_register_pending_approval_subject
'register_pending_approval/body': user_mail_register_pending_approval_body
'status_blocked/subject': user_mail_status_blocked_subject
'status_blocked/body': user_mail_status_blocked_body
destination:
plugin: config
config_name: user.mail
id: d7_user_role
label: Drupal 7 user roles
migration_tags:
- Drupal 7
source:
plugin: d7_user_role
process:
id:
-
plugin: machine_name
source: name
-
plugin: dedupe_entity
entity_type: user_role
field: id
length: 32
-
plugin: user_update_8002
label: name
permissions:
-
plugin: static_map
source: permissions
bypass: true
map:
'use PHP for block visibility': 'use PHP for settings'
'administer site-wide contact form': 'administer contact forms'
'post comments without approval': 'skip comment approval'
'edit own blog entries' : 'edit own blog content'
'edit any blog entry' : 'edit any blog content'
'delete own blog entries' : 'delete own blog content'
'delete any blog entry' : 'delete any blog content'
'create forum topics' : 'create forum content'
'delete any forum topic' : 'delete any forum content'
'delete own forum topics' : 'delete own forum content'
'edit any forum topic' : 'edit any forum content'
'edit own forum topics' : 'edit own forum content'
- plugin: flatten
weight: weight
destination:
plugin: entity:user_role
migration_dependencies:
optional:
- d7_filter_format
id: d6_user_picture_entity_display
label: Drupal 6 user picture display configuration
id: user_picture_entity_display
label: User picture display configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_user_picture_instance
plugin: user_picture_instance
constants:
entity_type: user
bundle: user
......@@ -27,4 +28,4 @@ destination:
plugin: component_entity_display
migration_dependencies:
required:
- d6_user_picture_field_instance
- user_picture_field_instance
id: d6_user_picture_entity_form_display
label: Drupal 6 user picture form display configuration
id: user_picture_entity_form_display
label: User picture form display configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_user_picture_instance
plugin: user_picture_instance
constants:
entity_type: user
bundle: user
......@@ -26,4 +27,4 @@ destination:
plugin: component_entity_form_display
migration_dependencies:
required:
- d6_user_picture_field_instance
- user_picture_field_instance
id: d6_user_picture_field
label: Drupal 6 user picture field configuration
id: user_picture_field
label: User picture field configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
# We do an empty source and a proper destination to have an idmap for
# dependencies.
......
id: d6_user_picture_field_instance
label: Drupal 6 user picture field instance configuration
id: user_picture_field_instance
label: User picture field instance configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_user_picture_instance
plugin: user_picture_instance
constants:
entity_type: user
bundle: user
......@@ -27,4 +28,4 @@ destination:
plugin: entity:field_config
migration_dependencies:
required:
- d6_user_picture_field
- user_picture_field
id: d6_user_profile_entity_display
label: Drupal 6 user profile display configuration
id: user_profile_entity_display
label: User profile display configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_profile_field
plugin: profile_field
constants:
entity_type: user
bundle: user
......
id: d6_user_profile_entity_form_display
label: Drupal 6 user profile form display configuration
id: user_profile_entity_form_display
label: User profile form display configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_profile_field
plugin: profile_field
constants:
empty: {}
entity_type: user
......
id: d6_user_profile_field
label: Drupal 6 user profile field configuration
id: user_profile_field
label: User profile field configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_profile_field
plugin: profile_field
constants:
entity_type: user
process:
......@@ -21,7 +22,7 @@ process:
textarea: text_long
url: link
settings:
plugin: d6_profile_field_settings
plugin: profile_field_settings
source: type
'settings/allowed_values': options
cardinality:
......
id: d6_user_profile_field_instance
label: Drupal 6 user profile field instance configuration
id: user_profile_field_instance
label: User profile field instance configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: d6_profile_field
plugin: profile_field
constants:
entity_type: user
bundle: user
......@@ -18,4 +19,4 @@ destination:
plugin: entity:field_config
migration_dependencies:
required:
- d6_user_profile_field
- user_profile_field
......@@ -24,7 +24,7 @@ public function buildMigrations(array $template) {
// @TODO The source plugin should accept a database connection.
// @see https://www.drupal.org/node/2552791
$source_plugin = $this->getSourcePlugin('d6_profile_field', $template['source']);
$source_plugin = $this->getSourcePlugin('profile_field', $template['source']);
try {
$source_plugin->checkRequirements();
}
......
<?php
/**
* @file
* Contains \Drupal\user\Plugin\migrate\builder\d7\User.
*/
namespace Drupal\user\Plugin\migrate\builder\d7;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @PluginID("d7_user")
*/
class User extends BuilderBase implements ContainerFactoryPluginInterface {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a d7_user builder plugin instance.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('module_handler')
);
}
/**
* {@inheritdoc}
*/
public function buildMigrations(array $template) {
$migration = Migration::create($template);
if ($this->moduleHandler->moduleExists('field')) {
$template['source']['entity_type'] = 'user';
$source_plugin = $this->getSourcePlugin('d7_field_instance', $template['source']);
foreach ($source_plugin as $field) {
$field_name = $field->getSourceProperty('field_name');
$migration->setProcessOfProperty($field_name, $field_name);
}
}
try {
$profile_fields = $this->getSourcePlugin('profile_field', $template['source']);
// Ensure that Profile is enabled in the source DB.
$profile_fields->checkRequirements();
foreach ($profile_fields as $field) {
$field_name = $field->getSourceProperty('name');
$migration->setProcessOfProperty($field_name, $field_name);
}
}
catch (RequirementsException $e) {
// Profile is not enabled in the source DB, so don't do anything.
}
return [$migration];
}
}