Fix remove project (#7941)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-02-06 12:41:36 +07:00
committed by GitHub
parent dad177e61d
commit 997d910821
9 changed files with 90 additions and 52 deletions
+1 -50
View File
@@ -14,17 +14,13 @@
//
import { Analytics } from '@hcengineering/analytics'
import core, {
type AttachedDoc,
import {
type Attribute,
type Class,
ClassifierKind,
type Client,
type Doc,
type DocManager,
type DocumentQuery,
DOMAIN_CONFIGURATION,
DOMAIN_MODEL,
getCurrentAccount,
type Ref,
type RelatedDocument,
@@ -275,52 +271,7 @@ async function deleteProject (project: Project | undefined): Promise<void> {
labelProps: { name: project.name },
message: tracker.string.DeleteProjectConfirm,
action: async () => {
// void client.update(project, { archived: true })
const client = getClient()
const classes = await client.findAll(core.class.Class, {})
const h = client.getHierarchy()
for (const c of classes) {
if (c.kind !== ClassifierKind.CLASS) {
continue
}
const d = h.findDomain(c._id)
if (d !== undefined && d !== DOMAIN_MODEL && d !== DOMAIN_CONFIGURATION) {
try {
while (true) {
const docs = await client.findAll(c._id, { space: project._id }, { limit: 50 })
if (docs.length === 0) {
break
}
const ops = client.apply(undefined, 'delete-project')
for (const object of docs) {
if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) {
const adoc = object as AttachedDoc
await ops
.removeCollection(
object._class,
object.space,
adoc._id,
adoc.attachedTo,
adoc.attachedToClass,
adoc.collection
)
.catch((err) => {
console.error(err)
})
} else {
await ops.removeDoc(object._class, object.space, object._id).catch((err) => {
console.error(err)
})
}
}
await ops.commit()
}
} catch (err: any) {
console.error(err)
Analytics.handleError(err)
}
}
}
await client.remove(project)
}
})