The transformed value is sent to the ` make_unique_entity_field`. The ` machine_name` plugin converts the `public_name` source column into transliterated string with some restrictions: any character that is not a number or letter will be converted to an underscore. None of the unique source columns (eg., `legacy_id`) is suitable to be used as username. If the source data contained a unique value for each record, it could be used to set the username. The `name`, entity property stores the username. Refer to this page for a list of supported timezones. The `timezone` needs to be a string taken from a specific set of values. The former might change if the user updates its profile, while the latter will never change. The difference is that `mail` stores the current email, while `init` stores the one used when the account was first created. Both `mail` and `init` are email addresses. The `mail`, `init`, and `timezone` entity properties are copied directly from the source. The following snippet shows three mappings: mail: user_email Let’s start with the basics: verbatim copies from source to destination. The specific transformation will depend on your source, but some arguably complex cases will be addressed in the example. The interesting part of a user migration is the field mapping. The following code snippet shows how the destination and dependencies are set: destination: Refer to these articles more information on migrating images and files and setting dependencies. The dependency of user on file is added explicitly. To migrate the profile pictures, a separate migration is created. For more information password migrations refer to these articles for basic and advanced use cases. If it is set to `true`, the system will take an MD5 hashed password and convert it to the encryption algorithm that Drupal uses. When that is the case, you can set an optional `md5_passwords` configuration. The destination section specifies that user is the target entity. Type: integer Configuring the destination and dependencies User_roles: 'forum moderator, forum admin' User_password: 'totally insecure password 1' The following snippet shows a sample record for the source section: source: Second, some elements might be missing in the source like roles and profile picture. First, source passwords are provided in plain text (never do this!). Special measures will be taken to prevent duplication as Drupal usernames must be unique. Instead, a username will be created from a `public_name` source column. Emails were used to uniquely identify users, but that is not desired in the new Drupal site. For this example, it is assumed that the legacy system from which users are being imported did not have unique usernames. This will guide the transformation process required to produce the expected destination format. It is very important to understand the format of your source data. We have covered two of them in the articles about subfields and constants and pseudofields. Note that other techniques exist for migrating images without having to create a separate migration. One motivation to have two migrations is for the images to be deleted if the file migration is rolled back. It depends on a file migration to get the profile pictures. The explanation below is only for the user migration. The word in parenthesis represents the machine name of the image field. Particularly, we depend on a Picture (`user_picture`) image field attached to the user entity. The example assumes Drupal was installed using the `standard` installation profile. Refer to this article to learn where the module should be placed. Notice that both migrations belong to the same module. The two migrations to execute are `udm_user_pictures` and `udm_users`. You can get the full code example at The module to enable is `UD users` whose machine name is `ud_migrations_users`. Feel free to read other posts in the series if you need a refresher. Therefore, no explanation is provided about the file migration to keep the focus on the user migration. This topic has been explained in detail in a previous post, and the example code is pretty similar. For instance, a file migration is included to import images used as profile pictures. For example, making sure that usernames are not duplicated.Īlthough the example is standalone, we will build on many of the concepts that had already been covered in the series. Several techniques will be implemented to ensure that the migrated data is valid. In the next one, we will cover creation date, roles, and profile pictures. In this one, we cover the migration of email, timezone, username, password, and status. The example code will be explained in two blog posts. Today we are going to learn how to migrate users into Drupal.
0 Comments
Leave a Reply. |