Drupal migrate: Update some fields on all users of drupal.

Created on 19 October 2023, over 1 year ago

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?

💬 Support request
Status

Active

Version

9.5

Component
Other 

Last updated about 12 hours ago

Created by

🇻🇳Vietnam elnavut

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue was unassigned.
  • Status changed to Postponed: needs info 4 months ago
  • 🇳🇿New Zealand quietone

    The Drupal Core issue queue is not the ideal place for support requests. The 'support request' option is there for filing support issues for contributed modules and themes. There are several support options listed on our support page (Community > Support at the top of Drupal.org) and there is Drupal Slack . You may get better replies in one of those places.

    Has this been resolved?

  • Status changed to Closed: works as designed 6 days ago
  • 🇳🇿New Zealand quietone

    There is no discussion here and as pointed out there are better places to get support for Drupal core.

    Therefor, closing this issue.

Production build 0.71.5 2024