diff --git a/plugins/FeedsDataProcessor.inc b/plugins/FeedsDataProcessor.inc index 181bc91..0ed2c8e 100644 --- a/plugins/FeedsDataProcessor.inc +++ b/plugins/FeedsDataProcessor.inc @@ -233,6 +233,7 @@ class FeedsDataProcessor extends FeedsProcessor { */ public function configDefaults() { return array( + 'insert_new' => FEEDS_INSERT_NEW, 'update_existing' => FEEDS_SKIP_EXISTING, 'expire' => FEEDS_EXPIRE_NEVER, // Don't expire items by default. 'mappings' => array(), diff --git a/plugins/FeedsFeedNodeProcessor.inc b/plugins/FeedsFeedNodeProcessor.inc index b083261..a7e13c8 100644 --- a/plugins/FeedsFeedNodeProcessor.inc +++ b/plugins/FeedsFeedNodeProcessor.inc @@ -17,9 +17,10 @@ class FeedsFeedNodeProcessor extends FeedsProcessor { public function process(FeedsImportBatch $batch, FeedsSource $source) { while ($item = $batch->shiftItem()) { - // If the target item does not exist OR if update_existing is enabled, - // map and save. - if (!$nid = $this->existingItemId($batch, $source) || $this->config['update_existing']) { + // Create if item does not exist and creat new is enabled + // or update if update existing is enabled. + $nid = $this->existingItemId($batch, $source); + if ((!$nid && $this->config['insert_new']) || ($nid && $this->config['update_existing'])) { // Map item to a node. $node = $this->map($batch); diff --git a/plugins/FeedsNodeProcessor.inc b/plugins/FeedsNodeProcessor.inc index f7c665a..fb7c47e 100644 --- a/plugins/FeedsNodeProcessor.inc +++ b/plugins/FeedsNodeProcessor.inc @@ -33,8 +33,10 @@ class FeedsNodeProcessor extends FeedsProcessor { while ($item = $batch->shiftItem()) { - // Create/update if item does not exist or update existing is enabled. - if (!($nid = $this->existingItemId($batch, $source)) || ($this->config['update_existing'] != FEEDS_SKIP_EXISTING)) { + // Create if item does not exist and creat new is enabled + // or update if update existing is enabled. + $nid = $this->existingItemId($batch, $source); + if ((!$nid && $this->config['insert_new']) || ($nid && $this->config['update_existing'])) { // Only proceed if item has actually changed. $hash = $this->hash($item); if (!empty($nid) && $hash == $this->getHash($nid)) { @@ -159,6 +161,7 @@ class FeedsNodeProcessor extends FeedsProcessor { return array( 'content_type' => $type, 'input_format' => FILTER_FORMAT_DEFAULT, + 'insert_new' => FEEDS_INSERT_NEW, 'update_existing' => FEEDS_SKIP_EXISTING, 'expire' => FEEDS_EXPIRE_NEVER, 'mappings' => array(), @@ -214,6 +217,16 @@ class FeedsNodeProcessor extends FeedsProcessor { '#description' => t('Select after how much time nodes should be deleted. The node\'s published date will be used for determining the node\'s age, see Mapping settings.'), '#default_value' => $this->config['expire'], ); + $form['insert_new'] = array( + '#type' => 'radios', + '#title' => t('Insert new nodes'), + '#description' => t('New nodes will be determined using mappings that are a "unique target".'), + '#options' => array( + FEEDS_INSERT_NEW => t('Insert new nodes'), + FEEDS_SKIP_NEW => t('Do not insert new nodes'), + ), + '#default_value' => $this->config['insert_new'], + ); $form['update_existing'] = array( '#type' => 'radios', '#title' => t('Update existing nodes'), diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc index 3154def..5a48035 100644 --- a/plugins/FeedsProcessor.inc +++ b/plugins/FeedsProcessor.inc @@ -6,6 +6,10 @@ define('FEEDS_SKIP_EXISTING', 0); define('FEEDS_REPLACE_EXISTING', 1); define('FEEDS_UPDATE_EXISTING', 2); +// Insert mode for new items. +define('FEEDS_INSERT_NEW', 1); +define('FEEDS_SKIP_NEW', 0); + /** * Abstract class, defines interface for processors. */ diff --git a/plugins/FeedsTermProcessor.inc b/plugins/FeedsTermProcessor.inc index 51c248e..5ffe70b 100644 --- a/plugins/FeedsTermProcessor.inc +++ b/plugins/FeedsTermProcessor.inc @@ -24,8 +24,10 @@ class FeedsTermProcessor extends FeedsProcessor { while ($item = $batch->shiftItem()) { - // Create/update if item does not exist or update existing is enabled. - if (!($tid = $this->existingItemId($batch, $source)) || $this->config['update_existing'] != FEEDS_SKIP_EXISTING) { + // Create if item does not exist and creat new is enabled + // or update if update existing is enabled. + $tid = $this->existingItemId($batch, $source) + if ((!$tid && $this->config['insert_new']) || ($tid && FEEDS_SKIP_EXISTING != $this->config['update_existing'])) { // Map feed item to a term. $term = array(); @@ -172,6 +174,7 @@ class FeedsTermProcessor extends FeedsProcessor { public function configDefaults() { return array( 'vocabulary' => 0, + 'insert_new' => FEEDS_INSERT_NEW, 'update_existing' => FEEDS_SKIP_EXISTING, 'mappings' => array(), ); @@ -198,6 +201,16 @@ class FeedsTermProcessor extends FeedsProcessor { '#options' => $options, '#default_value' => $this->config['vocabulary'], ); + $form['insert_new'] = array( + '#type' => 'radios', + '#title' => t('Insert new terms'), + '#description' => t('New terms will be determined using mappings that are a "unique target".'), + '#options' => array( + FEEDS_INSERT_NEW => t('Insert new terms'), + FEEDS_SKIP_NEW => t('Do not insert new terms'), + ), + '#default_value' => $this->config['insert_new'], + ); $form['update_existing'] = array( '#type' => 'radios', '#title' => t('Update existing terms'),