* @return \CRM_Core_DAO|mixed|null
*/
public static function markNonDuplicates($cid, $oid, $oper) {
+ if ($oper == 'dupe-nondupe') {
+ try {
+ civicrm_api3('Exception', 'create', ['contact_id1' => $cid, 'contact_id2' => $oid]);
+ return TRUE;
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ return FALSE;
+ }
+ }
+
$exception = new CRM_Dedupe_DAO_Exception();
$exception->contact_id1 = $cid;
$exception->contact_id2 = $oid;
}
$exception->find(TRUE);
$status = NULL;
- if ($oper == 'dupe-nondupe') {
- $status = $exception->save();
- }
+
if ($oper == 'nondupe-dupe') {
$status = $exception->delete();
}
public static function create($params) {
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Exception', CRM_Utils_Array::value('id', $params), $params);
-
+ $contact1 = CRM_Utils_Array::value('contact_id1', $params);
+ $contact2 = CRM_Utils_Array::value('contact_id2', $params);
$dao = new CRM_Dedupe_BAO_Exception();
$dao->copyValues($params);
- $dao->save();
- if ($dao->contact_id1 && $dao->contact_id2) {
+ if ($contact1 && $contact2) {
CRM_Core_DAO::singleValueQuery("
DELETE FROM civicrm_prevnext_cache
WHERE (entity_id1 = %1 AND entity_id2 = %2)
OR (entity_id1 = %2 AND entity_id2 = %2)",
- [1 => [$dao->contact_id1, 'Integer'], 2 => [$dao->contact_id2, 'Integer']]
+ [1 => [$contact1, 'Integer'], 2 => [$contact2, 'Integer']]
);
+ if ($contact2 < $contact1) {
+ // These are expected to be saved lowest first.
+ $dao->contact_id1 = $contact2;
+ $dao->contact_id2 = $contact1;
+ }
}
+ $dao->save();
CRM_Utils_Hook::post($hook, 'Exception', $dao->id, $dao);
return $dao;
$this->assertEquals(0, $dupes['count']);
}
+ /**
+ * Per the ajax code there is an expectation the lower id will be contact 1 - ensure api handles this.
+ *
+ * @throws \Exception
+ */
+ public function testExceptionSavesLowerIDFirst() {
+ $contact1 = $this->individualCreate();
+ $contact2 = $this->individualCreate();
+ $this->callAPISuccess('Exception', 'create', ['contact_id1' => $contact2, 'contact_id2' => $contact1]);
+ $this->callAPISuccessGetSingle('Exception', ['contact_id1' => $contact1, 'contact_id2' => $contact2]);
+ }
+
}