I am migrating a Drupal 7 site to an updated Drupal 7 site. The nodes and taxonomies on the old site were handled in custom tables.

I have migrated 2,000 nodes and that worked fine. My taxonomy terms have also been imported. I now have a custom table of 87,000 instances of terms being applied to the nodes over seven different term reference and entity reference fields.

When I try to run the term migration I get the error: System-of-record is DESTINATION, but no destination nid provided. I have seen this error elsewhere but have not solved my problem by looking at these other issues.

This is my node migration:

class MyNodeWebMigration extends MyMigration {
    public function __construct($arguments) {
        parent::__construct($arguments);
        $this->description = t('Web Reports v2');

        $query = Database::getConnection('default', 'datasource')
            ->select('my_data_group', 'sdg');
        $query->fields('sdg', array('groupid', 'name', 'description', 'notes', 'grp_level',
            'level1', 'level2', 'submitted', 'published', 'approver_notes', 'preprocessed',
            'themeid', 'public_health_significance', 'target_event', 'talking_points',
            'report_type', 'nid'));

        $count_query = Database::getConnection('default', 'datasource')
            ->select('my_data_group', 'sdg');
        $count_query->addExpression('COUNT(groupid)', 'cnt');

        $this->source = new MigrateSourceSQL($query, array(), NULL,
            array('map_joinable' => FALSE));

        // Set up our destination - nodes of type web_ready
        $this->destination = new MigrateDestinationNode('web_ready');

        $this->map = new MigrateSQLMap($this->machineName,
            array(
                'groupid' => array(
                    'type' => 'int',
                    'not null' => TRUE,
                    'description' => 'Report Group ID.',
                    'alias' => 'sdg',
                )
            ),
            MigrateDestinationNode::getKeySchema()
        );

        // Mapped fields
        $this->addFieldMapping('title', 'name')
            ->description(t('Mapping Report name in source to node title'));
        $this->addFieldMapping('status', 'published');
        $this->addFieldMapping('field_group_id', 'groupid');
        $this->addFieldMapping('body', 'description');
    }
}

This is the second migration I am using to import the terms into the fields on my nodes:

class MyReportTypeTermToWebMigration extends CMyMigration {
    public function __construct($arguments) {
        parent::__construct($arguments);
        $this->description = t('Imports Report Type Terms Into Web Reports');

        $query = Database::getConnection('default', 'datasource')
            ->select('my_data_meta', 'sdm');
        $query->fields('sdm', array('groupid', 'vocab', 'tid'))
            ->condition('vocab', 'report_doc_type');

        $count_query = Database::getConnection('default', 'datasource')
            ->select('my_data_meta', 'sdm');
        $count_query->addExpression('COUNT(groupid)', 'cnt');

        $this->source = new MigrateSourceSQL($query, array(), NULL,
            array('map_joinable' => FALSE));

        $this->systemOfRecord = Migration::DESTINATION;

        // Set up our destination - nodes of type web_ready
        $this->destination = new MigrateDestinationNode('web_ready');

        $this->map = new MigrateSQLMap($this->machineName,
            array(
                'groupid' => array(
                    'type' => 'int',
                    'not null' => TRUE,
                    'description' => 'Report Group ID.',
                    'alias' => 'sdg',
                )
            ),
            MigrateDestinationNode::getKeySchema()
        );

        // Mapped fields
        $this->addFieldMapping('nid', 'groupID')
            ->sourceMigration('CBHSQNodeWebReady');
        $this->addFieldMapping('field_report_doc_type', 'tid')
            ->separator(',')
            // Note this is the machine name of the user migration.
            ->sourceMigration('CBHSQTermReportDocType');

    }
}

When I run this second migration I get the error in the title of this issue. Any help would be greatly appreciated.

Comments

gettysburger created an issue. See original summary.

gettysburger’s picture

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

This issue might have a clue about using destid1 in the prepareRow() function.

gettysburger’s picture

I made some progress. I added this:

    public function prepareRow($row) {
        // Always include this fragment at the beginning of every prepareRow()
        // implementation, so parent classes can ignore rows.
        if (parent::prepareRow($row) === FALSE) {
            return FALSE;
        }
        // if the destination is not mapped in migrate we tell him where to go
        if (!isset($row->migrate_map_destid1) && isset($row->groupid)) {
            $row->migrate_map_destid1 = $row->groupid;
        }
    }

...and now at least I get a different error:

Incoming node ID 163 no longer exists
Incoming node ID 164 no longer exists
Incoming node ID 165 no longer exists
Incoming node ID 166 no longer exists
Incoming node ID 167 no longer exists
Incoming node ID 170 no longer exists
Incoming node ID 171 no longer exists
Incoming node ID 172 no longer exists
Incoming node ID 173 no longer exists
Incoming node ID 174 no longer exists
Incoming node ID 175 no longer exists
Incoming node ID 176 no longer exists
Incoming node ID 177 no longer exists
Incoming node ID 178 no longer exists
Incoming node ID 179 no longer exists
Incoming node ID 180 no longer exists
Incoming node ID 181 no longer exists
Incoming node ID 182 no longer exists
Incoming node ID 183 no longer exists
Incoming node ID 184 no longer exists

...which means I simply need to figure out a way to map the source groupid to the nid using the MyNodeWebReady migration class.

Does that sound correct?

gettysburger’s picture

Solved it! Here is the solution. I used a query to explicitly associate the source data with the target node.

    public function prepareRow($row) {
        // Always include this fragment at the beginning of every prepareRow()
        // implementation, so parent classes can ignore rows.
         if (parent::prepareRow($row) === FALSE) {
             return FALSE;
         }
        // if the destination is not mapped in migrate we tell him where to go
        if (!isset($row->migrate_map_destid1)) {
            $query = db_select('migrate_map_mynodewebready', 'mmc', array('fetch' => PDO::FETCH_ORI_FIRST));
            $query->addField('mmc', 'destid1');
            $query->condition('sourceid1', $row->groupid);
            $result = $query->execute();
            $result = $result->fetchAssoc();
            $row->migrate_map_destid1 = $result['destid1'];
        }
    }
gettysburger’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.