Skip to content

Commit

Permalink
fix updateAllRefs to support attached docs and mixins (#6033)
Browse files Browse the repository at this point in the history
Signed-off-by: Vyacheslav Tumanov <[email protected]>
  • Loading branch information
ThetaDR authored Jul 10, 2024
1 parent 5c4f0c5 commit 5d948fe
Showing 1 changed file with 46 additions and 41 deletions.
87 changes: 46 additions & 41 deletions plugins/contact-resources/src/components/MergePersons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<Doc>
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)
)
})
Expand All @@ -239,55 +240,59 @@
continue
}
const to = attr.type as RefTo<Doc>
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<Doc>
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<Doc>
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()
}
}
}
Expand Down

0 comments on commit 5d948fe

Please sign in to comment.