? 714424-3-save_new.patch
? 714424-7-save_new.patch
Index: mappers/taxonomy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/mappers/taxonomy.inc,v
retrieving revision 1.11.2.2
diff -u -p -r1.11.2.2 taxonomy.inc
--- mappers/taxonomy.inc	28 Oct 2010 20:49:38 -0000	1.11.2.2
+++ mappers/taxonomy.inc	4 Feb 2011 10:57:32 -0000
@@ -52,6 +52,7 @@ function taxonomy_feeds_node_processor_t
       'callback' => 'taxonomy_feeds_set_target',
       'description' => $description,
       'real_target' => 'taxonomy',
+      'uses options' => TRUE
     );
   }
 }
@@ -72,7 +73,7 @@ function taxonomy_feeds_node_processor_t
  * Add the given terms to the node object so the taxonomy module can add them
  * on node_save().
  */
-function taxonomy_feeds_set_target(&$node, $key, $terms) {
+function taxonomy_feeds_set_target(&$node, $key, $terms, $options = array()) {
 
   // Return if there are no terms.
   if (empty($terms)) {
@@ -102,15 +103,31 @@ function taxonomy_feeds_set_target(&$nod
         $node->taxonomy[$term->tid] = (object)$term;
       }
       // Check if a term already exists.
-      elseif ($terms_found = taxonomy_get_term_by_name_vid($term, $vocabulary->vid)) {
-        // If any terms are found add them to the node's taxonomy by found tid.
-        foreach ($terms_found AS $term_found) {
-          $node->taxonomy[$term_found->tid] = $term_found;
-          if (!$vocabulary->multiple) {
-            break;
-          }
+      $terms_found = taxonomy_get_term_by_name_vid($term, $vocabulary->vid);
+      if (empty($terms_found) && $options['taxonomy_add'] == 1) {
+        // We are allowed to add taxonomy terms
+        $new_term = array(
+          'name' => $term,
+          'vid' => $vocabulary->vid
+        );
+        $status = taxonomy_save_term($new_term);
+        // Check to see if everything went right
+        if ($status == SAVED_NEW) {
+          $terms_found = array((object) $new_term);
+        }
+        else {
+          break;
+        }
+      }
+      
+      // If any terms are found add them to the node's taxonomy by found tid.
+      foreach ($terms_found AS $term_found) {
+        $node->taxonomy[$term_found->tid] = $term_found;
+        if (!$vocabulary->multiple) {
+          break;
         }
       }
+      
       // If the vocab is not for multiple tags break after the first hit.
       if (!$vocabulary->multiple) {
         break;
Index: plugins/FeedsNodeProcessor.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsNodeProcessor.inc,v
retrieving revision 1.51.2.2
diff -u -p -r1.51.2.2 FeedsNodeProcessor.inc
--- plugins/FeedsNodeProcessor.inc	25 Oct 2010 22:43:03 -0000	1.51.2.2
+++ plugins/FeedsNodeProcessor.inc	4 Feb 2011 10:57:33 -0000
@@ -46,7 +46,7 @@ class FeedsNodeProcessor extends FeedsPr
 
         // Map and save node. If errors occur don't stop but report them.
         try {
-          $this->map($batch, $node);
+          $this->map($batch, $node, $this->config);
           node_save($node);
           if (!empty($nid)) {
             $batch->updated++;
@@ -150,6 +150,7 @@ class FeedsNodeProcessor extends FeedsPr
       'expire' => FEEDS_EXPIRE_NEVER,
       'mappings' => array(),
       'author' => 0,
+      'taxonomy_add' => 0
     );
   }
 
@@ -205,6 +206,12 @@ class FeedsNodeProcessor extends FeedsPr
       ),
       '#default_value' => $this->config['update_existing'],
     );
+    $form['taxonomy_add'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Add terms to taxonomy'),
+      '#description' => t('Check this box if you want to add terms to the taxonomies if the terms do not already exist.'),
+      '#default_value' => $this->config['taxonomy_add']
+    );
     return $form;
   }
 
Index: plugins/FeedsProcessor.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsProcessor.inc,v
retrieving revision 1.18
diff -u -p -r1.18 FeedsProcessor.inc
--- plugins/FeedsProcessor.inc	10 Sep 2010 15:44:56 -0000	1.18
+++ plugins/FeedsProcessor.inc	4 Feb 2011 10:57:33 -0000
@@ -82,7 +82,7 @@ abstract class FeedsProcessor extends Fe
    * @see hook_feeds_term_processor_targets_alter()
    * @see hook_feeds_user_processor_targets_alter()
    */
-  protected function map(FeedsImportBatch $batch, $target_item = NULL) {
+  protected function map(FeedsImportBatch $batch, $target_item = NULL, $options = array()) {
 
     // Static cache $targets as getMappingTargets() may be an expensive method.
     static $sources;
@@ -144,7 +144,12 @@ abstract class FeedsProcessor extends Fe
           isset($targets[$this->id][$mapping['target']]['callback']) &&
           function_exists($targets[$this->id][$mapping['target']]['callback'])) {
         $callback = $targets[$this->id][$mapping['target']]['callback'];
-        $callback($target_item, $mapping['target'], $value);
+        if ($targets[$this->id][$mapping['target']]['uses options'] == TRUE) {
+          $callback($target_item, $mapping['target'], $value, $options);
+        }
+        else {
+          $callback($target_item, $mapping['target'], $value);
+        }
       }
       else {
         $this->setTargetElement($target_item, $mapping['target'], $value);
