$checkPermissions ? CRM_Core_Permission::EDIT : FALSE
);
- $ignoredCustomFields = self::ignoredFields('custom');
foreach ($otherTree as $gid => $group) {
if (!isset($group['fields'])) {
continue;
}
foreach ($group['fields'] as $fid => $field) {
- if (in_array($group['name'] . '.' . $field['name'], $ignoredCustomFields)) {
- continue;
- }
$mainContactValue = $mainTree[$gid]['fields'][$fid]['customValue'] ?? NULL;
$otherContactValue = $otherTree[$gid]['fields'][$fid]['customValue'] ?? NULL;
if (in_array($fid, $compareFields['custom'])) {
$submitted = [];
}
+ // Move view only custom fields CRM-5362
+ $viewOnlyCustomFields = [];
foreach ($submitted as $key => $value) {
if (strpos($key, 'custom_') === 0) {
$fieldID = (int) substr($key, 7);
$htmlType = (string) $fieldMetadata['html_type'];
$isSerialized = CRM_Core_BAO_CustomField::isSerialized($fieldMetadata);
$isView = (bool) $fieldMetadata['is_view'];
- if (!$isView) {
- $submitted = self::processCustomFields($mainId, $key, $submitted, $value, $fieldID, $isView, $htmlType, $isSerialized);
+ if ($isView) {
+ $viewOnlyCustomFields[$key] = $value;
}
+ $submitted = self::processCustomFields($mainId, $key, $submitted, $value, $fieldID, $isView, $htmlType, $isSerialized);
}
}
}
+ // special case to set values for view only, CRM-5362
+ if (!empty($viewOnlyCustomFields)) {
+ $viewOnlyCustomFields['entityID'] = $mainId;
+ CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
+ }
+
// dev/core#996 Ensure that the earliest created date is stored against the kept contact id
$mainCreatedDate = civicrm_api3('Contact', 'getsingle', [
'id' => $mainId,
'postal_greeting_display',
'addressee_display',
],
- 'custom' => [],
];
-
- $readOnlyCustomFields = \Civi\Api4\CustomField::get(FALSE)
- ->addSelect('custom_group_id.name', 'name')
- ->addWhere('is_view', '=', TRUE)
- ->addWhere('custom_group_id.extends', 'IN', ['Individual', 'Household', 'Organization', 'Contact'])
- ->execute();
- foreach ($readOnlyCustomFields as $field) {
- $keysToIgnore['custom'][] = $field['custom_group_id.name'] . '.' . $field['name'];
- }
-
return $keysToIgnore[$type];
}
$this->callAPISuccess('CustomGroup', 'delete', ['id' => $activityGroup['id']]);
}
- /**
- * Verifies that when two contacts with view only custom fields are merged,
- * the view only field of the record being deleted is not merged, it is
- * simply deleted (it should also not be visible on the page).
- */
- public function testMigrationOfViewOnlyCustomData() {
- // Create Custom Fields
- $createGroup = $this->setupCustomGroupForIndividual();
- $customField = $this->setupCustomField('TestField', $createGroup);
-
- // Contacts setup
- $this->setupMatchData();
- $originalContactID = $this->contacts[0]['id'];
- $duplicateContactID = $this->contacts[1]['id'];
-
- // Update the text custom fields for duplicate contact
- $this->callAPISuccess('Contact', 'create', [
- 'id' => $duplicateContactID,
- "custom_{$customField['id']}" => 'abc',
- ]);
- $this->assertCustomFieldValue($duplicateContactID, 'abc', "custom_{$customField['id']}");
-
- // Change custom field to view only.
- $this->callAPISuccess('CustomField', 'update', ['id' => $customField['id'], 'is_view' => TRUE]);
-
- // Merge, and ensure that no value was migrated
- $this->mergeContacts($originalContactID, $duplicateContactID, [
- "move_custom_{$customField['id']}" => NULL,
- ]);
- $this->assertCustomFieldValue($originalContactID, '', "custom_{$customField['id']}");
-
- // cleanup created custom set
- $this->callAPISuccess('CustomField', 'delete', ['id' => $customField['id']]);
- $this->callAPISuccess('CustomGroup', 'delete', ['id' => $createGroup['id']]);
- }
-
/**
* Calls merge method on given contacts, with values given in $params array.
*
}
/**
- * Test the batch merge copes with view only custom data field. View Only custom fields
- * should never be merged.
+ * Test the batch merge copes with view only custom data field.
*/
public function testBatchMergeCustomDataViewOnlyField(): void {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact'];
$this->assertCount(1, $result['values']['merged']);
$mouseParams['return'] = 'custom_' . $customField['id'];
$mouse = $this->callAPISuccess('Contact', 'getsingle', $mouseParams);
- $this->assertEquals('', $mouse['custom_' . $customField['id']]);
+ $this->assertEquals('blah', $mouse['custom_' . $customField['id']]);
}
/**