Index: modules/core/taxonomy.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/migrate/modules/core/Attic/taxonomy.inc,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 taxonomy.inc --- modules/core/taxonomy.inc 14 Jun 2009 19:59:15 -0000 1.1.2.2 +++ modules/core/taxonomy.inc 18 Jul 2009 22:20:04 -0000 @@ -4,6 +4,36 @@ // Note: this file is included both for taxonomy.module and for // the wrapper taxonomy.module of category.module. This file // handles both cases for assigning terms to nodes. +// @TODO: Need to deal with hierarchy + +/** + * Implementation of hook_migrate_destination_types(). + */ +function taxonomy_migrate_destination_types() { + static $vocabularies = NULL; + + if (!isset($vocabularies)) { + $vocabularies = array(); + foreach (taxonomy_get_vocabularies() as $type => $info) { + $vocabularies['taxonomy/' . $type] = t('Vocabulary: ') . $info->name; + } + asort($vocabularies); + } + return $vocabularies; +} + +/** + * Implementation of hook_migrate_destination_fields_taxonomy(). + */ +function taxonomy_migrate_destination_fields_taxonomy($type) { + $fields = array( + 'name' => t('Taxonomy: Name'), + 'description' => t('Taxonomy: Description'), + 'weight' => t('Taxonomy: Weight'), + 'parent' => t('Taxonomy: Parent'), + ); + return $fields; +} /** * Implementation of hook_migrate_destination_fields_node(). @@ -17,6 +47,69 @@ function taxonomy_migrate_destination_fi } /** + * Implementation of hook_migrate_destination_delete_taxonomy(). + */ +function taxonomy_migrate_destination_delete_taxonomy($tid) { + taxonomy_del_term($tid); +} + +/** + * Implementation of hook_migrate_destination_import_taxonomy(). + */ +function taxonomy_migrate_destination_import_taxonomy($tblinfo, $row) { + $sourcekey = $tblinfo->sourcekey; + $errors = array(); + // Begin building term array. + $term = array(); + $term['vid'] = $tblinfo->desttype; + + foreach ($tblinfo->fields as $destfield => $values) { + if ($values['srcfield'] && $row->$values['srcfield']) { + $source_value = $row->$values['srcfield']; + } else { + $source_value = $values['default_value']; + } + if ($destfield != 'parent') { + $term[$destfield] = $source_value; + } + else { + // @TODO: support input parent taxonomy terms that are strings rather than ids. + // @TODO: what if parent term is not already loaded into database? + // Manually order the view by parent id? + if (is_numeric($source_value)) { + $parent = db_result(db_query("SELECT destid FROM {". $tblinfo->maptable ."} WHERE sourceid = %d", $source_value)); + $term[$destfield] = ($parent >= 0 ? $parent : 0); + } + } + // @todo: could include vocabulary as an import field, rather than having to select a single vocabulary before import + } + + // Prepare the term for import. + $errors = migrate_destination_invoke_all('prepare_taxonomy', $term, $tblinfo, $row); + + $success = TRUE; + foreach ($errors as $error) { + if ($error['level'] != MIGRATE_MESSAGE_INFORMATIONAL) { + $success = FALSE; + break; + } + } + if ($success) { + timer_start('taxonomy_save'); + taxonomy_save_term($term); + timer_stop('taxonomy_save'); + // Call completion hooks, for any processing which needs to be done after node_save + timer_start('taxonomy completion hooks'); + $errors = migrate_destination_invoke_all('complete_taxonomy', $term, $tblinfo, $row); + timer_stop('taxonomy completion hooks'); + + // @TODO: Check first for existence, we may have updated an existing term - do we care about duplicates? + migrate_add_mapping($tblinfo->mcsid, $row->$sourcekey, $term['tid']); + } + return $errors; +} + +/** * Implementation of hook_migrate_prepare(). */ function taxonomy_migrate_destination_prepare_node(&$node, $tblinfo, $row) { @@ -130,6 +223,10 @@ function taxonomy_migrate_destination_pr return $errors; } +function taxonomy_migrate_destination_xlat_taxonomy($tid) { + return "taxonomy/term/$tid"; +} + /** * Return a tid for a term (text). * @@ -191,3 +288,4 @@ function _migrate_taxonomy_get_term($voc $missing_terms[$vid][$text] = $tid; return $tid; } +