Skip to content
Snippets Groups Projects
Commit 03c32b5d authored by Sascha Schmidt's avatar Sascha Schmidt
Browse files

[Projekt: xRM-ContactManagement][TicketNr.: 1083861][Dubletten Merge kann...

[Projekt: xRM-ContactManagement][TicketNr.: 1083861][Dubletten Merge kann Dateninkonsistenzen erzeugen]
parent e786d33a
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,9 @@ DuplicateMergeUtils.mergeContext = function(pContext, pSourceContactId, pTargetC
*/
DuplicateMergeUtils.mergePerson = function(pSourceContactId, pTargetContactId)
{
//@Workaround @TODO because COMMUNICATION.OBJECT_TYPE is not right -> has to be "Person"
var pObjectType = "Contact";
var sourcePersonId = newSelect("PERSON_ID")
.from("CONTACT")
.where("CONTACT.CONTACTID", pSourceContactId)
......@@ -86,7 +89,7 @@ DuplicateMergeUtils.mergePerson = function(pSourceContactId, pTargetContactId)
.cell();
DuplicateMergeUtils._deleteUniqueAttributes(pSourceContactId, pTargetContactId);
var isLinkedDataUpdated = DuplicateMergeUtils._migrateLinkedContactData(pSourceContactId, pTargetContactId);
var isLinkedDataUpdated = DuplicateMergeUtils._migrateLinkedContactData(pSourceContactId, pTargetContactId, pObjectType);
var isParticipantsUpdated = DuplicateMergeUtils._migrateParticipantsToNewContact("CAMPAIGNPARTICIPANT", "CONTACT_ID", "CAMPAIGN_ID",
pSourceContactId, pTargetContactId);
DuplicateMergeUtils._updateOtherContacts(pSourceContactId, sourcePersonId, targetPersonId);
......@@ -115,6 +118,9 @@ DuplicateMergeUtils.mergePerson = function(pSourceContactId, pTargetContactId)
DuplicateMergeUtils.mergeOrganisation = function(pSourceContactId, pTargetContactId)
{
//@Workaround @TODO because COMMUNICATION.OBJECT_TYPE is not right -> has to be "Organisation"
var pObjectType = "Contact";
var sourceOrganisationId = newSelect("ORGANISATION_ID")
.from("CONTACT")
.where("CONTACT.CONTACTID", pSourceContactId)
......@@ -126,7 +132,7 @@ DuplicateMergeUtils.mergeOrganisation = function(pSourceContactId, pTargetContac
.cell();
DuplicateMergeUtils._deleteUniqueAttributes(pSourceContactId, pTargetContactId);
DuplicateMergeUtils._migrateLinkedContactData(pSourceContactId, pTargetContactId);
DuplicateMergeUtils._migrateLinkedContactData(pSourceContactId, pTargetContactId, pObjectType);
DuplicateMergeUtils._migrateParticipantsToNewContact("CAMPAIGNPARTICIPANT", "CONTACT_ID", "CAMPAIGN_ID",
pSourceContactId, pTargetContactId);
DuplicateMergeUtils._migratePersonsToNewOrganisation(sourceOrganisationId, targetOrganisationId);
......@@ -204,7 +210,7 @@ DuplicateMergeUtils._deleteUniqueAttributes = function (pSourceContactId, pTarge
return deleteCount > 0;
}
DuplicateMergeUtils._migrateLinkedContactData = function (pSourceContactId, pTargetContactId)
DuplicateMergeUtils._migrateLinkedContactData = function (pSourceContactId, pTargetContactId, pObjectType)
{
var updateStatements = new Map();
var currentAlias = db.getCurrentAlias();
......@@ -224,7 +230,7 @@ DuplicateMergeUtils._migrateLinkedContactData = function (pSourceContactId, pTar
{
setStandardsStatements.push(
newWhere("COMMUNICATION.OBJECT_ROWID", pSourceContactId)
.and("COMMUNICATION.OBJECT_TYPE", "Contact")
.and("COMMUNICATION.OBJECT_TYPE", pObjectType)
.and("COMMUNICATION.MEDIUM_ID", CommUtil.getMediumIdsByCategory("PHONE"), SqlBuilder.IN())
.buildUpdateStatement({"ISSTANDARD" : "0"})
);
......@@ -233,7 +239,7 @@ DuplicateMergeUtils._migrateLinkedContactData = function (pSourceContactId, pTar
{
setStandardsStatements.push(
newWhere("COMMUNICATION.OBJECT_ROWID", pSourceContactId)
.and("COMMUNICATION.OBJECT_TYPE", "Contact")
.and("COMMUNICATION.OBJECT_TYPE", pObjectType)
.and("COMMUNICATION.MEDIUM_ID", CommUtil.getMediumIdsByCategory("EMAIL"), SqlBuilder.IN())
.buildUpdateStatement({"ISSTANDARD" : "0"})
);
......@@ -281,7 +287,7 @@ DuplicateMergeUtils._migrateLinkedContactData = function (pSourceContactId, pTar
//delete leftover communications from the source contact
totalChanges += newWhere("COMMUNICATION.OBJECT_ROWID", pSourceContactId)
.and("COMMUNICATION.OBJECT_TYPE", "Contact")
.and("COMMUNICATION.OBJECT_TYPE", pObjectType)
.deleteData();
totalChanges += new AttributeRelationQuery(pSourceContactId).deleteAllAttributes(); //delete leftover attributes
......@@ -357,21 +363,21 @@ DuplicateMergeUtils._buildDeleteOrganisationAndContactQuery = function(pSourceOr
*
* @returns {String[[]]} Array in the format [TableName, ContactIdColumnName, AdditionalCondition, alias]
*/
DuplicateMergeUtils._getLinkedTableInfos = function(pTargetContactId)
DuplicateMergeUtils._getLinkedTableInfos = function(pTargetContactId, pObjectType)
{
//don't use communications that the target already has
var targetComms = newSelect("COMMUNICATION.ADDR")
.from("COMMUNICATION")
.where("COMMUNICATION.OBJECT_ROWID", pTargetContactId)
.and("COMMUNICATION.OBJECT_TYPE", "Contact")
.and("COMMUNICATION.OBJECT_TYPE", pObjectType)
.arrayColumn();
var communicationDedupCondition = targetComms.length > 0
? newWhere("COMMUNICATION.ADDR", targetComms, SqlBuilder.NOT_IN())
: "";
? newWhere("COMMUNICATION.ADDR", targetComms, SqlBuilder.NOT_IN()).and("COMMUNICATION.OBJECT_TYPE", pObjectType)
: newWhere("COMMUNICATION.OBJECT_TYPE", pObjectType);
return[
["AB_APPOINTMENTLINK", "OBJECT_ROWID"],
["AB_APPOINTMENTLINK", "OBJECT_ROWID", newWhere("AB_APPOINTMENTLINK.OBJECT_TYPE", pObjectType)],
["AB_CTILOG", "CONTACT_ID"],
["AB_OBJECTRELATION", "AB_OBJECTRELATIONID"],
["AB_OBJECTRELATION", "OBJECT1_ROWID"],
......@@ -396,13 +402,13 @@ DuplicateMergeUtils._getLinkedTableInfos = function(pTargetContactId)
["SALESPROJECT", "CONTACT_ID"],
["TASK", "REQUESTOR_CONTACT_ID"],
["TASK", "EDITOR_CONTACT_ID"],
["TASKLINK", "OBJECT_ROWID"],
["TASKLINK", "OBJECT_ROWID", newWhere("TASKLINK.OBJECT_TYPE", pObjectType)],
["ACTIVITY", "RESPONSIBLE"],
["DSGVO", "CONTACT_ID"],
["DSGVOINFO", "CONTACT_ID"],
["TIMETRACKING", "CONTACT_ID"],
["ACTIVITYLINK", "OBJECT_ROWID"],
["AB_ATTRIBUTERELATION", "OBJECT_ROWID"],
["ACTIVITYLINK", "OBJECT_ROWID", newWhere("AB_APPOINTMENTLINK.OBJECT_TYPE", pObjectType)],
["AB_ATTRIBUTERELATION", "OBJECT_ROWID", newWhere("AB_APPOINTMENTLINK.OBJECT_TYPE", pObjectType)],
["ASYS_CALENDARLINK", "DBID", "", SqlUtils.getSystemAlias()]
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment