I have a use case where during the migration of a taxonomy vocabulary from a D6 site to a D7 site, I need to split out the terms into two separate, new, vocabularies. Doing the splitting is easy enough, and I can do it with a custom table, an extension of DrupalTerm6Migration, and an implementation of prepareRow().
function nb_migrate_register_migrations() {
// Define arguments used for all migrations.
$common_arguments = array(
'source_connection' => 'legacy',
'source_version' => 6,
);
$vocabulary_arguments = array(
array(
'class_name' => 'NBPeopleOrganizationsTermMigration',
'description' => t('Migration of People and Organizations terms from Drupal 6'),
'machine_name' => 'PeopleOrganizations',
'source_vocabulary' => '4', // D6 Vocabulary ID
'destination_vocabulary' => 'non_journalists',
),
);
$common_vocabulary_arguments = $common_arguments + array(
'soft_dependencies' => array('NBUser'),
);
foreach ($vocabulary_arguments as $arguments) {
$arguments += $common_vocabulary_arguments;
Migration::registerMigration($arguments['class_name'], $arguments['machine_name'],
$arguments);
}
}
class NBPeopleOrganizationsTermMigration extends DrupalTerm6Migration {
public function __construct(array $arguments) {
parent::__construct($arguments);
}
/**
* Implementation of Migration::prepareRow().
*
* Need to redirect terms into either Journalists or Non-Journalists vocabularies
* based on whether term is listed in nb_migrate_journalists table.
*
* @param $row
*/
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
static $journalists = array();
if (!$journalists) {
$sql = "SELECT * FROM nb_migrate_journalists";
$result = db_query($sql);
foreach ($result as $record) {
$journalists[] = $record->tid;
}
}
// Check to see if term is in $journalists. If not, leave it as
// non_journalists (as defined in migration registration), otherwise
// change it to journalists.
if (in_array($row->tid, $journalists)) {
$row->destination_vocabulary = 'journalists';
}
}
}
When I try to run this particular migration (via drush migrate-import), I get the following error:
Migration failed with source plugin exception: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'tid' in where clause is ambiguous
which doesn't make sense to me, since I haven't modified the query to select the terms from D6 in the first place. If I use the default DrupalTerm6Migration class, it works fine. In fact, the error hits before prepareRow() is called (and I've verified that my class is registered by looking in the migrate_status table). I've tried to track in down in my debugger, but haven't had any luck yet.
Am I doing something wrong that's causing this error?
Thanks.
Comment | File | Size | Author |
---|---|---|---|
#5 | need_taxonomy_sourcekey_alias-2160027-4.patch | 458 bytes | roberttstephens |
Comments
Comment #1
wonder95 CreditAttribution: wonder95 commentedIt turns out the problem has to do with something I didn't specify above in how I was starting the migration, and that's passing an idlist option to the drush migrate-import command. When I call it like so:
it chokes when building the query. I tracked it through SelectQuery::_toString() (in Drupal core select.inc), and this is the query that is generated:
where
as contained in $this->$query->where['conditions']. Looking at the query at this point you can see the error, because both the term_data and term_hierarchy table have tid values, so since the tid values don't have a table prefix (e.g. td.tid or th.tid) the error is thrown. So as I see it, unless I'm missing something else, a table prefix needs to be added to the field name in the WHERE condition when the idlist option is passed to migrate-import for taxonomy term migrations.
Comment #2
wonder95 CreditAttribution: wonder95 commentedComment #3
wonder95 CreditAttribution: wonder95 commentedSwitching this to Migrate issues queue since drush commands are provided there, not in migrate_d2d.
Comment #4
roberttstephens CreditAttribution: roberttstephens commentedActually, it looks like it should be fixed in migrate_d2d.
This seems to be caused by an alias not being used when the source key is set. When --idlist is used in drush, the migrate module will concatonate the alias to the field name in migrate/plugins/sources/sql.inc around line 258.
The source key is set around line 55 in migrate_d2d/taxonomy.inc
It looks like $query objects in the d5, d6, and d7 taxonomy migrations specify an alias for td, so it's safe to add the alias to the sourceKey in taxonomy.inc.
Comment #5
roberttstephens CreditAttribution: roberttstephens commentedComment #6
roberttstephens CreditAttribution: roberttstephens commentedI'm reasonably sure that the patch provided will fix the issue and that it should be fixed in migrate_d2d. My apologies if I'm mistaken. I'm switching this ticket back to migrate_d2d and setting the status to "Needs review".
wonder95, would you be able to confirm whether or not this fixes your issue?
Comment #7
mikhailian CreditAttribution: mikhailian commented@robertstephens,
If I may reply instead of wonder95… I had exactly the same problem, and your patch solves it.
Thanks alot!
Comment #8
mikhailian CreditAttribution: mikhailian commentedComment #9
mikeryanCommitted, thanks.