From 5d948fe3a717058a98f339210a3efb336478ca42 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Wed, 10 Jul 2024 11:19:09 +0500 Subject: [PATCH] fix updateAllRefs to support attached docs and mixins (#6033) Signed-off-by: Vyacheslav Tumanov --- .../src/components/MergePersons.svelte | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/plugins/contact-resources/src/components/MergePersons.svelte b/plugins/contact-resources/src/components/MergePersons.svelte index 0c48147a50..c4021865d4 100644 --- a/plugins/contact-resources/src/components/MergePersons.svelte +++ b/plugins/contact-resources/src/components/MergePersons.svelte @@ -224,13 +224,14 @@ const h = client.getHierarchy() // Move all possible references to Account and Employee and replace to target one. + const anchestors = h.getAncestors(contact.class.Person) const reftos = (await client.findAll(core.class.Attribute, { 'type._class': core.class.RefTo })).filter((it) => { const to = it.type as RefTo return ( - to.to === contact.class.Person || - to.to === contact.mixin.Employee || to.to === core.class.Account || - to.to === contact.class.PersonAccount + to.to === contact.class.PersonAccount || + h.getBaseClass(to.to) === contact.class.Person || + anchestors.includes(to.to) ) }) @@ -239,55 +240,59 @@ continue } const to = attr.type as RefTo - if (to.to === contact.mixin.Employee || to.to === contact.class.Person) { - const descendants = h.getDescendants(attr.attributeOf) - for (const d of descendants) { - if (h.isDerived(d, core.class.Tx)) { - continue - } - if (h.findDomain(d) !== undefined) { - while (true) { - const values = await client.findAll(d, { [attr.name]: sourceAccount._id }, { limit: 100 }) - if (values.length === 0) { - break - } + const descendants = h.getDescendants(attr.attributeOf) + for (const d of descendants) { + if (h.isDerived(d, core.class.Tx) || h.isDerived(d, core.class.BenchmarkDoc)) { + continue + } + if (h.findDomain(d) !== undefined) { + while (true) { + const values = await client.findAll(d, { [attr.name]: sourceAccount._id }, { limit: 100 }) + if (values.length === 0) { + break + } - const builder = client.apply(sourceAccount._id) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id) - } - if (builder.txes.length > 0) { - await builder.commit() - } + const builder = client.apply(sourceAccount._id) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id) + } + if (builder.txes.length > 0) { + await builder.commit() } } } } } - const arrs = await client.findAll(core.class.Attribute, { 'type._class': core.class.ArrOf }) + const arrs = (await client.findAll(core.class.Attribute, { 'type._class': core.class.ArrOf })).filter((it) => { + const to = it.type as RefTo + return ( + to.to === core.class.Account || + to.to === contact.class.PersonAccount || + h.getBaseClass(to.to) === contact.class.Person || + anchestors.includes(to.to) + ) + }) + for (const attr of arrs) { if (attr.name === '_id') { continue } - const to = attr.type as RefTo - if (to.to === contact.mixin.Employee || to.to === contact.class.Person) { - const descendants = h.getDescendants(attr.attributeOf) - for (const d of descendants) { - if (h.isDerived(d, core.class.Tx)) { - continue - } - if (h.findDomain(d) !== undefined) { - while (true) { - const values = await client.findAll(attr.attributeOf, { [attr.name]: sourceAccount._id }, { limit: 100 }) - if (values.length === 0) { - break - } - const builder = client.apply(sourceAccount._id) - for (const v of values) { - await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id) - } - await builder.commit() + const descendants = h.getDescendants(attr.attributeOf) + for (const d of descendants) { + if (h.isDerived(d, core.class.Tx) || h.isDerived(d, core.class.BenchmarkDoc)) { + continue + } + if (h.findDomain(d) !== undefined) { + while (true) { + const values = await client.findAll(attr.attributeOf, { [attr.name]: sourceAccount._id }, { limit: 100 }) + if (values.length === 0) { + break + } + const builder = client.apply(sourceAccount._id) + for (const v of values) { + await updateAttribute(builder, v, d, { key: attr.name, attr }, targetAccount._id) } + await builder.commit() } } }