0

I need to migrate users from drupal 6(old site) to drupal 7(new site) alongwith User Profile from Profile module

I am looking at documentation given in migrate module as follows:

https://www.drupal.org/node/415260

On Subsequent pages at After adding new migrations, or making changes to the arguments of previously-registered migrations, if you want them to be recognized by Migrate, you need to:

Clear the Drupal cache, so any new classes are added to the Drupal cache registry. Perform the registration, either with drush migrate-register or by visiting admin/content/migrate/configure and clicking the "Register statically-defined classes" button.

I have created migrate_xyz.info ,migrate_xyz.module and migrate_xyz.migrate.inc files As mentioned above when I move to admin/content/migrate/configure i get a blank screen

Is this the right way to go for migrating users from drupal 6 to drupal 7? Or should I use some other module like migrate_d2d

  • 1
    Well, migrate_d2d also depends on the migrate module. I think you might have missed something while implementing the migration classes. Or it might be a simple syntax error. It is very hard to tell when you get a WSOD. Follow the instructions given at drupal.org/node/158043, to debug what the issue might be. – AjitS Jan 14 '15 at 7:26
  • is migrate_d2d right module to import users via UI or should I go about creating a custom module. I mean is it like using migrate_d2d , i dont need to create a custom module? – harshal Jan 14 '15 at 8:03
1

Check this article . It describes how to use migrate module and it's API. Code from this article:

First of all we need to create module by adding folder with name my_migration adding my_migration.info and my_migration.module files. So lets start, code below will have a lot of comments:

//my_migration.info file

name = "User Migrate"
 description = "Migration of data from Drupal 6 to Drupal 7"
 package = "Custom Migrate"
 core = 7.x
 dependencies[] = migrate
 dependencies[] = migrate_extras
 dependencies[] = field
 dependencies[] = file
 dependencies[] = text
 dependencies[] = path
 dependencies[] = taxonomy

 files[] = includes/users.inc

//my_migration.module file
// this file can be empty but we will define some constants
<!--?php /*
 * Define some constants to use in class
 */
define("SOURCE_DATABASE", 'd6_latest'); // Put drupal 6 db name you should also add settings to settings.php
define("CONNECT_NAME", 'migrate');// name of connection to drupal 6 db in settings.php
define('SOURCE_TERM_GARDEN_CAT', 3); // When we will migrate terms we will use it.
define('SOURCE_URL', 'http://path_to_drupal6.site');
define('MIGRATE67_SITE_DIRECTORY', 'public://');


//my_migrate_migrate.inc you should name this file as module_name_migrate.inc 
// if not your migration won't be autoloaded.
<?php

/**
 * Implements hook_migrate_api().
 */
function my_migrate_migrate_api() {
  $api = array(
    'api' =?--> 2,
    'migrations' => array(
      'MfUserMigrate' => array('class_name' => 'MfUserMigrate'),
    ),
  );

  return $api;
}



//my_migration/users.inc

<!--?php /**
 * User migration class to migrate users.
 */
class UserMigrate extends Migration {
  public function __construct() {
    parent::__construct(MigrateGroup::getInstance('UserMigrate'));
    // Select fields from the Drupal 6 user table.
    $query = Database::getConnection('default', CONNECT_NAME)
      -?-->select('users', 'u')
      ->fields('u', array('uid', 'name', 'pass', 'mail', 'created', 'access',
        'login', 'status', 'picture', 'init'));
    // This is supposed to get roles not sure how.
    $source_fields = array(
      'uid' => t('User ID'),
      'roles' => t('The set of roles assigned to a user.'),
    );
    // Set source and destination.
    $this->source = new MigrateSourceSQL($query, $source_fields);
    $this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
    // Set up database maping.
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'uid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'description' => 'D6 Unique User ID',
          'alias' => 'u',
        )
      ),
      MigrateDestinationUser::getKeySchema()
    );
    // Add simple field mappings
    $this->addFieldMapping('is_new')
      ->defaultValue(TRUE);
    $this->addFieldMapping('uid', 'id_to_preserve');
    $this->addFieldMapping('name', 'name')->dedupe('users', 'name');
    $this->addFieldMapping('pass', 'pass');
    $this->addFieldMapping('mail', 'mail')->dedupe('users', 'mail');
    $this->addFieldMapping('language')->defaultValue('');
    $this->addFieldMapping('theme')->defaultValue('');
    $this->addFieldMapping('signature')->defaultValue('');
    $this->addFieldMapping('signature_format')->defaultValue('filtered_html');
    $this->addFieldMapping('created', 'created');
    $this->addFieldMapping('access', 'access');
    $this->addFieldMapping('login', 'login');
    $this->addFieldMapping('status', 'status');
    $this->addFieldMapping('picture')->defaultValue(0);
    $this->addFieldMapping('init', 'init');
    $this->addFieldMapping('timezone')->defaultValue(NULL);
    $this->addFieldMapping('roles', 'roles');
  }
  // Set up Roles.
  // massage the user roles before saving
  public function prepareRow($current_row) {
    $source_id = $current_row->uid;
    $query = Database::getConnection('default', CONNECT_NAME)
      ->select('users_roles', 'r')
      ->fields('r', array('uid', 'rid'))
      ->havingCondition('r.uid', $source_id, '=');
    $results = $query->execute();
    // add the anonymous role for everyone
    $roles = array('1' => '1');
    foreach ($results as $row) {
      // adjust the old to new role id's
      // Editors (rid 7) need role id 4
      if ($row->rid == 7) {
        $roles['4'] = '4';
      }
      elseif ($row->rid == 4) {
        // producer from 4 to 5
        $roles['5'] = '5';
      }
      elseif ($row->rid == 5) {
        // blogger from 5 to 6
        $roles['6'] = '6';
      }
      elseif ($row->rid == 8) {
        // freelancer 8 to 7
        $roles['7'] = '7';
      }
      else {
        // Collaboraters are role id 5 in both old and new dbs
        $roles[$row->rid] = $row->rid;
      }
    }
    $current_row->roles = $roles;
    return TRUE;
  }
} // close the ourUserMigration class

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.