0

I have a Migrate module class that works with CSV files and when I go through with the import it only goes through the first line of the CSV and then completes with a success message. That one line is imported correctly and the data is in place, but I'm wondering why it continues to stop at the first line.

When I run the import again it does not import anything and completes with success message again, mostly likely because the first line is already imported.

Any ideas?

class UserMigration extends MyMigration {
  public function __construct($arguments) {
    parent::__construct($arguments);

    $this->description = t('Import Users');
    $columns = array(
      0 => array('username', 'Username'),
      2 => array('email', 'Email'),
    );

    $this->source = new MigrateSourceCSV(drupal_get_path('module', 'my_module') . '/Users.csv', $columns);
    $this->destination = new MigrateDestinationUser();
    $this->addFieldMapping('name', 'username');
    $this->addFieldMapping('mail', 'email');
    $this->addFieldMapping('roles')
         ->defaultValue(DRUPAL_AUTHENTICATED_RID);
    $source_key = array(
      'username' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      )
    );
    $this->map = new MigrateSQLMap($this->machineName, $source_key, MigrateDestinationUser::getKeySchema());

  }
}
  • 2
    Is it possible that the CSV is saved with line endings in the wrong format? Be default, I think Migrate expects Unix format. – Dave Bruns Nov 13 '13 at 18:58
  • @DaveBruns I believe that would be culprit. I've been having issues with these CSVs as they are saved from Server '03 and I'm on a Mac. I will re-generate the files on this machine and try again. – CR47 Nov 13 '13 at 19:06
  • 1
    @DaveBruns Re-generating the file with Uniux file endings worked perfectly. You may want to make this an answer to the question so I can accept it. – CR47 Nov 13 '13 at 19:47
2

It's possible that the CSV is saved with the wrong line endings. Try saving the CSV file with Unix-style line endings. By default, I believe Migrate expects a Unix format text file.

|improve this answer|||||

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.