Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / user / src / Plugin / migrate / destination / EntityUser.php
index b5317beb8ceb619e09b60526a09a6e58077a63f3..316d063bf7426912d5ad351f8b94b1fc55d5fbdc 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Drupal\user\Plugin\migrate\destination;
 
-use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\ContentEntityInterface;
 use Drupal\Core\Entity\EntityManagerInterface;
 use Drupal\Core\Entity\EntityStorageInterface;
@@ -15,6 +14,52 @@ use Drupal\migrate\Row;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
+ * Provides a destination plugin for migrating user entities.
+ *
+ * Example:
+ *
+ * The example below migrates users and preserves original passwords from a
+ * source that has passwords as MD5 hashes without salt. The passwords will be
+ * salted and re-hashed before they are saved to the destination Drupal
+ * database. The MD5 hash used in the example is a hash of 'password'.
+ *
+ * The example uses the EmbeddedDataSource source plugin for the sake of
+ * simplicity. The mapping between old user_ids and new Drupal uids is saved in
+ * the migration map table.
+ * @code
+ * id: custom_user_migration
+ * label: Custom user migration
+ * source:
+ *   plugin: embedded_data
+ *   data_rows:
+ *     -
+ *       user_id: 1
+ *       name: johnsmith
+ *       mail: johnsmith@example.com
+ *       hash: '5f4dcc3b5aa765d61d8327deb882cf99'
+ *   ids:
+ *     user_id:
+ *       type: integer
+ * process:
+ *   name: name
+ *   mail: mail
+ *   pass: hash
+ *   status:
+ *     plugin: default_value
+ *     default_value: 1
+ * destination:
+ *   plugin: entity:user
+ *   md5_passwords: true
+ * @endcode
+ *
+ * For configuration options inherited from the parent class, refer to
+ * \Drupal\migrate\Plugin\migrate\destination\EntityContentBase.
+ *
+ * The example above is about migrating an MD5 password hash. For more examples
+ * on different password hash types and a list of other user properties, refer
+ * to the handbook documentation:
+ * @see https://www.drupal.org/docs/8/api/migrate-api/migrate-destination-plugins-examples/migrating-users
+ *
  * @MigrateDestination(
  *   id = "entity:user"
  * )
@@ -122,8 +167,8 @@ class EntityUser extends EntityContentBase {
     if (is_array($name)) {
       $name = reset($name);
     }
-    if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) {
-      $row->setDestinationProperty('name', Unicode::substr($name, 0, USERNAME_MAX_LENGTH));
+    if (mb_strlen($name) > USERNAME_MAX_LENGTH) {
+      $row->setDestinationProperty('name', mb_substr($name, 0, USERNAME_MAX_LENGTH));
     }
   }