import type { BasePayload } from 'payload' type MongoGlobals = { collection?: { updateOne: ( filter: Record, update: Record[], ) => 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 { 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' }) } }