foreach ($allFields as $field) {
// Use implicit join syntax but only if the fk entity has a `name` field
if (!empty($field['fk_entity']) && array_key_exists('name', $this->getFieldsForExport($field['fk_entity']))) {
+ $select[] = $field['name'];
$select[] = $field['name'] . '.name';
$pseudofields[$field['name'] . '.name'] = $field['name'];
}
// Use pseudoconstant syntax if appropriate
elseif ($this->shouldUsePseudoconstant($entityType, $field)) {
+ $select[] = $field['name'];
$select[] = $field['name'] . ':name';
$pseudofields[$field['name'] . ':name'] = $field['name'];
}
elseif (empty($field['fk_entity'])) {
$select[] = $field['name'];
}
- // Needed for exporting the option group for a custom field
- if ($entityType === 'CustomField' && ($field['fk_entity'] ?? NULL) === 'OptionGroup') {
- $select[] = $field['name'];
- }
}
$record = civicrm_api4($entityType, 'get', [
'checkPermissions' => $this->checkPermissions,
}
// The get api always returns ID, but it should not be included in an export
unset($record['id']);
- // Null fields should not use joins/pseudoconstants
- foreach ($pseudofields as $alias => $fieldName) {
- if (is_null($record[$alias])) {
- unset($record[$alias]);
- $record[$fieldName] = NULL;
- }
- }
// Should references be limited to the current domain?
$limitRefsByDomain = $entityType === 'OptionGroup' && \CRM_Core_OptionGroup::isDomainOptionGroup($record['name']) ? \CRM_Core_BAO_Domain::getDomain()->id : FALSE;
foreach ($allFields as $fieldName => $field) {
) {
$this->exportRecord('OptionGroup', $record['option_group_id'], $result);
}
- unset($record['option_group_id']);
+ }
+ // Don't use joins/pseudoconstants if null or if it has the same value as the original
+ foreach ($pseudofields as $alias => $fieldName) {
+ if (!isset($record[$alias]) || $record[$alias] == ($record[$fieldName] ?? NULL)) {
+ unset($record[$alias]);
+ }
+ else {
+ unset($record[$fieldName]);
+ }
}
$result[] = [
'name' => $name,
$daoName = CoreUtil::getInfoItem($entityType, 'dao');
if ($daoName) {
/** @var \CRM_Core_DAO $dao */
- $dao = new $daoName();
- $dao->id = $entityId;
+ $dao = $daoName::findById($entityId);
// Collect references into arrays keyed by entity type
$references = [];
foreach ($dao->findReferences() as $reference) {
return FALSE;
}
$daoName = CoreUtil::getInfoItem($entityType, 'dao');
+ // Exception for Profile.field_name
+ if ($entityType === 'UFField' && $field['name'] === 'field_name') {
+ return TRUE;
+ }
// Options generated by a callback function tend to be stable,
// and the :name property may not be reliable. Use plain value.
if ($daoName && !empty($daoName::getSupportedFields()[$field['name']]['pseudoconstant']['callback'])) {