From 67c72553212368322f7fed9bcf5e259a52fdd5b5 Mon Sep 17 00:00:00 2001 From: "b.ulrich" <b.ulrich@bulrich.aditosoftware.local> Date: Fri, 14 Feb 2020 15:57:47 +0100 Subject: [PATCH] zwischencommit --- process/DuplicateScanner_lib/process.js | 38 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/process/DuplicateScanner_lib/process.js b/process/DuplicateScanner_lib/process.js index 53c5403b600..f94019bc937 100644 --- a/process/DuplicateScanner_lib/process.js +++ b/process/DuplicateScanner_lib/process.js @@ -50,7 +50,16 @@ DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity) */ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) { - var query = newSelect("count(ID), CLUSTERID from DUPLICATECLUSTERS") + + var query = newSelect("count(ID)") + .from("DUPLICATECLUSTERS") + .where("DUPLICATECLUSTERS.CLUSTERID", newSelect("CLUSTERID") + .from("DUPLICATECLUSTERS") + .where("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId).build(), + SqlBuilder.IN()) + .and("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId, SqlBuilder.NOT_EQUAL()); + +var test = newSelect("CLUSTERID") .from("DUPLICATECLUSTERS") .where("DUPLICATECLUSTERS.CLUSTERID", newSelect("CLUSTERID") .from("DUPLICATECLUSTERS") @@ -58,10 +67,20 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) SqlBuilder.IN()) .and("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId, SqlBuilder.NOT_EQUAL()) .groupBy("CLUSTERID"); + + var so = "select count(ID),( select CLUSTERID from DUPLICATECLUSTERS)" ++ " from DUPLICATECLUSTERS where DUPLICATECLUSTERS.CLUSTERID in" ++ " (select CLUSTERID from DUPLICATECLUSTERS where(DUPLICATECLUSTERS.DUPLICATEID = ('" + pDuplicateId + "')))" ++ " and(" ++ " DUPLICATECLUSTERS.DUPLICATEID <> ('" + pDuplicateId + "')" ++ " )" ++ " group by CLUSTERID" + var countAndClusterId = query.arrayRow(); + var testundso = test.arrayRow() let countDuplicatesInClusterWithoutParameterId = countAndClusterId[0]; - let clusterId = countAndClusterId[1]; + let clusterId = testundso[0]; //If only one duplicate would be remaining, //the whole cluster has to be deleted because there are no more duplicates. @@ -70,9 +89,10 @@ DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId) if(countDuplicatesInClusterWithoutParameterId <= 1) { let deleteStatements = []; + if(clusterId != null && clusterId != undefined){ deleteStatements.push(["DUPLICATECLUSTERS", newWhere("DUPLICATECLUSTERS.CLUSTERID", clusterId).build()]); deleteStatements.push(["UNRELATEDDUPLICATES", newWhere("UNRELATEDDUPLICATES.CLUSTERID", clusterId).build()]); - + } db.deletes(deleteStatements); } else @@ -635,9 +655,9 @@ DuplicateScannerUtils.TranslateEntityToIndexFields = function(pEntityName, pEnti */ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId) { - let updateStatementsCurrentAlias = []; - let updateStatementsSystemAlias = []; - let deleteStatements = []; + var updateStatementsCurrentAlias = []; + var updateStatementsSystemAlias = []; + var deleteStatements = []; var sourcePersonId = newSelect("PERSON_ID") .from("CONTACT") @@ -656,9 +676,9 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId) deleteStatements = deleteStatements.concat(_DuplicateScannerUtils._buildDeletePersonAndContactQuery(sourcePersonId, pSourceContactId)); deleteStatements = deleteStatements.concat(_DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery(pSourceContactId)); - let affectedRowsCurrentAlias = db.updates(updateStatementsCurrentAlias); - let affectedRowsSystemAlias = db.updates(updateStatementsSystemAlias, SqlUtils.getSystemAlias()); - let deletedRows = db.deletes(deleteStatements) + var affectedRowsCurrentAlias = db.updates(updateStatementsCurrentAlias); + var affectedRowsSystemAlias = db.updates(updateStatementsSystemAlias, SqlUtils.getSystemAlias()); + var deletedRows = db.deletes(deleteStatements) DuplicateScannerUtils.DeleteCachedDuplicate(pSourceContactId); -- GitLab