Files
ipal-kit/src/globals/CookieSettings/migrateSaveButton.ts
T
Radosław SmolińskiandClaude Fable 5.2 0a4f001797 IAPL rename, scripted: preferred names in src, bin, scripts, services, tests; bin files and skill folders moved
Replaced by an explicit list of forms only (ten exported names, runtime env names, project file
names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import
paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are
not touched. package.json keeps the five old bin names beside the five new ones.
The old names stop working in this commit and come back as aliases in the next; docs follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:24:21 +01:00

40 lines
1.6 KiB
TypeScript

import type { BasePayload } from 'payload'
type MongoGlobals = {
collection?: {
updateOne: (
filter: Record<string, unknown>,
update: Record<string, unknown>[],
) => Promise<{ modifiedCount?: number }>
}
}
/**
* 1.11.1 renamed Cookie Settings `buttons.save` → `buttons.savePreferences` (Mongoose
* reserves `save`). MongoDB keeps the old key, but the first save of the global — panel
* or script — rewrites the document without it, and the button text silently falls back
* to "Save preferences" in every language. Runs once per start: copies the old value
* (all locales at once) into the new field when the new one is still missing.
* SQL adapters: the column rename happens in the migration (`migrate:create` → rename).
*/
export async function migrateCookieSettingsSaveButton(payload: BasePayload): Promise<void> {
if (payload.db.name !== 'mongoose') {return}
const globals = (payload.db as unknown as { globals?: MongoGlobals }).globals
if (!globals?.collection) {return}
try {
const result = await globals.collection.updateOne(
{
'buttons.save': { $exists: true },
'buttons.savePreferences': { $exists: false },
globalType: 'cookie-settings',
},
[{ $set: { 'buttons.savePreferences': '$buttons.save' } }],
)
if (result.modifiedCount) {
payload.logger.info('[iapl] Cookie Settings: buttons.save copied to buttons.savePreferences (1.11.1 rename).')
}
} catch (error) {
payload.logger.error({ err: error, msg: '[iapl] Cookie Settings: could not migrate buttons.save → buttons.savePreferences' })
}
}