diff --git a/Civi/DataProcessor/Source/AbstractSource.php b/Civi/DataProcessor/Source/AbstractSource.php index 69fb06ddda135de51f8c54f5a77c8917eb19b6c4..7aea226984add63171255967e209d8ee4099da59 100644 --- a/Civi/DataProcessor/Source/AbstractSource.php +++ b/Civi/DataProcessor/Source/AbstractSource.php @@ -165,8 +165,18 @@ abstract class AbstractSource implements SourceInterface { * @throws \Exception */ public function ensureFieldInSource(FieldSpecification $fieldSpecification) { - if (!$this->dataFlow->getDataSpecification()->doesFieldExist($fieldSpecification->name)) { - $this->dataFlow->getDataSpecification()->addFieldSpecification($fieldSpecification->name, $fieldSpecification); + try { + $originalFieldSpecification = null; + if ($this->getAvailableFields()->doesAliasExists($fieldSpecification->alias)) { + $originalFieldSpecification = $this->getAvailableFields()->getFieldSpecificationByAlias($fieldSpecification->alias); + } elseif ($this->getAvailableFields()->doesFieldExist($fieldSpecification->name)) { + $originalFieldSpecification = $this->getAvailableFields()->getFieldSpecificationByName($fieldSpecification->name); + } + if ($originalFieldSpecification) { + $this->dataFlow->getDataSpecification()->addFieldSpecification($fieldSpecification->alias, $fieldSpecification); + } + } catch (FieldExistsException $e) { + // Do nothing. } return $this; }