4

I am attempting to use the migrate module to bring in data from another web application. There are several fields that are related and the first one I'm working with is languages. I can import the languages as taxonomy terms without problems. The BiblioMigration class imports most of the data without problems also. Unfortunately, no matter what I seem to do it fails to import anything into the "field_biblio_language" field. I have manually edited and created a node and placed a value into this field and it works fine. It is just the import that seems to produce nothing. According to the detail section for the Biblio Migration the language field is properly mapped. I have attempted to structure the code around this in several different ways but always end up with nothing. I have even attempted to pass a default value and it still fails to populate the table. Any help would be much appreciated.

class LanguageMigration extends Migration {
  public function __construct() {
    parent::__construct();

    $this->description = t('Migrate languages from the source database to taxonomy terms');

    $this->map = new MigrateSQLMap($this->machineName,
        array(
          'name' => array('type' => 'varchar',
                           'length' => 255,
                           'not null' => TRUE,
                           'description' => 'Language',
                          )
        ),
        MigrateDestinationTerm::getKeySchema()
      );

    $query = db_select('matrix_language', 'l')
             ->fields('l', array('id', 'name'));

    // Create a MigrateSource object, which manages retrieving the input data.
    $this->source = new MigrateSourceSQL($query);

    // Set up our destination - terms in the migrate_example_beer_styles vocabulary
    $this->destination = new MigrateDestinationTerm('language');
    $this->addFieldMapping('name', 'name');

  }
}

class BiblioMigration extends Migration {
  public function __construct() {
    // Put the migration into a group for each content type
    parent::__construct(MigrateGroup::getInstance('bibliographia'));

    // Query the original database
    $query = db_select('matrix_biblio', 'biblio')
      ->fields('biblio', array(
        'id',
        'primaryauthor',
        'role',
        'additionalauthors',
        'title',
        'titlealphaorder',
        'publishedin',
        'publisher',
        'citation',
        'languageid',
        'date',
        'notes',
        'bibliotypeid',
        'sourcetypeid',
        'publicationstatus',
        'archivelocation',
        'created',
        'lastmodified',
        'lastmodifiedby',
        'adminnotes',
        'placeofpublication',
        'dateofpublicationnote',
        'hide',
      ));
      $query->orderBy('id', 'DESC');

    // Define our original database query results as our source
    $this->source = new MigrateSourceSQL($query);

    // Define our new content type as our destination
    $this->destination = new MigrateDestinationNode('bibliographia');

    // Map the node id to the id field in our original database, this mapping is needed for rollbacks
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'id' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'alias' => 'biblio',
        )
      ),
      MigrateDestinationNode::getKeySchema()
    );

    // Map our fields desitination -> source
    $this->addFieldMapping('field_biblio_primary_author', 'primaryauthor');
    $this->addFieldMapping('field_biblio_role', 'role');
    $this->addFieldMapping('field_biblio_additional_authors', 'additionalauthors');
    $this->addFieldMapping('title', 'title');
    $this->addFieldMapping('field_biblio_sorting_title', 'titlealphaorder');
    $this->addFieldMapping('field_biblio_published_in', 'publishedin');
    $this->addFieldMapping('field_biblio_publisher', 'publisher');
    $this->addFieldMapping('field_biblio_citation', 'citation');
    //$this->addFieldMapping('field_biblio_language', 'languageid');

       $this->addFieldMapping('field_biblio_language', 'languageid')
            ->sourceMigration('Language')
            ->arguments(array('source_type' => 'tid'));

    $this->addFieldMapping('field_biblio_date', 'date');
    $this->addFieldMapping('field_biblio_notes', 'notes');
    $this->addFieldMapping('field_biblio_publication_type', 'bibliotypeid');
    $this->addFieldMapping('field_biblio_source_type', 'sourcetypeid');
    $this->addFieldMapping('field_biblio_publication_status', 'publicationstatus');
    $this->addFieldMapping('field_biblio_archive_location', 'archivelocation');
    $this->addFieldMapping('field_biblio_record_created', 'created');
    $this->addFieldMapping('field_biblio_last_modified', 'lastmodified');
    $this->addFieldMapping('field_biblio_last_modified_by', 'lastmodifiedby');
    $this->addFieldMapping('field_biblio_admin_notes', 'adminnotes');
    $this->addFieldMapping('field_biblio_place_publication', 'placeofpublication');
    $this->addFieldMapping('field_biblio_date_publication', 'dateofpublicationnote');
    $this->addFieldMapping('field_biblio_hide', 'hide');
  }

}
3

I think you need to define the languageid (id) as MigrateSQLMap identifier (instead of the name) in the LanguageMigration. With the name the mapping is not possible. The rest seems correct:

  $this->map = new MigrateSQLMap($this->machineName,
        array(
          'id' => array('type' => 'int',
                           'length' => 10,
                           'not null' => TRUE,
                           'description' => 'Language',
                          )
        ),
        MigrateDestinationTerm::getKeySchema()
  );

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.