You are here

protected function FeedsUserProcessor::existingEntityId in Feeds 8.2

Get id of an existing feed item term if available.

Overrides FeedsProcessor::existingEntityId

File

lib/Drupal/feeds/Plugin/feeds/processor/FeedsUserProcessor.php, line 227
FeedsUserProcessor class.

Class

FeedsUserProcessor
Defines a user processor.

Namespace

Drupal\feeds\Plugin\feeds\processor

Code

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

  // Iterate through all unique targets and try to find a user for the
  // target's value.
  foreach ($this
    ->uniqueTargets($source, $result) as $target => $value) {
    switch ($target) {
      case 'name':
        $uid = db_query("SELECT uid FROM {users} WHERE name = :name", array(
          ':name' => $value,
        ))
          ->fetchField();
        break;
      case 'mail':
        $uid = db_query("SELECT uid FROM {users} WHERE mail = :mail", array(
          ':mail' => $value,
        ))
          ->fetchField();
        break;
      case 'openid':
        $uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname AND module = 'openid'", array(
          ':authname' => $value,
        ))
          ->fetchField();
        break;
    }
    if ($uid) {

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