public function MigrateDestinationTerm::findMatchingTerm in Migrate 7.2
Attempt to find a term that has the same name, vocabulary, and parents.
Parameters
object $term: A taxonomy term object with at least the name and vid properties defined.
Return value
object A matching taxonomy term object if found, otherwise FALSE.
1 call to MigrateDestinationTerm::findMatchingTerm()
- MigrateDestinationTerm::import in plugins/
destinations/ term.inc - Import a single term.
File
- plugins/
destinations/ term.inc, line 298 - Support for taxonomy term destinations.
Class
- MigrateDestinationTerm
- Destination class implementing migration into terms.
Code
public function findMatchingTerm($term) {
// See if the term, with the same parentage, already exists - if so,
// load it
$candidates = taxonomy_term_load_multiple(array(), array(
'name' => trim($term->name),
'vid' => $term->vid,
));
foreach ($candidates as $candidate) {
$parents = taxonomy_get_parents($candidate->tid);
// We need to set up $parents as a simple array of tids
if (empty($parents)) {
$parents = array(
0,
);
}
else {
// Parents array is tid => term object, make into list of tids
$new_parents = array();
foreach ($parents as $parent) {
$new_parents[] = $parent->tid;
}
$parents = $new_parents;
}
if ($term->parent == $parents) {
// We've found a matching term.
return $candidate;
}
}
return FALSE;
}