From d0dc5e50b36da7d6a136113272a3e3136de8570d Mon Sep 17 00:00:00 2001 From: Chris Leppanen <chris.leppanen@gmail.com> Date: Fri, 16 Nov 2012 10:29:14 -0800 Subject: [PATCH] Fix replace existing behavior. --- plugins/FeedsProcessor.inc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc index 7c8dde1c..d37555d7 100755 --- a/plugins/FeedsProcessor.inc +++ b/plugins/FeedsProcessor.inc @@ -137,6 +137,8 @@ abstract class FeedsProcessor extends FeedsPlugin { */ public function process(FeedsSource $source, FeedsParserResult $parser_result) { $state = $source->state(FEEDS_PROCESS); + $entity_info = $this->entityInfo(); + $id_key = $entity_info['entity keys']['id']; while ($item = $parser_result->shiftItem()) { @@ -161,8 +163,10 @@ abstract class FeedsProcessor extends FeedsPlugin { try { + $replace_existing = $this->config['update_existing'] == FEEDS_REPLACE_EXISTING; + // Build a new entity. - if (empty($entity_id)) { + if (!$entity_id || $replace_existing) { $entity = $this->newEntity($source); $this->newItemInfo($entity, $source->feed_nid, $hash); } @@ -171,12 +175,17 @@ abstract class FeedsProcessor extends FeedsPlugin { else { $entity = $this->entityLoad($source, $entity_id); - // The feeds_item table is always updated with the info for the most recently processed entity. - // The only carryover is the entity_id. + // The feeds_item table is always updated with the info for the most + // recently processed entity. The only carryover is the entity_id. $this->newItemInfo($entity, $source->feed_nid, $hash); $entity->feeds_item->entity_id = $entity_id; } + if ($entity_id && $replace_existing) { + $entity->is_new = FALSE; + $entity->$id_key = $entity_id; + } + // Set property and field values. $this->map($source, $parser_result, $entity); $this->entityValidate($entity); -- GitLab