78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { getPayload } from 'payload'
|
|
import configPromise from '../src/payload.config'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
async function run() {
|
|
const payload = await getPayload({ config: configPromise })
|
|
|
|
const snapshotPath = path.join(process.cwd(), 'scripts', 'content-snapshot.json')
|
|
const snapshot = JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'))
|
|
const kontaktSnap = snapshot.pages.find((p: any) => p.pl.slug === 'kontakt')
|
|
|
|
if (!kontaktSnap) {
|
|
console.error("No kontakt in snapshot")
|
|
return
|
|
}
|
|
|
|
// Find actual page ID
|
|
const dbPages = await payload.find({ collection: 'pages', where: { slug: { equals: 'kontakt' } } })
|
|
const dbPage = dbPages.docs[0]
|
|
|
|
if (!dbPage) {
|
|
console.error("No kontakt in DB")
|
|
return
|
|
}
|
|
|
|
for (const loc of ['pl', 'de', 'en']) {
|
|
let layout = kontaktSnap[loc]?.layout
|
|
if (!layout && loc === 'en') {
|
|
// fallback to PL for layout structure
|
|
layout = JSON.parse(JSON.stringify(kontaktSnap.pl.layout))
|
|
}
|
|
if (!layout) continue;
|
|
|
|
const newLayout = layout.map((block: any) => {
|
|
const b = { ...block }
|
|
delete b.id // VERY IMPORTANT to avoid SQLite unique constraint errors or table mismatches
|
|
|
|
// If we find contactInfo, UPGRADE it to contactSection and attach form 1!
|
|
if (b.blockType === 'contactInfo' || b.blockType === 'contactSection') {
|
|
b.blockType = 'contactSection'
|
|
b.form = 1 // We created form 1 earlier
|
|
}
|
|
|
|
// Fix EN translations if this is EN
|
|
if (loc === 'en') {
|
|
if (b.blockType === 'pageHeader') {
|
|
b.title = "Contact"
|
|
b.subtitle = "Do you have questions about tax settlement in Germany? Contact us — we will be happy to help."
|
|
}
|
|
if (b.blockType === 'contactSection') {
|
|
b.address = "TO BE CONFIRMED BY CLIENT"
|
|
b.hours = "Mon-Fri: 9:00 - 17:00\nBy appointment"
|
|
}
|
|
}
|
|
|
|
return b
|
|
})
|
|
|
|
const title = loc === 'en' ? 'Contact' : (loc === 'de' ? 'Kontakt' : 'Kontakt')
|
|
|
|
await payload.update({
|
|
collection: 'pages',
|
|
id: dbPage.id,
|
|
locale: loc as any,
|
|
data: {
|
|
title,
|
|
layout: newLayout
|
|
}
|
|
})
|
|
console.log(`Restored kontakt in ${loc}`)
|
|
}
|
|
|
|
process.exit(0)
|
|
}
|
|
|
|
run().catch(console.error)
|