62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { getPayload } from 'payload'
|
|
import configPromise from '../src/payload.config'
|
|
|
|
async function run() {
|
|
const payload = await getPayload({ config: configPromise })
|
|
|
|
for (const locale of ['pl', 'de']) {
|
|
const pages = await payload.find({
|
|
collection: 'pages',
|
|
locale: locale as 'pl' | 'de',
|
|
where: {
|
|
slug: { equals: 'kontakt' }
|
|
}
|
|
})
|
|
|
|
if (pages.docs.length === 0) continue;
|
|
|
|
const page = pages.docs[0];
|
|
let updated = false;
|
|
|
|
// We do point updates on the layout array
|
|
const newLayout = page.layout?.map((block: any) => {
|
|
// If we find contactInfo, upgrade it to contactSection
|
|
if (block.blockType === 'contactInfo') {
|
|
updated = true;
|
|
return {
|
|
...block,
|
|
blockType: 'contactSection',
|
|
form: 1 // Add the form relation
|
|
}
|
|
}
|
|
// If we already have contactSection but missing form, just add it (just in case)
|
|
if (block.blockType === 'contactSection' && !block.form) {
|
|
updated = true;
|
|
return {
|
|
...block,
|
|
form: 1
|
|
}
|
|
}
|
|
return block;
|
|
});
|
|
|
|
if (updated) {
|
|
await payload.update({
|
|
collection: 'pages',
|
|
id: page.id,
|
|
locale: locale as 'pl' | 'de',
|
|
data: {
|
|
layout: newLayout
|
|
}
|
|
});
|
|
console.log(`Updated layout for ${locale.toUpperCase()}`);
|
|
} else {
|
|
console.log(`No contactInfo block found to upgrade for ${locale.toUpperCase()}`);
|
|
}
|
|
}
|
|
|
|
process.exit(0);
|
|
}
|
|
|
|
run().catch(console.error);
|