Files
klz-cables.com/.pnpm-store/v10/files/86/22c7f8a7e4f22e85913df7301f56df24cfe99298646755bf9eaa39d1ec713b2aef6955f2c281ee3d8b63c7e44c0847043594ca800e4aabdd28b325a44cb2f4
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

173 lines
7.0 KiB
Plaintext

import { upsertRow } from '../../../../upsertRow/index.js';
import { traverseFields } from './traverseFields.js';
export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName })=>{
for (const [id, rows] of Object.entries(docsToResave)){
if (collectionSlug) {
const collectionConfig = payload.collections[collectionSlug].config;
if (collectionConfig) {
if (isVersions) {
const doc = await payload.findVersionByID({
id,
collection: collectionSlug,
depth: 0,
fallbackLocale: null,
locale: 'all',
req,
showHiddenFields: true
});
if (debug) {
payload.logger.info(`The collection "${collectionConfig.slug}" version with ID ${id} will be migrated`);
}
traverseFields({
doc,
fields,
path: '',
rows
});
try {
await upsertRow({
id: doc.id,
adapter,
collectionSlug,
data: doc,
db,
fields,
ignoreResult: true,
operation: 'update',
req,
tableName
});
} catch (err) {
payload.logger.error(`"${collectionConfig.slug}" version with ID ${doc.id} FAILED TO MIGRATE`);
throw err;
}
if (debug) {
payload.logger.info(`"${collectionConfig.slug}" version with ID ${doc.id} migrated successfully!`);
}
} else {
const doc = await payload.findByID({
id,
collection: collectionSlug,
depth: 0,
fallbackLocale: null,
locale: 'all',
req,
showHiddenFields: true
});
if (debug) {
payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} will be migrated`);
}
traverseFields({
doc,
fields,
path: '',
rows
});
try {
await upsertRow({
id: doc.id,
adapter,
collectionSlug,
data: doc,
db,
fields,
ignoreResult: true,
operation: 'update',
req,
tableName
});
} catch (err) {
payload.logger.error(`The collection "${collectionConfig.slug}" with ID ${doc.id} has FAILED TO MIGRATE`);
throw err;
}
if (debug) {
payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} has migrated successfully!`);
}
}
}
}
if (globalSlug) {
const globalConfig = payload.config.globals?.find((global)=>global.slug === globalSlug);
if (globalConfig) {
if (isVersions) {
const { docs } = await payload.findGlobalVersions({
slug: globalSlug,
depth: 0,
fallbackLocale: null,
limit: 0,
locale: 'all',
req,
showHiddenFields: true
});
if (debug) {
payload.logger.info(`${docs.length} global "${globalSlug}" versions will be migrated`);
}
for (const doc of docs){
traverseFields({
doc,
fields,
path: '',
rows
});
try {
await upsertRow({
id: doc.id,
adapter,
data: doc,
db,
fields,
globalSlug,
ignoreResult: true,
operation: 'update',
req,
tableName
});
} catch (err) {
payload.logger.error(`"${globalSlug}" version with ID ${doc.id} FAILED TO MIGRATE`);
throw err;
}
if (debug) {
payload.logger.info(`"${globalSlug}" version with ID ${doc.id} migrated successfully!`);
}
}
} else {
const doc = await payload.findGlobal({
slug: globalSlug,
depth: 0,
fallbackLocale: null,
locale: 'all',
req,
showHiddenFields: true
});
traverseFields({
doc,
fields,
path: '',
rows
});
try {
await upsertRow({
adapter,
data: doc,
db,
fields,
globalSlug,
ignoreResult: true,
operation: 'update',
req,
tableName
});
} catch (err) {
payload.logger.error(`The global "${globalSlug}" has FAILED TO MIGRATE`);
throw err;
}
if (debug) {
payload.logger.info(`The global "${globalSlug}" has migrated successfully!`);
}
}
}
}
}
};
//# sourceMappingURL=index.js.map