mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 12:35:02 +02:00
Fix remove project (#7941)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user