From 7e836d07067ab9403188d94c293d9325c6405c86 Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Tue, 13 Aug 2019 13:47:19 +0200
Subject: [PATCH] =?UTF-8?q?Eventuelle=20gecachete=20Duplicate=20werden=20n?=
 =?UTF-8?q?un=20beim=20L=C3=B6schen=20einer=20Person=20ebenso=20gel=C3=B6s?=
 =?UTF-8?q?cht.=20W=C3=A4re=20nach=20dem=20L=C3=B6schen=20dieses=20Kontakt?=
 =?UTF-8?q?es=20nur=20noch=20ein=20Duplikat=20in=20den=20Cluster=20eingetr?=
 =?UTF-8?q?agen,=20wird=20dieser=20automatisch=20mitgel=C3=B6scht.=20TODO?=
 =?UTF-8?q?=20Sobald=20Ignorieren=20Logik=20existiert,=20werden=20diese=20?=
 =?UTF-8?q?Eintr=C3=A4ge=20auch=20gel=C3=B6scht=20werden.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../onlyshowcontactids_param/valueProcess.js  |  5 +--
 .../_____LANGUAGE_EXTRA.aod                   |  9 +++++
 .../_____LANGUAGE_de/_____LANGUAGE_de.aod     | 12 +++++++
 .../_____LANGUAGE_en/_____LANGUAGE_en.aod     |  9 +++++
 process/DuplicateScanner_lib/process.js       | 34 ++++++++++++++++++-
 5 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/entity/Person_entity/entityfields/selfduplicates/children/onlyshowcontactids_param/valueProcess.js b/entity/Person_entity/entityfields/selfduplicates/children/onlyshowcontactids_param/valueProcess.js
index 0d12ba78972..0338fbaa15f 100644
--- a/entity/Person_entity/entityfields/selfduplicates/children/onlyshowcontactids_param/valueProcess.js
+++ b/entity/Person_entity/entityfields/selfduplicates/children/onlyshowcontactids_param/valueProcess.js
@@ -9,12 +9,9 @@ let duplicateIds = DuplicateScannerUtils.GetCachedDuplicatesForContactId(contact
 
 /*
  * To achieve that if there are no duplicates, no contacts should be shown and therefore returned by the 
- * recordcontainer, a "nonsense" id gets returned. It then is used in the conditionProcess.
+ * recordcontainer, an invalid id gets returned. It then is used in the conditionProcess to load the duplicates.
  * Because of its invalidity, no records are shown.
 */
-logging.log("duplicateIds -> " + duplicateIds);
-logging.log("duplicateIds -> " + duplicateIds.length);
-
 if(duplicateIds.length == 0)
     result.string(JSON.stringify(["nodata"]));
 else
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index c2aad558ee9..b78b681876f 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -4977,6 +4977,15 @@
     <entry>
       <key>Ignore Duplicate</key>
     </entry>
+    <entry>
+      <key>Integrate current into selected contact</key>
+    </entry>
+    <entry>
+      <key>Integrate selected into current contact</key>
+    </entry>
+    <entry>
+      <key>Duplicate actions</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 26fe06dafb0..ae4377a01ae 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -6268,6 +6268,18 @@
       <key>Ignore Duplicate</key>
       <value>Dublette ignorieren</value>
     </entry>
+    <entry>
+      <key>Integrate current into selected contact</key>
+      <value>Aktuellen Datensatz in selektierten integrieren</value>
+    </entry>
+    <entry>
+      <key>Integrate selected into current contact</key>
+      <value>Selektierten Datensatz in aktuellen integrieren</value>
+    </entry>
+    <entry>
+      <key>Duplicate actions</key>
+      <value>Dubletten Aktionen</value>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index 5a622924ea1..259ad7e781a 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5026,6 +5026,15 @@
     <entry>
       <key>Ignore Duplicate</key>
     </entry>
+    <entry>
+      <key>Integrate current into selected contact</key>
+    </entry>
+    <entry>
+      <key>Integrate selected into current contact</key>
+    </entry>
+    <entry>
+      <key>Duplicate actions</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js
index 4af56b3a054..30b78bc43f8 100644
--- a/process/DuplicateScanner_lib/process.js
+++ b/process/DuplicateScanner_lib/process.js
@@ -51,11 +51,43 @@ DuplicateScannerUtils.ScanForDuplicates = function(pFilterName, pTargetEntity, p
 //    }
 //}
 
-DuplicateScannerUtils.RemoveFromDuplicatesCache = function(pContactId)
+DuplicateScannerUtils.DeleteCachedDuplicate = function(pContactId)
 {
+    let query = "select count(ID), CLUSTERID from DUPLICATECLUSTERS"
+    + " where CLUSTERID = (select CLUSTERID from DUPLICATECLUSTERS where DUPLICATEID = '"+ pContactId +"')"
+    + " and DUPLICATEID != '"+ pContactId +"'"
+    + " group by CLUSTERID";
+
+    let coundAndClusterId = db.array(db.ROW, query);
+    let countDuplicatesInClusterWithoutParameterId = coundAndClusterId[0];
+    let clusterId = coundAndClusterId[1];
     
+    //If only one duplicate would be remaining, 
+    //the whole cluster has to be deleted because there are no more duplicates.
+    //Otherwise delete just the single duplicate.
+    if(countDuplicatesInClusterWithoutParameterId <= 1)
+    {
+        let deleteClusterCondition = "DUPLICATECLUSTERS.CLUSTERID = '"+ clusterId +"'";
+        db.deleteData("DUPLICATECLUSTERS", pCondition);
+    }
+    else
+    {
+        db.deleteData("DUPLICATECLUSTERS", "DUPLICATECLUSTERS.DUPLICATEID = '"+ pContactId +"'");
+    }
+    //todo delete from ignore table, too
 }
 
+DuplicateScannerUtils.IgnoreDuplicateRelation = function(pContactId1, pContactId2)
+{
+    
+}
+
+DuplicateScannerUtils.UnIgnoreDuplicateRelation = function(pContactId1, pContactId2)
+{
+    
+}
+
+
 DuplicateScannerUtils.GetCachedDuplicatesForContactId = function(pDuplicateId)
 {
     let querySelectDuplicateContactIds = "select DUPLICATEID from DUPLICATECLUSTERS"
-- 
GitLab