protected function FeedsProcessor::existingEntityId in Feeds 7.2
Retrieve the target entity's existing id if available. Otherwise return 0.
Parameters
FeedsSource $source: The source information about this import.
FeedsParserResult $result: A FeedsParserResult object.
Return value
int The serial id of an entity if found, 0 otherwise.
Related topics
4 calls to FeedsProcessor::existingEntityId()
- FeedsNodeProcessor::existingEntityId in plugins/
FeedsNodeProcessor.inc - Get nid of an existing feed item node if available.
- FeedsProcessor::process in plugins/
FeedsProcessor.inc - Process the result of the parsing stage.
- FeedsTermProcessor::existingEntityId in plugins/
FeedsTermProcessor.inc - Get id of an existing feed item term if available.
- FeedsUserProcessor::existingEntityId in plugins/
FeedsUserProcessor.inc - Get id of an existing feed item term if available.
3 methods override FeedsProcessor::existingEntityId()
- FeedsNodeProcessor::existingEntityId in plugins/
FeedsNodeProcessor.inc - Get nid of an existing feed item node if available.
- FeedsTermProcessor::existingEntityId in plugins/
FeedsTermProcessor.inc - Get id of an existing feed item term if available.
- FeedsUserProcessor::existingEntityId in plugins/
FeedsUserProcessor.inc - Get id of an existing feed item term if available.
File
- plugins/
FeedsProcessor.inc, line 1266 - Contains FeedsProcessor and related classes.
Class
- FeedsProcessor
- Abstract class, defines interface for processors.
Code
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
$targets = $this
->getCachedTargets();
$entity_id = 0;
// Iterate through all unique targets and test whether they already exist in
// the database.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
if ($target === 'guid' || $target === 'url') {
$entity_id = db_select('feeds_item')
->fields('feeds_item', array(
'entity_id',
))
->condition('feed_nid', $source->feed_nid)
->condition('entity_type', $this
->entityType())
->condition('id', $source->id)
->condition($target, $value)
->execute()
->fetchField();
}
if (!$entity_id && !empty($targets[$target]['unique_callbacks'])) {
if (!is_array($value)) {
$value = array(
$value,
);
}
foreach ($targets[$target]['unique_callbacks'] as $callback) {
if ($entity_id = call_user_func($callback, $source, $this
->entityType(), $this
->bundle(), $target, $value)) {
// Stop at the first unique ID returned by a callback.
break;
}
}
}
// Return with the content id found.
if ($entity_id) {
return $entity_id;
}
}
return $entity_id;
}