protected function SharedImporterNodeProcessor::existingEntityId in Feeds Shared Source 7
Get nid of an existing feed item node if available.
Retrieve the target entity's existing id if available. Otherwise return 0.
Copied from FeedsProcessor::existingEntityId and tweaked to not care about the feed_nid
Parameters
FeedsSource $source: The source information about this import.
FeedsParserResult $result: A FeedsParserResult object.
Return value
sstring The serial id of an entity if found, 0 otherwise.
File
- plugins/
SharedImporterNodeProcessor.inc, line 63 - Class definition of FeedsNodeProcessor.
Class
- SharedImporterNodeProcessor
- Creates nodes from feed items.
Code
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
if ($nid = parent::existingEntityId($source, $result)) {
return $nid;
}
$query = db_select('feeds_item')
->fields('feeds_item', array(
'entity_id',
))
->condition('entity_type', $this
->entityType());
if ($this->config['use_importer_id']) {
$query
->condition('id', $source->id);
}
if ($this->config['use_feed_nid']) {
$query
->condition('feed_nid', $source->feed_nid);
}
// Iterate through all unique targets and test whether they do already
// exist in the database.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
// Use a copy of the query object so we don't wind up with invalid conditions.
$target_query = clone $query;
switch ($target) {
case 'url':
$entity_id = $target_query
->condition('url', $value)
->execute()
->fetchField();
break;
case 'guid':
$entity_id = $target_query
->condition('guid', $value)
->execute()
->fetchField();
break;
}
if (isset($entity_id)) {
// Return with the content id found.
return $entity_id;
}
}
return 0;
}