You are here

protected function FeedsProcessor::existingEntityId in Feeds 8.2

Retrieve the target entity's existing id if available. Otherwise return 0.

Parameters

FeedsSource $source: The source information about this import.

$result: A FeedsParserResult object.

Return value

The serial id of an entity if found, 0 otherwise.

Related topics

4 calls to FeedsProcessor::existingEntityId()
FeedsNodeProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsNodeProcessor.php
Get nid of an existing feed item node if available.
FeedsProcessor::process in lib/Drupal/feeds/Plugin/FeedsProcessor.php
Process the result of the parsing stage.
FeedsTermProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsTermProcessor.php
Get id of an existing feed item term if available.
FeedsUserProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsUserProcessor.php
Get id of an existing feed item term if available.
3 methods override FeedsProcessor::existingEntityId()
FeedsNodeProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsNodeProcessor.php
Get nid of an existing feed item node if available.
FeedsTermProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsTermProcessor.php
Get id of an existing feed item term if available.
FeedsUserProcessor::existingEntityId in lib/Drupal/feeds/Plugin/feeds/processor/FeedsUserProcessor.php
Get id of an existing feed item term if available.

File

lib/Drupal/feeds/Plugin/FeedsProcessor.php, line 743
Contains FeedsProcessor and related classes.

Class

FeedsProcessor
Abstract class, defines interface for processors.

Namespace

Drupal\feeds\Plugin

Code

protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
  $query = 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);

  // Iterate through all unique targets and test whether they do already
  // exist in the database.
  foreach ($this
    ->uniqueTargets($source, $result) as $target => $value) {
    switch ($target) {
      case 'url':
        $entity_id = $query
          ->condition('url', $value)
          ->execute()
          ->fetchField();
        break;
      case 'guid':
        $entity_id = $query
          ->condition('guid', $value)
          ->execute()
          ->fetchField();
        break;
    }
    if (isset($entity_id)) {

      // Return with the content id found.
      return $entity_id;
    }
  }
  return 0;
}