mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-29 14:34:12 +03:00
fix updateAllRefs to support attached docs and mixins (#6033)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
5c4f0c55cb
commit
5d948fe3a7
@ -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)
|
||||
)
|
||||
})
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user