You are here

protected function FeedsTermProcessor::existingItemId in Feeds 6

Same name and namespace in other branches
  1. 7 plugins/FeedsTermProcessor.inc \FeedsTermProcessor::existingItemId()

Get id of an existing feed item term if available.

Overrides FeedsProcessor::existingItemId

1 call to FeedsTermProcessor::existingItemId()
FeedsTermProcessor::process in plugins/FeedsTermProcessor.inc
Implementation of FeedsProcessor::process().

File

plugins/FeedsTermProcessor.inc, line 286
FeedsTermProcessor class.

Class

FeedsTermProcessor
Feeds processor plugin. Create taxonomy terms from feed items.

Code

protected function existingItemId(FeedsImportBatch $batch, FeedsSource $source) {

  // Iterate through all unique targets and test whether they already
  // exist in the database.
  foreach ($this
    ->uniqueTargets($batch) as $target => $value) {
    switch ($target) {
      case 'url':
      case 'guid':
        $tid = db_result(db_query("SELECT tid FROM {feeds_term_item} WHERE feed_nid = %d AND id = '%s' AND %s = '%s'", $source->feed_nid, $this->id, $target, $value));
        break;
      case 'name':
        $vocabulary = $this
          ->vocabulary();
        $tid = db_result(db_query("SELECT tid FROM {term_data} WHERE name = '%s' AND vid = %d", $value, $vocabulary->vid));
        break;
    }
    if ($tid) {

      // Return the first tid found.
      return $tid;
    }
  }
  return 0;
}