CRM_Core_OptionGroup::lookupValues($submitted, $names, TRUE);
// fix custom fields so they're edible by createProfileContact()
- static $treeCache = array();
+ $treeCache = array();
if (!array_key_exists($migrationInfo['main_details']['contact_type'], $treeCache)) {
- $treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree($migrationInfo['main_details']['contact_type'], NULL, NULL, -1);
+ $treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree(
+ $migrationInfo['main_details']['contact_type'],
+ NULL,
+ NULL,
+ -1,
+ array(),
+ NULL,
+ TRUE,
+ NULL,
+ FALSE,
+ FALSE
+ );
}
$cFields = array();
// move view only custom fields CRM-5362
$viewOnlyCustomFields = array();
foreach ($submitted as $key => $value) {
- $fid = (int) substr($key, 7);
- if (array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])) {
+ $fid = CRM_Core_BAO_CustomField::getKeyID($key);
+ if ($fid && array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])
+ ) {
$viewOnlyCustomFields[$key] = $value;
}
}
-
// special case to set values for view only, CRM-5362
if (!empty($viewOnlyCustomFields)) {
$viewOnlyCustomFields['entityID'] = $mainId;
}
+ /**
+ * Test the batch merge copes with view only custom data field.
+ */
+ public function testBatchMergeCustomDataViewOnlyField() {
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact');
+ $mouseParams = ['first_name' => 'Mickey', 'last_name' => 'Mouse', 'email' => 'tha_mouse@mouse.com'];
+ $this->individualCreate($mouseParams);
+
+ $customGroup = $this->CustomGroupCreate();
+ $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'], 'is_view' => 1));
+ $this->individualCreate(array_merge($mouseParams, ['custom_' . $customField['id'] => 'blah']));
+
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0, 'mode' => 'safe'));
+ $this->assertEquals(1, count($result['values']['merged']));
+ $mouseParams['return'] = 'custom_' . $customField['id'];
+ $mouse = $this->callAPISuccess('Contact', 'getsingle', $mouseParams);
+ $this->assertEquals('blah', $mouse['custom_' . $customField['id']]);
+
+ $this->customFieldDelete($customGroup['id']);
+ $this->customGroupDelete($customGroup['id']);
+ }
+
/**
* Test the batch merge function actually works!
*