mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-29 09:09:15 +03:00
TSK-1213: Allow to clean archived vacancies with content (#2999)
This commit is contained in:
parent
7f68032397
commit
f590002b94
@ -157,7 +157,7 @@
|
||||
"@hcengineering/document": "^0.6.0",
|
||||
"@hcengineering/document-assets": "^0.6.0",
|
||||
"@hcengineering/document-resources": "^0.6.0",
|
||||
"@hcengineering/bitrix": "^0.6.30",
|
||||
"@hcengineering/bitrix": "^0.6.31",
|
||||
"@hcengineering/bitrix-assets": "^0.6.0",
|
||||
"@hcengineering/bitrix-resources": "^0.6.0",
|
||||
"@hcengineering/request": "^0.6.0",
|
||||
|
@ -162,3 +162,45 @@ export async function cleanRemovedTransactions (workspaceId: WorkspaceId, transa
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
export async function cleanArchivedSpaces (workspaceId: WorkspaceId, transactorUrl: string): Promise<void> {
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
try {
|
||||
const count = 0
|
||||
const ops = new TxOperations(connection, core.account.System)
|
||||
while (true) {
|
||||
const spaces = await connection.findAll(core.class.Space, { archived: true }, { limit: 1000 })
|
||||
if (spaces.length === 0) {
|
||||
break
|
||||
}
|
||||
|
||||
const h = connection.getHierarchy()
|
||||
const withDomain = h
|
||||
.getDescendants(core.class.Doc)
|
||||
.filter((it) => h.findDomain(it) !== undefined)
|
||||
.filter((it) => !h.isMixin(it))
|
||||
for (const c of withDomain) {
|
||||
while (true) {
|
||||
const docs = await connection.findAll(c, { space: { $in: spaces.map((it) => it._id) } })
|
||||
if (docs.length === 0) {
|
||||
break
|
||||
}
|
||||
console.log('removing:', c, docs.length)
|
||||
for (const d of docs) {
|
||||
await ops.remove(d)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const s of spaces) {
|
||||
await ops.remove(s)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('total docs with remove', count)
|
||||
} catch (err: any) {
|
||||
console.trace(err)
|
||||
} finally {
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ import { Data, getWorkspaceId, Tx, Version } from '@hcengineering/core'
|
||||
import { MinioService } from '@hcengineering/minio'
|
||||
import { MigrateOperation } from '@hcengineering/model'
|
||||
import { openAIConfigDefaults } from '@hcengineering/openai'
|
||||
import { cleanArchivedSpaces, cleanRemovedTransactions, cleanWorkspace } from './clean'
|
||||
import { rebuildElastic } from './elastic'
|
||||
import { openAIConfig } from './openai'
|
||||
import { cleanRemovedTransactions, cleanWorkspace } from './clean'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -463,5 +463,12 @@ export function devTool (
|
||||
await cleanRemovedTransactions(getWorkspaceId(workspace, productId), transactorUrl)
|
||||
})
|
||||
|
||||
program
|
||||
.command('clean-archived-spaces <workspace>')
|
||||
.description('clean archived spaces')
|
||||
.action(async (workspace: string, cmd: any) => {
|
||||
await cleanArchivedSpaces(getWorkspaceId(workspace, productId), transactorUrl)
|
||||
})
|
||||
|
||||
program.parse(process.argv)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
"@hcengineering/view": "^0.6.4",
|
||||
"@hcengineering/model-view": "^0.6.0",
|
||||
"@hcengineering/contact": "^0.6.13",
|
||||
"@hcengineering/bitrix": "^0.6.30",
|
||||
"@hcengineering/bitrix": "^0.6.31",
|
||||
"@hcengineering/bitrix-resources": "^0.6.0",
|
||||
"@hcengineering/preference": "^0.6.4",
|
||||
"@hcengineering/model-preference": "^0.6.0",
|
||||
|
@ -30,6 +30,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hcengineering/platform": "^0.6.8",
|
||||
"@hcengineering/bitrix": "^0.6.30"
|
||||
"@hcengineering/bitrix": "^0.6.31"
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
"dependencies": {
|
||||
"@hcengineering/platform": "^0.6.8",
|
||||
"svelte": "3.55.1",
|
||||
"@hcengineering/bitrix": "^0.6.30",
|
||||
"@hcengineering/bitrix": "^0.6.31",
|
||||
"@hcengineering/ui": "^0.6.6",
|
||||
"@hcengineering/presentation": "^0.6.2",
|
||||
"@hcengineering/text-editor": "^0.6.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/bitrix",
|
||||
"version": "0.6.30",
|
||||
"version": "0.6.31",
|
||||
"main": "lib/index.js",
|
||||
"author": "Anticrm Platform Contributors",
|
||||
"license": "EPL-2.0",
|
||||
|
@ -174,10 +174,30 @@ export async function syncDocument (
|
||||
attachedTo: { $in: [resultDoc.document._id, ...attachIds] }
|
||||
})
|
||||
for (const [ed, op, upd] of resultDoc.blobs) {
|
||||
const existing = existingBlobs.find((it) => {
|
||||
let existing = existingBlobs.find((it) => {
|
||||
const bdoc = hierarchy.as<Doc, BitrixSyncDoc>(it, bitrix.mixin.BitrixSyncDoc)
|
||||
return bdoc.bitrixId === ed.bitrixId
|
||||
})
|
||||
// Check attachment document exists in our storage.
|
||||
|
||||
if (existing !== undefined) {
|
||||
const ex = existing
|
||||
try {
|
||||
const resp = await fetch(concatLink(frontUrl, `/files?file=${existing?.file}&token=${info.token}`), {
|
||||
method: 'GET'
|
||||
})
|
||||
if (!resp.ok) {
|
||||
// Attachment is broken and need to be re-added.
|
||||
await applyOp.remove(ex)
|
||||
existing = undefined
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
await applyOp.remove(ex)
|
||||
existing = undefined
|
||||
}
|
||||
}
|
||||
|
||||
// For Attachments, just do it once per attachment and assume it is not changed.
|
||||
if (existing === undefined) {
|
||||
const attachmentId: Ref<Attachment> = generateId()
|
||||
@ -963,6 +983,13 @@ async function synchronizeUsers (
|
||||
syncTime: Date.now()
|
||||
})
|
||||
}
|
||||
// TODO: Commented to replace names
|
||||
// if (emp !== undefined && emp.name !== combineName(u.NAME, u.LAST_NAME)) {
|
||||
// await ops.client.update(emp, { name: combineName(u.NAME, u.LAST_NAME) })
|
||||
// }
|
||||
// if (account.name !== combineName(u.NAME, u.LAST_NAME)) {
|
||||
// await ops.client.update(account, { name: combineName(u.NAME, u.LAST_NAME) })
|
||||
// }
|
||||
}
|
||||
userList.set(u.ID, accountId)
|
||||
}
|
||||
|
@ -135,7 +135,7 @@
|
||||
"@hcengineering/board": "^0.6.4",
|
||||
"@hcengineering/hr": "^0.6.4",
|
||||
"@hcengineering/document": "^0.6.0",
|
||||
"@hcengineering/bitrix": "^0.6.30",
|
||||
"@hcengineering/bitrix": "^0.6.31",
|
||||
"@hcengineering/request": "^0.6.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user