Problem/Motivation
Hello
<!--break-->
I'm working with drupal version "9.5.11" and need to update a few fields for all drupal users. My current task is to get the user list from firebase and update it to the corresponding user according to uid.
<!--break-->
Below is my code
<!--break-->
yml
id: firebase_users
label: 'Firebase Users'
migration_group: legacy
source:
plugin: 'firebase_users'
destination:
plugin: 'entity:user'
key: uid # Unique ID field in the source
process:
field_image_url:
plugin: entity_lookup
source: photoURL
entity_type: user
bundle: user
migration_dependencies:
required:
- module_auth
FirebaseUsers.php
<?php
/**
*
* @MigrateSource(
* id = "firebase_users"
* )
*/
class FirebaseUsers extends SourcePluginBase {
/**
* Prints the query string when the object is used as a string.
*
* @return string
* The query string.
*/
public function __toString() {
return "\Drupal::service('module.firebase')->listAuthUsers()";
}
/**
* {@inheritdoc}
*/
public function initializeIterator() {
$firebase = \Drupal::service('module.firebase');
$users = $firebase->listAuthUsers();
// Return an iterator over the source data.
foreach ($users as $user) {
$status = false;
yield [
'name' => $user->displayName,
'email' => $user->email,
'status' => $status,
'uid' => $user->uid,
'photoURL' => 'https://domain.com/image.png',
];
}
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'uid' => [
'type' => 'string',
],
];
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'email' => $this->t('Email'),
'name' => $this->t('Name'),
'roles' => $this->t('Roles'),
'isActive' => $this->t('Active'),
'uid' => $this->t('Uid'),
'field_image_url' => $this->t('Image Url'),
];
return $fields;
}
}
Is there any effective solution to this problem?