You are here

protected function AssetFeedsProcessor::existingEntityId in Asset 7

Get aid of an existing feed item asset if available.

File

modules/asset_feeds/AssetFeedsProcessor.inc, line 261
Class definition of AssetFeedsProcessor.

Class

AssetFeedsProcessor
Creates assets from feed items.

Code

protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
  if ($aid = parent::existingEntityId($source, $result)) {
    return $aid;
  }

  // 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 'aid':
        $aid = db_query("SELECT aid FROM {asset} WHERE aid = :aid", array(
          ':aid' => $value,
        ))
          ->fetchField();
        break;
      case 'title':
        $aid = db_query("SELECT aid FROM {asset} WHERE title = :title", array(
          ':title' => $value,
        ))
          ->fetchField();
        break;
      case 'feeds_source':
        if ($id = feeds_get_importer_id($this->config['asset_type'])) {
          $aid = db_query("SELECT fs.feed_nid FROM {asset} a JOIN {feeds_source} fs ON a.aid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(
            ':id' => $id,
            ':source' => $value,
          ))
            ->fetchField();
        }
        break;
    }
    if ($aid) {

      // Return with the first aid found.
      return $aid;
    }
  }
  return 0;
}