UBERF-4647 Use non-empty ydoc field name in wiki documents (#5673)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-05-27 21:13:15 +07:00 committed by GitHub
parent 0b76c264bc
commit 2b75ae92f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 10 deletions

View File

@ -49,6 +49,7 @@
"@hcengineering/tags": "^0.6.12", "@hcengineering/tags": "^0.6.12",
"@hcengineering/time": "^0.6.0", "@hcengineering/time": "^0.6.0",
"@hcengineering/document": "^0.6.0", "@hcengineering/document": "^0.6.0",
"@hcengineering/document-resources": "^0.6.0" "@hcengineering/document-resources": "^0.6.0",
"@hcengineering/collaboration": "^0.6.0"
} }
} }

View File

@ -14,7 +14,14 @@
// //
import { type Attachment } from '@hcengineering/attachment' import { type Attachment } from '@hcengineering/attachment'
import { DOMAIN_TX, getCollaborativeDoc, type Class, type Doc, type Ref } from '@hcengineering/core' import {
DOMAIN_TX,
getCollaborativeDoc,
MeasureMetricsContext,
type Class,
type Doc,
type Ref
} from '@hcengineering/core'
import { type Document, type Teamspace } from '@hcengineering/document' import { type Document, type Teamspace } from '@hcengineering/document'
import { import {
tryMigrate, tryMigrate,
@ -27,6 +34,7 @@ import core, { DOMAIN_SPACE } from '@hcengineering/model-core'
import { type Asset } from '@hcengineering/platform' import { type Asset } from '@hcengineering/platform'
import document, { documentId, DOMAIN_DOCUMENT } from './index' import document, { documentId, DOMAIN_DOCUMENT } from './index'
import { loadCollaborativeDoc, saveCollaborativeDoc, yDocCopyXmlField } from '@hcengineering/collaboration'
async function migrateCollaborativeContent (client: MigrationClient): Promise<void> { async function migrateCollaborativeContent (client: MigrationClient): Promise<void> {
const attachedFiles = await client.find<Attachment>(DOMAIN_ATTACHMENT, { const attachedFiles = await client.find<Attachment>(DOMAIN_ATTACHMENT, {
@ -265,6 +273,36 @@ async function migrateTeamspacesMixins (client: MigrationClient): Promise<void>
) )
} }
async function migrateContentField (client: MigrationClient): Promise<void> {
const ctx = new MeasureMetricsContext('migrate_content_field', {})
const storage = client.storageAdapter
if (storage === undefined) {
return
}
const documents = await client.find<Document>(DOMAIN_DOCUMENT, {
content: { $exists: true }
})
for (const document of documents) {
try {
const ydoc = await loadCollaborativeDoc(storage, client.workspaceId, document.content, ctx)
if (ydoc === undefined) {
continue
}
if (!ydoc.share.has('')) {
continue
}
yDocCopyXmlField(ydoc, '', 'content')
await saveCollaborativeDoc(storage, client.workspaceId, document.content, ydoc, ctx)
} catch {}
}
}
export const documentOperation: MigrateOperation = { export const documentOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> { async migrate (client: MigrationClient): Promise<void> {
await tryMigrate(client, documentId, [ await tryMigrate(client, documentId, [
@ -296,15 +334,15 @@ export const documentOperation: MigrateOperation = {
}, },
{ {
state: 'migrate-timespaces', state: 'migrate-timespaces',
func: async (client) => { func: migrateTeamspaces
await migrateTeamspaces(client)
}
}, },
{ {
state: 'migrate-teamspaces-mixins', state: 'migrate-teamspaces-mixins',
func: async (client) => { func: migrateTeamspacesMixins
await migrateTeamspacesMixins(client) },
} {
state: 'migrateContentField',
func: migrateContentField
} }
]) ])
}, },

View File

@ -75,7 +75,7 @@
export let collaborativeDoc: CollaborativeDoc export let collaborativeDoc: CollaborativeDoc
export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined
export let field: string | undefined = undefined export let field: string
export let objectClass: Ref<Class<Doc>> | undefined export let objectClass: Ref<Class<Doc>> | undefined
export let objectId: Ref<Doc> | undefined export let objectId: Ref<Doc> | undefined

View File

@ -30,7 +30,7 @@
export let collaborativeDoc: CollaborativeDoc export let collaborativeDoc: CollaborativeDoc
export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined
export let field: string | undefined = undefined export let field: string
export let objectClass: Ref<Class<Doc>> | undefined = undefined export let objectClass: Ref<Class<Doc>> | undefined = undefined
export let objectId: Ref<Doc> | undefined = undefined export let objectId: Ref<Doc> | undefined = undefined

View File

@ -93,6 +93,7 @@
objectClass={object._class} objectClass={object._class}
objectId={object._id} objectId={object._id}
objectAttr="content" objectAttr="content"
field="content"
{user} {user}
{userComponent} {userComponent}
{focusIndex} {focusIndex}