1

I am working on my first migration from D7 to D8. I am trying to keep it very simple and start with users. I have created a custom module migrate_custom, created my definition at config/install/migrate.migration.d7cafe_users.yml:

id: d7cafe_users
label: User accounts
migration_tags:
  - Drupal 7
source:
  plugin: d7cafe_users
destination:
  plugin: entity:user
process:
  uid: uid
  name: name
  pass: pass
  mail: mail
  created: created
  access: access
  login: login
  status: status
  timezone: timezone
  langcode: language
  init: init 

Then I have my source plugin at src/plugin/migrate/source/User.php:

<?php
/**
 * @file
 * Contains \Drupal\migrate_custom\Plugin\migrate\source\User.
 */

namespace Drupal\migrate_custom\Plugin\migrate\source;

use Drupal\migrate\Plugin\migrate\source\SqlBase;

/**
 * Extract users from Drupal 7 database.
 *
 * @MigrateSource(
 *   id = "d7cafe_users"
 * )
 */
class User extends SqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    return $this->select('dcf_users', 'dcf_u')
      ->fields('dcf_u', ['uid', 'status', 'created','access', 'login',    'name',
        'pass', 'mail', 'init', 'language']);
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = [
      'uid' => $this->t('Account ID'),
      'status' => $this->t('Blocked/Allowed'),
      'created' => $this->t('Registered date'),
      'access' => $this->t('Time of last access'),
      'login' => $this->t('Time of last login'),
      'name' => $this->t('Account name (for login)'),
      'pass' => $this->t('Account password (raw)'),
      'mail' => $this->t('Account email'),
      'init' => $this->t('init'),
      'language' => $this->t('language'),
    ];

    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    return [
      'uid' => [
        'type' => 'integer',
        'alias' => 'dcf_u',
      ],
    ];
  }

}
?>

And finally I have a manifest.yml file containing:

- d7cafe_users

I run the migration with:

drush migrate-manifest manifest.yml --legacy-db-url=mysql://root:root@localhost/d7cafe

But all I get on command line is:

Running d7cafe_users                                                                                                                                                         [ok]
Processed 0 items (0 created, 0 updated, 0 failed, 0 ignored) - done with 'd7cafe_users' 

I don't think I'm far off, as I could see running it and importing the 4 users from the legacy db, but did a bit of fiddling on the definition file and now I can't get it back to importing records. What is wrong with my code?

1

Ok I tried it on a new site install and the code works and migrates users perfectly. All I can think of is that db got corrupted after running migration and rolling back a number of times.

  • It would be better to keep a backup before running migration so that you can restore in this situation instead of reinstalling same site again and again. Take a backup using "drupal dbdu" and restore same backup using "drupal dbr --file=name_of_backup_file.sql" – Yogesh Kushwaha Jun 27 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.