fix(richtext-lexical): slate => lexical migrator improvements (#7802)
This commit is contained in:
@@ -19,7 +19,7 @@ export const SlateLinkConverter: SlateNodeConverter = {
|
||||
doc: slateNode.doc || null,
|
||||
linkType: slateNode.linkType || 'custom',
|
||||
newTab: slateNode.newTab || false,
|
||||
url: slateNode.url || undefined,
|
||||
url: (slateNode.linkType || 'custom') === 'custom' ? slateNode.url || 'https' : undefined, // can be undefined only if linkType is not custom, otherwise: validation error
|
||||
},
|
||||
format: '',
|
||||
indent: 0,
|
||||
|
||||
@@ -15,6 +15,8 @@ import { migrateDocumentFieldsRecursively } from './migrateDocumentFieldsRecursi
|
||||
export async function migrateSlateToLexical({ payload }: { payload: Payload }) {
|
||||
const collections = payload.config.collections
|
||||
|
||||
const errors = []
|
||||
|
||||
const allLocales = payload.config.localization ? payload.config.localization.localeCodes : [null]
|
||||
|
||||
const totalCollections = collections.length
|
||||
@@ -25,6 +27,7 @@ export async function migrateSlateToLexical({ payload }: { payload: Payload }) {
|
||||
await migrateCollection({
|
||||
collection,
|
||||
cur: curCollection,
|
||||
errors,
|
||||
locale,
|
||||
max: totalCollections,
|
||||
payload,
|
||||
@@ -32,19 +35,28 @@ export async function migrateSlateToLexical({ payload }: { payload: Payload }) {
|
||||
}
|
||||
for (const global of payload.config.globals) {
|
||||
await migrateGlobal({
|
||||
errors,
|
||||
global,
|
||||
locale,
|
||||
payload,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(`Found ${errors.length} errors::`, JSON.stringify(errors, null, 2))
|
||||
} else {
|
||||
console.log('Migration successful - no errors')
|
||||
}
|
||||
}
|
||||
|
||||
async function migrateGlobal({
|
||||
errors,
|
||||
global,
|
||||
locale,
|
||||
payload,
|
||||
}: {
|
||||
errors: any[]
|
||||
global: GlobalConfig
|
||||
locale: null | string
|
||||
payload: Payload
|
||||
@@ -54,6 +66,7 @@ async function migrateGlobal({
|
||||
const document = await payload.findGlobal({
|
||||
slug: global.slug,
|
||||
depth: 0,
|
||||
draft: true,
|
||||
locale: locale || undefined,
|
||||
overrideAccess: true,
|
||||
})
|
||||
@@ -69,14 +82,15 @@ async function migrateGlobal({
|
||||
slug: global.slug,
|
||||
data: document,
|
||||
depth: 0,
|
||||
draft: document?._status === 'draft',
|
||||
locale: locale || undefined,
|
||||
})
|
||||
// Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration
|
||||
} catch (e) {
|
||||
console.log('Error updating global', e, {
|
||||
id: document.id,
|
||||
slug: global.slug,
|
||||
})
|
||||
errors.push(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,12 +98,14 @@ async function migrateGlobal({
|
||||
async function migrateCollection({
|
||||
collection,
|
||||
cur,
|
||||
errors,
|
||||
locale,
|
||||
max,
|
||||
payload,
|
||||
}: {
|
||||
collection: CollectionConfig
|
||||
cur: number
|
||||
errors: any[]
|
||||
locale: null | string
|
||||
max: number
|
||||
payload: Payload
|
||||
@@ -115,6 +131,7 @@ async function migrateCollection({
|
||||
const documents = await payload.find({
|
||||
collection: collection.slug,
|
||||
depth: 0,
|
||||
draft: true,
|
||||
locale: locale || undefined,
|
||||
overrideAccess: true,
|
||||
page,
|
||||
@@ -150,10 +167,13 @@ async function migrateCollection({
|
||||
collection: collection.slug,
|
||||
data: document,
|
||||
depth: 0,
|
||||
draft: document?._status === 'draft',
|
||||
locale: locale || undefined,
|
||||
})
|
||||
// Catch it, because some errors were caused by the user previously (e.g. invalid relationships) and will throw an error now, even though they are not related to the migration
|
||||
} catch (e) {
|
||||
errors.push(e)
|
||||
|
||||
console.log('Error updating collection', e, {
|
||||
id: document.id,
|
||||
slug: collection.slug,
|
||||
|
||||
Reference in New Issue
Block a user