* @param array $tableOperations
* @param array $customTableToCopyFrom
*/
- public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = [], $customTableToCopyFrom = NULL) {
+ public static function moveContactBelongings($mainId, $otherId, $tables, $tableOperations, array $customTableToCopyFrom) {
$cidRefs = self::cidRefs();
$eidRefs = self::eidRefs();
$cpTables = self::cpTables();
// getting all custom tables
$customTables = [];
- if ($customTableToCopyFrom !== NULL) {
- // @todo this duplicates cidRefs?
- CRM_Core_DAO::appendCustomTablesExtendingContacts($customTables);
- CRM_Core_DAO::appendCustomContactReferenceFields($customTables);
- $customTables = array_keys($customTables);
- }
+ // @todo this duplicates cidRefs?
+ CRM_Core_DAO::appendCustomTablesExtendingContacts($customTables);
+ CRM_Core_DAO::appendCustomContactReferenceFields($customTables);
+ $customTables = array_keys($customTables);
$affected = array_merge(array_keys($cidRefs), array_keys($eidRefs));
foreach ($affected as $table) {
// skipping non selected single-value custom table's value migration
if (!in_array($table, $multi_value_tables)) {
- if ($customTableToCopyFrom !== NULL && in_array($table, $customTables) && !in_array($table, $customTableToCopyFrom)) {
+ if (in_array($table, $customTables) && !in_array($table, $customTableToCopyFrom)) {
if (isset($cidRefs[$table]) && ($delCol = array_search('entity_id', $cidRefs[$table])) !== FALSE) {
// remove entity_id from the field list
unset($cidRefs[$table][$delCol]);
$preOperationSqls = self::operationSql($mainId, $otherId, $table, $tableOperations);
$sqls = array_merge($sqls, $preOperationSqls);
- if ($customTableToCopyFrom !== NULL && in_array($table, $customTableToCopyFrom) && !self::customRecordExists($mainId, $table, $field) && $field == 'entity_id') {
+ if (in_array($table, $customTableToCopyFrom) && !self::customRecordExists($mainId, $table, $field) && $field == 'entity_id') {
// this is the entity_id column of a custom field group where:
// - the custom table should be copied as indicated by $customTableToCopyFrom
// e.g. because a field in the group was selected in a form
* @param $value
*
* @return array
- * @throws \Exception
+ * @throws \CRM_Core_Exception
*/
protected static function processCustomFields($mainId, $key, $cFields, $submitted, $value) {
if (substr($key, 0, 7) == 'custom_') {
* @param string $contactType
*
* @return array
+ * @throws \CRM_Core_Exception
*/
protected static function getCustomFieldMetadata($contactType) {
$treeCache = [];
/**
* Check we get a conflict on the customs field when the data conflicts for booleans (reverse).
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testBatchMergeCustomFieldConflictsOneBlank() {
+ public function testBatchMergeCustomFieldNoConflictsOneBlank() {
$this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
$this->individualCreate();
$result = $this->callAPISuccess('Job', 'process_batch_merge', []);
- $this->assertEquals(1, count($result['values']['merged']));
- $this->assertEquals(0, count($result['values']['skipped']));
+ $this->assertCount(1, $result['values']['merged']);
+ $this->assertCount(0, $result['values']['skipped']);
}
/**
* Check we get a conflict on the customs field when the data conflicts for booleans (reverse).
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testBatchMergeCustomFieldConflictsOneBlankReverse() {
- $this->individualCreate();
+ public function testBatchMergeCustomFieldNoConflictsOneBlankReverse() {
+ $contactID = $this->individualCreate();
$this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
$result = $this->callAPISuccess('Job', 'process_batch_merge', []);
- $this->assertEquals(1, count($result['values']['merged']));
- $this->assertEquals(0, count($result['values']['skipped']));
+ $this->assertCount(1, $result['values']['merged']);
+ $this->assertCount(0, $result['values']['skipped']);
+ $this->assertEquals(1, $this->callAPISuccessGetValue('Contact', ['id' => $contactID, 'return' => 'custom_' . $this->customBoolFieldID]));
}
}