From 8d46c57edf763368f7599f46ce7db2c03eec1d0a Mon Sep 17 00:00:00 2001 From: Desmond Morris Date: Fri, 11 Mar 2011 11:01:16 -0500 Subject: [PATCH] Issue #959984 by desmondmorris: Added taxonomy_feeds_node_get_terms function to accomodate undefined function taxonomy_node_get_terms error. --- mappers/taxonomy.inc | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc index 01d92f3..42a547c 100644 --- a/mappers/taxonomy.inc +++ b/mappers/taxonomy.inc @@ -27,7 +27,7 @@ function taxonomy_feeds_parser_sources_alter(&$sources, $content_type) { */ function taxonomy_feeds_get_source(FeedsSource $source, FeedsParserResult $result, $key) { if ($node = node_load($source->feed_nid)) { - $terms = taxonomy_node_get_terms($node); + $terms = taxonomy_feeds_node_get_terms($node); $vocabularies = taxonomy_vocabulary_load_multiple(array(), array('machine_name' => str_replace('parent:taxonomy:', '', $key))); $vocabulary = array_shift($vocabularies); $result = array(); @@ -106,6 +106,27 @@ function taxonomy_feeds_set_target($source, $entity, $target, $terms) { } /** + * Find all terms associated with the given node, within one vocabulary. + */ +function taxonomy_feeds_node_get_terms($node, $key = 'tid') { + static $terms; + + if (!isset($terms[$node->vid][$key])) { + $query = db_select('taxonomy_index', 'r'); + $t_alias = $query->join('taxonomy_term_data', 't', 'r.tid = t.tid'); + $v_alias = $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid'); + $query->fields( $t_alias ); + $query->condition("r.nid", $node->nid); + $result = $query->execute(); + $terms[$node->vid][$key] = array(); + foreach ($result as $term) { + $terms[$node->vid][$key][$term->$key] = $term; + } + } + return $terms[$node->vid][$key]; +} + +/** * Checks whether a term identified by name and vocabulary exists. Creates a * new term if it does not exist. * -- 1.7.3.5