diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc index 6666276..e789138 100755 --- a/plugins/FeedsProcessor.inc +++ b/plugins/FeedsProcessor.inc @@ -5,6 +5,10 @@ * Contains FeedsProcessor and related classes. */ +// Insert mode for new items. +define('FEEDS_INSERT_NEW', 0); +define('FEEDS_SKIP_NEW', 1); + // Update mode for existing items. define('FEEDS_SKIP_EXISTING', 0); define('FEEDS_REPLACE_EXISTING', 1); @@ -181,12 +185,14 @@ abstract class FeedsProcessor extends FeedsPlugin { // Check if this item already exists. $entity_id = $this->existingEntityId($source, $parser_result); + $skip_new = $this->config['insert_new'] == FEEDS_SKIP_NEW; $skip_existing = $this->config['update_existing'] == FEEDS_SKIP_EXISTING; module_invoke_all('feeds_before_update', $source, $item, $entity_id); - // If it exists, and we are not updating, pass onto the next item. - if ($entity_id && $skip_existing) { + // If it exists, and we are not updating, or if it not exists and we are + // not inserting, pass onto the next item. + if (($entity_id && $skip_existing) || (!$entity_id && $skip_new)) { continue; } @@ -605,6 +611,7 @@ abstract class FeedsProcessor extends FeedsPlugin { } return array( 'mappings' => array(), + 'insert_new' => FEEDS_INSERT_NEW, 'update_existing' => FEEDS_SKIP_EXISTING, 'input_format' => NULL, 'skip_hash_check' => FALSE, @@ -637,6 +644,18 @@ abstract class FeedsProcessor extends FeedsPlugin { $tokens = array('@entities' => strtolower($info['label plural'])); + $form['insert_new'] = array( + '#type' => 'radios', + '#title' => t('Insert new @entities', $tokens), + '#description' => + t('New @entities will be determined using mappings that are a "unique target".', $tokens), + '#options' => array( + FEEDS_INSERT_NEW => t('Insert new @entities', $tokens), + FEEDS_SKIP_NEW => t('Do not insert new @entities', $tokens), + ), + '#default_value' => $this->config['insert_new'], + ); + $form['update_existing'] = array( '#type' => 'radios', '#title' => t('Update existing @entities', $tokens),