strapi-plugin-bulk-updater 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +1081 -848
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1081 -848
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -335,6 +335,137 @@ const contentTypes = {
|
|
|
335
335
|
schema: auditLog
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
|
+
const CRASH_GUARD_SYMBOL = Symbol.for("strapi-plugin-bulk-updater.undiciCrashGuardInstalled");
|
|
339
|
+
let activeBulkOperations = 0;
|
|
340
|
+
function getActiveBulkOperationCount() {
|
|
341
|
+
return activeBulkOperations;
|
|
342
|
+
}
|
|
343
|
+
async function trackActiveBulkOperation(fn) {
|
|
344
|
+
activeBulkOperations++;
|
|
345
|
+
try {
|
|
346
|
+
return await fn();
|
|
347
|
+
} finally {
|
|
348
|
+
activeBulkOperations = Math.max(0, activeBulkOperations - 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function getBatchConcurrency(strapi) {
|
|
352
|
+
const DEFAULT_CONCURRENCY = 5;
|
|
353
|
+
const MIN_CONCURRENCY = 1;
|
|
354
|
+
const MAX_CONCURRENCY = 10;
|
|
355
|
+
try {
|
|
356
|
+
const configured = strapi?.config?.get?.("plugin::bulk-updater.batchConcurrency");
|
|
357
|
+
if (configured !== void 0 && configured !== null && configured !== "") {
|
|
358
|
+
const parsed = Number(configured);
|
|
359
|
+
if (Number.isFinite(parsed) && parsed >= MIN_CONCURRENCY) {
|
|
360
|
+
return Math.min(MAX_CONCURRENCY, Math.floor(parsed));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
return DEFAULT_CONCURRENCY;
|
|
366
|
+
}
|
|
367
|
+
function sanitizeSensitiveErrorText(text) {
|
|
368
|
+
if (!text || typeof text !== "string") return "";
|
|
369
|
+
return text.replace(/Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi, "Bearer [REDACTED]").replace(/Basic\s+[A-Za-z0-9+/=]+/gi, "Basic [REDACTED]").replace(/(authorization|api[_-]?key|token|secret|password)\s*[:=]\s*[^\s,;'"}\]]+/gi, "$1=[REDACTED]").replace(/([?&](?:token|key|api_key|apikey|secret|password|auth)=)[^&\s]+/gi, "$1[REDACTED]");
|
|
370
|
+
}
|
|
371
|
+
function isFetchFailedError(err) {
|
|
372
|
+
if (!err) return false;
|
|
373
|
+
const visited = /* @__PURE__ */ new Set();
|
|
374
|
+
let current = err;
|
|
375
|
+
while (current && typeof current === "object" && !visited.has(current)) {
|
|
376
|
+
visited.add(current);
|
|
377
|
+
const msg = typeof current.message === "string" ? current.message : "";
|
|
378
|
+
const code = typeof current.code === "string" ? current.code : "";
|
|
379
|
+
const stack = typeof current.stack === "string" ? current.stack : "";
|
|
380
|
+
if (/fetch failed/i.test(msg) || code.startsWith("UND_ERR_") || stack.includes("node:internal/deps/undici")) {
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
if (Array.isArray(current.errors)) {
|
|
384
|
+
for (const sub of current.errors) {
|
|
385
|
+
if (isFetchFailedError(sub)) return true;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
current = current.cause;
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
function formatErrorWithCause(err, fallback = "Unknown error") {
|
|
393
|
+
if (!err) return fallback;
|
|
394
|
+
if (typeof err === "string") return sanitizeSensitiveErrorText(err) || fallback;
|
|
395
|
+
const primaryMsg = typeof err.message === "string" && err.message.trim() && err.message !== "[object Object]" ? err.message.trim() : fallback;
|
|
396
|
+
const causeParts = [];
|
|
397
|
+
const visited = /* @__PURE__ */ new Set([err]);
|
|
398
|
+
let current = err.cause;
|
|
399
|
+
while (current && !visited.has(current) && causeParts.length < 4) {
|
|
400
|
+
visited.add(current);
|
|
401
|
+
if (typeof current === "string") {
|
|
402
|
+
if (current.trim()) causeParts.push(current.trim());
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
if (typeof current === "object") {
|
|
406
|
+
const code = typeof current.code === "string" ? current.code.trim() : "";
|
|
407
|
+
const msg = typeof current.message === "string" ? current.message.trim() : "";
|
|
408
|
+
const addr = typeof current.address === "string" ? current.address.trim() : "";
|
|
409
|
+
const port = current.port !== void 0 && current.port !== null ? String(current.port) : "";
|
|
410
|
+
const endpoint = addr ? port ? `${addr}:${port}` : addr : "";
|
|
411
|
+
const pieces = [];
|
|
412
|
+
if (code) pieces.push(code);
|
|
413
|
+
if (msg && msg !== code) pieces.push(msg);
|
|
414
|
+
if (endpoint && !msg.includes(endpoint)) pieces.push(endpoint);
|
|
415
|
+
if (pieces.length > 0) {
|
|
416
|
+
causeParts.push(pieces.join(" - "));
|
|
417
|
+
} else if (Array.isArray(current.errors) && current.errors.length > 0) {
|
|
418
|
+
const subMsgs = current.errors.slice(0, 2).map((e) => {
|
|
419
|
+
const subCode = e?.code ? `${e.code}: ` : "";
|
|
420
|
+
return `${subCode}${e?.message || ""}`.trim();
|
|
421
|
+
}).filter(Boolean);
|
|
422
|
+
if (subMsgs.length > 0) {
|
|
423
|
+
causeParts.push(subMsgs.join("; "));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
current = current.cause;
|
|
427
|
+
} else {
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
let formatted = primaryMsg;
|
|
432
|
+
if (causeParts.length > 0) {
|
|
433
|
+
formatted = `${primaryMsg} (${causeParts.join(" -> ")})`;
|
|
434
|
+
}
|
|
435
|
+
if (isFetchFailedError(err) && !formatted.toLowerCase().includes("webhook")) {
|
|
436
|
+
formatted += " — downstream webhook or lifecycle HTTP request failed";
|
|
437
|
+
}
|
|
438
|
+
return sanitizeSensitiveErrorText(formatted);
|
|
439
|
+
}
|
|
440
|
+
function installUndiciCrashGuard(strapi) {
|
|
441
|
+
const globalObj = globalThis;
|
|
442
|
+
if (globalObj[CRASH_GUARD_SYMBOL]) {
|
|
443
|
+
return globalObj[CRASH_GUARD_SYMBOL];
|
|
444
|
+
}
|
|
445
|
+
const handler = (reason) => {
|
|
446
|
+
if (!isFetchFailedError(reason)) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const formatted = formatErrorWithCause(reason, "fetch failed");
|
|
450
|
+
const inBulk = activeBulkOperations > 0;
|
|
451
|
+
const contextNote = inBulk ? `during active bulk/CSV operation (${activeBulkOperations} active)` : "outside active bulk operation";
|
|
452
|
+
const logMsg = `[bulk-updater] Prevented server crash from unhandled undici fetch rejection ${contextNote}: ${formatted}. Check Strapi Settings > Webhooks or custom lifecycle hooks for unreachable/slow endpoints.`;
|
|
453
|
+
if (strapi?.log?.error) {
|
|
454
|
+
strapi.log.error(logMsg);
|
|
455
|
+
} else {
|
|
456
|
+
console.error(logMsg);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
process.on("unhandledRejection", handler);
|
|
460
|
+
const uninstall = () => {
|
|
461
|
+
process.removeListener("unhandledRejection", handler);
|
|
462
|
+
if (globalObj[CRASH_GUARD_SYMBOL] === uninstall) {
|
|
463
|
+
delete globalObj[CRASH_GUARD_SYMBOL];
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
globalObj[CRASH_GUARD_SYMBOL] = uninstall;
|
|
467
|
+
return uninstall;
|
|
468
|
+
}
|
|
338
469
|
const bulkUpdaterController = ({ strapi }) => ({
|
|
339
470
|
async getModels(ctx) {
|
|
340
471
|
try {
|
|
@@ -410,8 +541,10 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
410
541
|
const result = await service.batchUpdate(ctx.request.body || {}, currentUser);
|
|
411
542
|
ctx.body = result;
|
|
412
543
|
} catch (err) {
|
|
413
|
-
|
|
414
|
-
|
|
544
|
+
const formatted = formatErrorWithCause(err, "Batch update failed");
|
|
545
|
+
strapi.log?.error?.(`[bulk-updater] POST /batch-update error: ${formatted}`);
|
|
546
|
+
ctx.status = isFetchFailedError(err) ? 502 : 400;
|
|
547
|
+
ctx.body = { success: false, error: formatted };
|
|
415
548
|
}
|
|
416
549
|
},
|
|
417
550
|
async batchPublish(ctx) {
|
|
@@ -421,8 +554,10 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
421
554
|
const result = await service.batchPublish(ctx.request.body || {}, currentUser);
|
|
422
555
|
ctx.body = result;
|
|
423
556
|
} catch (err) {
|
|
424
|
-
|
|
425
|
-
|
|
557
|
+
const formatted = formatErrorWithCause(err, "Batch publish failed");
|
|
558
|
+
strapi.log?.error?.(`[bulk-updater] POST /batch-publish error: ${formatted}`);
|
|
559
|
+
ctx.status = isFetchFailedError(err) ? 502 : 400;
|
|
560
|
+
ctx.body = { success: false, error: formatted };
|
|
426
561
|
}
|
|
427
562
|
},
|
|
428
563
|
async previewBatch(ctx) {
|
|
@@ -454,8 +589,10 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
454
589
|
const result = await service.approveBatch(batchId, currentUser, { executeImmediately });
|
|
455
590
|
ctx.body = result;
|
|
456
591
|
} catch (err) {
|
|
457
|
-
|
|
458
|
-
|
|
592
|
+
const formatted = formatErrorWithCause(err, "Batch approval failed");
|
|
593
|
+
strapi.log?.error?.(`[bulk-updater] POST /batches/${ctx.params?.batchId}/approve error: ${formatted}`);
|
|
594
|
+
ctx.status = isFetchFailedError(err) ? 502 : 400;
|
|
595
|
+
ctx.body = { success: false, error: formatted };
|
|
459
596
|
}
|
|
460
597
|
},
|
|
461
598
|
async rejectBatch(ctx) {
|
|
@@ -479,8 +616,10 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
479
616
|
const result = await service.executeNow(batchId, currentUser);
|
|
480
617
|
ctx.body = result;
|
|
481
618
|
} catch (err) {
|
|
482
|
-
|
|
483
|
-
|
|
619
|
+
const formatted = formatErrorWithCause(err, "Batch execution failed");
|
|
620
|
+
strapi.log?.error?.(`[bulk-updater] POST /batches/${ctx.params?.batchId}/execute-now error: ${formatted}`);
|
|
621
|
+
ctx.status = isFetchFailedError(err) ? 502 : 400;
|
|
622
|
+
ctx.body = { success: false, error: formatted };
|
|
484
623
|
}
|
|
485
624
|
},
|
|
486
625
|
async getBatchStatus(ctx) {
|
|
@@ -766,8 +905,10 @@ const csvController = ({ strapi }) => ({
|
|
|
766
905
|
});
|
|
767
906
|
ctx.body = result;
|
|
768
907
|
} catch (err) {
|
|
769
|
-
|
|
770
|
-
|
|
908
|
+
const formatted = formatErrorWithCause(err, "CSV import failed");
|
|
909
|
+
strapi.log?.error?.(`[bulk-updater] POST /csv/import error: ${formatted}`);
|
|
910
|
+
ctx.status = isFetchFailedError(err) ? 502 : 500;
|
|
911
|
+
ctx.body = { success: false, error: formatted };
|
|
771
912
|
}
|
|
772
913
|
},
|
|
773
914
|
async importChunk(ctx) {
|
|
@@ -798,8 +939,10 @@ const csvController = ({ strapi }) => ({
|
|
|
798
939
|
});
|
|
799
940
|
ctx.body = result;
|
|
800
941
|
} catch (err) {
|
|
801
|
-
|
|
802
|
-
|
|
942
|
+
const formatted = formatErrorWithCause(err, "CSV chunk import failed");
|
|
943
|
+
strapi.log?.error?.(`[bulk-updater] POST /csv/import-chunk error: ${formatted}`);
|
|
944
|
+
ctx.status = isFetchFailedError(err) ? 502 : 500;
|
|
945
|
+
ctx.body = { success: false, error: formatted };
|
|
803
946
|
}
|
|
804
947
|
},
|
|
805
948
|
async validatePreflight(ctx) {
|
|
@@ -852,8 +995,10 @@ const csvController = ({ strapi }) => ({
|
|
|
852
995
|
});
|
|
853
996
|
ctx.body = result;
|
|
854
997
|
} catch (err) {
|
|
855
|
-
|
|
856
|
-
|
|
998
|
+
const formatted = formatErrorWithCause(err, "CSV batch submission failed");
|
|
999
|
+
strapi.log?.error?.(`[bulk-updater] POST /csv/submit-batch error: ${formatted}`);
|
|
1000
|
+
ctx.status = isFetchFailedError(err) ? 502 : 500;
|
|
1001
|
+
ctx.body = { success: false, error: formatted };
|
|
857
1002
|
}
|
|
858
1003
|
}
|
|
859
1004
|
});
|
|
@@ -5511,7 +5656,9 @@ async function resolveAndMaybePublishTarget({
|
|
|
5511
5656
|
if (isLocalized) pubArgs.locale = candLocale;
|
|
5512
5657
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
5513
5658
|
} catch (publishErr) {
|
|
5514
|
-
strapi.log.warn(
|
|
5659
|
+
strapi.log.warn(
|
|
5660
|
+
`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
|
|
5661
|
+
);
|
|
5515
5662
|
}
|
|
5516
5663
|
}
|
|
5517
5664
|
invalidateCollectionCache(target.uid);
|
|
@@ -5742,562 +5889,594 @@ async function executeBatchInternal(strapi, {
|
|
|
5742
5889
|
results: []
|
|
5743
5890
|
};
|
|
5744
5891
|
batchJobsMap.set(batchId, jobState);
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
const
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5892
|
+
return await trackActiveBulkOperation(async () => {
|
|
5893
|
+
try {
|
|
5894
|
+
let regexObj = null;
|
|
5895
|
+
if (effectiveEditMode !== "grid" && isRegex && regexPattern) {
|
|
5896
|
+
regexObj = new RegExp(regexPattern, "g");
|
|
5897
|
+
}
|
|
5898
|
+
const CHUNK_SIZE = getBatchConcurrency(strapi);
|
|
5899
|
+
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
5900
|
+
const uidsWithDraftAndPublish = /* @__PURE__ */ new Set();
|
|
5901
|
+
const docIdsByUid = /* @__PURE__ */ new Map();
|
|
5902
|
+
for (const target of targets) {
|
|
5903
|
+
if (target.uid && target.documentId) {
|
|
5904
|
+
const ct = strapi.contentTypes[target.uid];
|
|
5905
|
+
if (ct?.options?.draftAndPublish) {
|
|
5906
|
+
uidsWithDraftAndPublish.add(target.uid);
|
|
5907
|
+
if (!docIdsByUid.has(target.uid)) {
|
|
5908
|
+
docIdsByUid.set(target.uid, []);
|
|
5909
|
+
}
|
|
5910
|
+
docIdsByUid.get(target.uid).push(target.documentId);
|
|
5911
|
+
}
|
|
5760
5912
|
}
|
|
5761
|
-
docIdsByUid.get(target.uid).push(target.documentId);
|
|
5762
5913
|
}
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5914
|
+
for (const colUid of uidsWithDraftAndPublish) {
|
|
5915
|
+
const docIds = docIdsByUid.get(colUid) || [];
|
|
5916
|
+
if (docIds.length > 0) {
|
|
5917
|
+
try {
|
|
5918
|
+
const pubDocs = await strapi.documents(colUid).findMany({
|
|
5919
|
+
status: "published",
|
|
5920
|
+
filters: { documentId: { $in: docIds } },
|
|
5921
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
5922
|
+
limit: Math.max(docIds.length, 100)
|
|
5923
|
+
});
|
|
5924
|
+
for (const pub of pubDocs || []) {
|
|
5925
|
+
if (pub?.documentId) {
|
|
5926
|
+
publishedCounterparts.set(`${colUid}@@@${pub.documentId}`, pub);
|
|
5927
|
+
if (pub.locale) {
|
|
5928
|
+
publishedCounterparts.set(`${colUid}@@@${pub.documentId}@@@${pub.locale}`, pub);
|
|
5929
|
+
}
|
|
5930
|
+
}
|
|
5780
5931
|
}
|
|
5932
|
+
} catch {
|
|
5781
5933
|
}
|
|
5782
5934
|
}
|
|
5783
|
-
} catch {
|
|
5784
5935
|
}
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
})
|
|
5799
|
-
);
|
|
5800
|
-
}
|
|
5801
|
-
return documentLoader.get(loaderKey);
|
|
5802
|
-
};
|
|
5803
|
-
for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
|
|
5804
|
-
const chunk = targets.slice(i, i + CHUNK_SIZE);
|
|
5805
|
-
const chunkPromises = chunk.map(async (target) => {
|
|
5806
|
-
const contentType = strapi.contentTypes[target.uid];
|
|
5807
|
-
const displayName = contentType?.info?.displayName || target.uid;
|
|
5808
|
-
try {
|
|
5809
|
-
if (effectiveEditMode === "grid") {
|
|
5810
|
-
return await executeGridTargetUpdate({
|
|
5811
|
-
strapi,
|
|
5812
|
-
target,
|
|
5813
|
-
attribute,
|
|
5814
|
-
contentType,
|
|
5815
|
-
displayName,
|
|
5816
|
-
publishedCounterparts,
|
|
5817
|
-
publishOnApproval: Boolean(publishOnApproval),
|
|
5818
|
-
publishStrategy,
|
|
5819
|
-
unreviewedConsent: Boolean(unreviewedConsent),
|
|
5820
|
-
currentUser
|
|
5821
|
-
});
|
|
5936
|
+
const documentLoader = /* @__PURE__ */ new Map();
|
|
5937
|
+
const getDocumentDeduplicated = (uid, documentId) => {
|
|
5938
|
+
const loaderKey = `${uid}@@@${documentId}`;
|
|
5939
|
+
if (!documentLoader.has(loaderKey)) {
|
|
5940
|
+
const ct = strapi.contentTypes[uid];
|
|
5941
|
+
const populateDef = ct?.attributes ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
|
|
5942
|
+
documentLoader.set(
|
|
5943
|
+
loaderKey,
|
|
5944
|
+
strapi.documents(uid).findOne({
|
|
5945
|
+
documentId,
|
|
5946
|
+
...populateDef ? { populate: populateDef } : { populate: "*" }
|
|
5947
|
+
})
|
|
5948
|
+
);
|
|
5822
5949
|
}
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
const
|
|
5827
|
-
const
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5950
|
+
return documentLoader.get(loaderKey);
|
|
5951
|
+
};
|
|
5952
|
+
for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
|
|
5953
|
+
const chunk = targets.slice(i, i + CHUNK_SIZE);
|
|
5954
|
+
const chunkPromises = chunk.map(async (target) => {
|
|
5955
|
+
const contentType = strapi.contentTypes[target.uid];
|
|
5956
|
+
const displayName = contentType?.info?.displayName || target.uid;
|
|
5957
|
+
try {
|
|
5958
|
+
if (effectiveEditMode === "grid") {
|
|
5959
|
+
return await executeGridTargetUpdate({
|
|
5960
|
+
strapi,
|
|
5961
|
+
target,
|
|
5962
|
+
attribute,
|
|
5963
|
+
contentType,
|
|
5964
|
+
displayName,
|
|
5965
|
+
publishedCounterparts,
|
|
5966
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
5967
|
+
publishStrategy,
|
|
5968
|
+
unreviewedConsent: Boolean(unreviewedConsent),
|
|
5969
|
+
currentUser
|
|
5970
|
+
});
|
|
5840
5971
|
}
|
|
5841
|
-
const
|
|
5842
|
-
const
|
|
5843
|
-
const
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5972
|
+
const currentEntry = await getDocumentDeduplicated(target.uid, target.documentId);
|
|
5973
|
+
const entryLabel = currentEntry?.name || currentEntry?.title || currentEntry?.email || `Entry #${target.documentId}`;
|
|
5974
|
+
const parsed = parseDynamicZonePath(attribute);
|
|
5975
|
+
const isNested = attribute.includes(".") || attribute.includes("[");
|
|
5976
|
+
const isComponentNested = isNested && isDeepComponentField(contentType, strapi.components, attribute);
|
|
5977
|
+
const parts = isNested ? parsed.cleanPath.split(".") : [];
|
|
5978
|
+
const rootKey = parsed.rootKey;
|
|
5979
|
+
const targetComponentUid = target.targetComponentUid || parsed.targetComponentUid;
|
|
5980
|
+
const targetIndexes = target.dynamicZoneIndexes;
|
|
5981
|
+
const attrDef = contentType?.attributes?.[attribute];
|
|
5982
|
+
const hasAttribute = Boolean(attrDef) || isComponentNested;
|
|
5983
|
+
if (hasAttribute) {
|
|
5984
|
+
if (isComponentNested) {
|
|
5985
|
+
const populateOption = buildDeepPopulate(contentType.attributes, strapi.components);
|
|
5986
|
+
const findOneArgs = { documentId: target.documentId };
|
|
5987
|
+
if (populateOption) {
|
|
5988
|
+
findOneArgs.populate = populateOption;
|
|
5989
|
+
}
|
|
5990
|
+
const currentEntryWithPopulate = await strapi.documents(target.uid).findOne(findOneArgs);
|
|
5991
|
+
const isRootDz = contentType?.attributes?.[rootKey]?.type === "dynamiczone";
|
|
5992
|
+
const existingRoot = currentEntryWithPopulate?.[rootKey] || (isRootDz ? [] : {});
|
|
5993
|
+
let affectedMatches = [];
|
|
5994
|
+
if (isRootDz && Array.isArray(existingRoot)) {
|
|
5995
|
+
affectedMatches = getAllNestedValues({ [rootKey]: existingRoot }, attribute);
|
|
5996
|
+
if (targetIndexes && targetIndexes.length > 0) {
|
|
5997
|
+
affectedMatches = affectedMatches.filter((m) => targetIndexes.includes(m.index));
|
|
5998
|
+
}
|
|
5999
|
+
if (targetComponentUid) {
|
|
6000
|
+
affectedMatches = affectedMatches.filter((m) => m.componentUid === targetComponentUid);
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
const currentVal2 = isRootDz ? affectedMatches.length > 0 ? affectedMatches.map((m) => m.value).join(", ") : getDeepProperty(existingRoot, parts.slice(1).join(".")) : getDeepProperty(existingRoot, parts.slice(1).join("."));
|
|
6004
|
+
let newValue2 = value;
|
|
6005
|
+
if (regexObj && typeof currentVal2 === "string") {
|
|
6006
|
+
newValue2 = currentVal2.replace(regexObj, value);
|
|
6007
|
+
}
|
|
6008
|
+
const updatedRoot = setDeepProperty(existingRoot, parts.slice(1), newValue2, {
|
|
6009
|
+
targetIndexes,
|
|
6010
|
+
targetComponentUid
|
|
6011
|
+
});
|
|
6012
|
+
const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
|
|
6013
|
+
const candLocaleComp = target.locale || currentEntry?.locale;
|
|
6014
|
+
let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
6015
|
+
if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
|
|
6016
|
+
try {
|
|
6017
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
6018
|
+
status: "published",
|
|
6019
|
+
filters: { documentId: target.documentId },
|
|
6020
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6021
|
+
limit: 1
|
|
6022
|
+
});
|
|
6023
|
+
if (singlePub && singlePub.length > 0) {
|
|
6024
|
+
pubRecordComp = singlePub[0];
|
|
6025
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordComp);
|
|
6026
|
+
}
|
|
6027
|
+
} catch {
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6031
|
+
const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
|
|
6032
|
+
inspectionTargetComp,
|
|
6033
|
+
pubRecordComp,
|
|
6034
|
+
isDraftAndPublishComp
|
|
6035
|
+
);
|
|
6036
|
+
const isEditingComp = isRowInEditingStage$1(inspectionTargetComp) || isRowInEditingStage$1(target);
|
|
6037
|
+
const shouldPublishComp = evaluateShouldPublish({
|
|
6038
|
+
isDraftAndPublish: isDraftAndPublishComp,
|
|
6039
|
+
hadPublishedVersion: hadPubComp,
|
|
6040
|
+
isEditing: isEditingComp,
|
|
6041
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
6042
|
+
publishStrategy,
|
|
6043
|
+
unreviewedConsent
|
|
6044
|
+
});
|
|
6045
|
+
const proposedEntityComp = deepMergeEntities(currentEntryWithPopulate || currentEntry, { [rootKey]: updatedRoot });
|
|
6046
|
+
const valResultComp = await validateEntityQuotas(strapi, target.uid, proposedEntityComp);
|
|
6047
|
+
if (!valResultComp.isValid) {
|
|
6048
|
+
return {
|
|
6049
|
+
uid: target.uid,
|
|
6050
|
+
collectionName: displayName,
|
|
6051
|
+
documentId: target.documentId,
|
|
6052
|
+
label: entryLabel,
|
|
6053
|
+
attribute,
|
|
6054
|
+
oldValue: currentVal2 ?? null,
|
|
6055
|
+
newValue: newValue2,
|
|
6056
|
+
status: "error",
|
|
6057
|
+
message: valResultComp.errorMessage
|
|
6058
|
+
};
|
|
6059
|
+
}
|
|
6060
|
+
const updateArgsComp = {
|
|
6061
|
+
documentId: target.documentId,
|
|
6062
|
+
data: {
|
|
6063
|
+
[rootKey]: updatedRoot
|
|
6064
|
+
}
|
|
6065
|
+
};
|
|
6066
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
6067
|
+
updateArgsComp.locale = candLocaleComp;
|
|
6068
|
+
}
|
|
6069
|
+
await strapi.documents(target.uid).update(updateArgsComp);
|
|
6070
|
+
if (shouldPublishComp) {
|
|
6071
|
+
try {
|
|
6072
|
+
const pubArgs = {
|
|
6073
|
+
documentId: target.documentId
|
|
6074
|
+
};
|
|
6075
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
6076
|
+
pubArgs.locale = candLocaleComp;
|
|
6077
|
+
}
|
|
6078
|
+
await strapi.documents(target.uid).publish(pubArgs);
|
|
6079
|
+
} catch (publishErr) {
|
|
6080
|
+
strapi.log.warn(
|
|
6081
|
+
`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
|
|
6082
|
+
);
|
|
6083
|
+
}
|
|
6084
|
+
}
|
|
6085
|
+
invalidateCollectionCache(target.uid);
|
|
6086
|
+
await recordContentHistoryVersion(strapi, {
|
|
6087
|
+
uid: target.uid,
|
|
6088
|
+
documentId: target.documentId,
|
|
6089
|
+
userId: currentUser?.id,
|
|
6090
|
+
statusOverride: shouldPublishComp ? "published" : isDraftAndPublishComp ? hadPubComp ? "modified" : "draft" : void 0
|
|
6091
|
+
});
|
|
6092
|
+
const dzDiffs = isRootDz && affectedMatches.length > 0 ? affectedMatches.map((m) => ({
|
|
6093
|
+
index: m.index,
|
|
6094
|
+
componentUid: m.componentUid,
|
|
6095
|
+
componentName: m.componentName,
|
|
6096
|
+
attribute: `${rootKey}[#${m.index} ${m.componentName}].${parts.slice(1).join(".")}`,
|
|
6097
|
+
oldValue: m.value,
|
|
6098
|
+
newValue: regexObj && typeof m.value === "string" ? m.value.replace(regexObj, value) : value
|
|
6099
|
+
})) : [];
|
|
6100
|
+
return {
|
|
6101
|
+
uid: target.uid,
|
|
6102
|
+
collectionName: displayName,
|
|
6103
|
+
documentId: target.documentId,
|
|
6104
|
+
label: entryLabel,
|
|
6105
|
+
attribute,
|
|
6106
|
+
oldValue: currentVal2 ?? null,
|
|
6107
|
+
newValue: newValue2,
|
|
6108
|
+
status: "updated",
|
|
6109
|
+
message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
|
|
6110
|
+
dynamicZoneDiffs: dzDiffs
|
|
6111
|
+
};
|
|
5852
6112
|
}
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
}
|
|
5859
|
-
const updatedRoot = setDeepProperty(existingRoot, parts.slice(1), newValue2, {
|
|
5860
|
-
targetIndexes,
|
|
5861
|
-
targetComponentUid
|
|
5862
|
-
});
|
|
5863
|
-
const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
|
|
5864
|
-
const candLocaleComp = target.locale || currentEntry?.locale;
|
|
5865
|
-
let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
5866
|
-
if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
|
|
5867
|
-
try {
|
|
5868
|
-
const singlePub = await strapi.documents(target.uid).findMany({
|
|
5869
|
-
status: "published",
|
|
5870
|
-
filters: { documentId: target.documentId },
|
|
5871
|
-
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
5872
|
-
limit: 1
|
|
6113
|
+
if (attrDef.type === "relation") {
|
|
6114
|
+
const isMulti = attrDef.relation === "oneToMany" || attrDef.relation === "manyToMany";
|
|
6115
|
+
const currentEntryWithPopulate = await strapi.documents(target.uid).findOne({
|
|
6116
|
+
documentId: target.documentId,
|
|
6117
|
+
populate: [attribute]
|
|
5873
6118
|
});
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
6119
|
+
const currentRel = currentEntryWithPopulate?.[attribute];
|
|
6120
|
+
let oldDocIds = [];
|
|
6121
|
+
let oldDisplay = "";
|
|
6122
|
+
if (isMulti && Array.isArray(currentRel)) {
|
|
6123
|
+
oldDocIds = currentRel.map((r) => r.documentId).filter(Boolean);
|
|
6124
|
+
oldDisplay = currentRel.map((r) => r.name || r.title || r.email || r.documentId).join(", ") || "(empty)";
|
|
6125
|
+
} else if (currentRel) {
|
|
6126
|
+
oldDocIds = currentRel.documentId ? [currentRel.documentId] : [];
|
|
6127
|
+
oldDisplay = currentRel.name || currentRel.title || currentRel.email || currentRel.documentId || "(empty)";
|
|
6128
|
+
} else {
|
|
6129
|
+
oldDisplay = "(unlinked / none)";
|
|
5877
6130
|
}
|
|
5878
|
-
|
|
6131
|
+
let mode = "set";
|
|
6132
|
+
let targetDocIds = [];
|
|
6133
|
+
let newDisplay = "";
|
|
6134
|
+
if (value === "__clear__" || value === "") {
|
|
6135
|
+
mode = "clear";
|
|
6136
|
+
newDisplay = "(cleared / unlinked)";
|
|
6137
|
+
} else {
|
|
6138
|
+
try {
|
|
6139
|
+
const parsed2 = JSON.parse(value);
|
|
6140
|
+
if (parsed2 && typeof parsed2 === "object" && parsed2.mode) {
|
|
6141
|
+
mode = parsed2.mode;
|
|
6142
|
+
targetDocIds = Array.isArray(parsed2.documentIds) ? parsed2.documentIds : parsed2.documentId ? [parsed2.documentId] : [];
|
|
6143
|
+
newDisplay = parsed2.label || targetDocIds.join(", ") || `[${mode}]`;
|
|
6144
|
+
} else if (Array.isArray(parsed2)) {
|
|
6145
|
+
targetDocIds = parsed2;
|
|
6146
|
+
newDisplay = targetDocIds.join(", ");
|
|
6147
|
+
} else {
|
|
6148
|
+
targetDocIds = [value];
|
|
6149
|
+
newDisplay = value;
|
|
6150
|
+
}
|
|
6151
|
+
} catch {
|
|
6152
|
+
targetDocIds = [value];
|
|
6153
|
+
newDisplay = value;
|
|
6154
|
+
}
|
|
6155
|
+
}
|
|
6156
|
+
let relationPayload;
|
|
6157
|
+
if (mode === "clear") {
|
|
6158
|
+
relationPayload = isMulti ? { set: [] } : null;
|
|
6159
|
+
} else if (mode === "set") {
|
|
6160
|
+
relationPayload = isMulti ? { set: targetDocIds } : targetDocIds[0] || null;
|
|
6161
|
+
} else if (mode === "connect") {
|
|
6162
|
+
relationPayload = { connect: targetDocIds };
|
|
6163
|
+
} else if (mode === "disconnect") {
|
|
6164
|
+
relationPayload = { disconnect: targetDocIds };
|
|
6165
|
+
}
|
|
6166
|
+
const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
|
|
6167
|
+
const candLocaleRel = target.locale || currentEntry?.locale;
|
|
6168
|
+
let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
6169
|
+
if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
|
|
6170
|
+
try {
|
|
6171
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
6172
|
+
status: "published",
|
|
6173
|
+
filters: { documentId: target.documentId },
|
|
6174
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6175
|
+
limit: 1
|
|
6176
|
+
});
|
|
6177
|
+
if (singlePub && singlePub.length > 0) {
|
|
6178
|
+
pubRecordRel = singlePub[0];
|
|
6179
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordRel);
|
|
6180
|
+
}
|
|
6181
|
+
} catch {
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6185
|
+
const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
|
|
6186
|
+
inspectionTargetRel,
|
|
6187
|
+
pubRecordRel,
|
|
6188
|
+
isDraftAndPublishRel
|
|
6189
|
+
);
|
|
6190
|
+
const isEditingRel = isRowInEditingStage$1(inspectionTargetRel) || isRowInEditingStage$1(target);
|
|
6191
|
+
const shouldPublishRel = evaluateShouldPublish({
|
|
6192
|
+
isDraftAndPublish: isDraftAndPublishRel,
|
|
6193
|
+
hadPublishedVersion: hadPubRel,
|
|
6194
|
+
isEditing: isEditingRel,
|
|
6195
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
6196
|
+
publishStrategy,
|
|
6197
|
+
unreviewedConsent
|
|
6198
|
+
});
|
|
6199
|
+
const proposedEntityRel = deepMergeEntities(currentEntry, { [attribute]: relationPayload });
|
|
6200
|
+
const valResultRel = await validateEntityQuotas(strapi, target.uid, proposedEntityRel);
|
|
6201
|
+
if (!valResultRel.isValid) {
|
|
6202
|
+
return {
|
|
6203
|
+
uid: target.uid,
|
|
6204
|
+
collectionName: displayName,
|
|
6205
|
+
documentId: target.documentId,
|
|
6206
|
+
label: entryLabel,
|
|
6207
|
+
attribute,
|
|
6208
|
+
oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
|
|
6209
|
+
newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
|
|
6210
|
+
status: "error",
|
|
6211
|
+
message: valResultRel.errorMessage
|
|
6212
|
+
};
|
|
6213
|
+
}
|
|
6214
|
+
const updateArgsRel = {
|
|
6215
|
+
documentId: target.documentId,
|
|
6216
|
+
data: {
|
|
6217
|
+
[attribute]: relationPayload
|
|
6218
|
+
}
|
|
6219
|
+
};
|
|
6220
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
6221
|
+
updateArgsRel.locale = candLocaleRel;
|
|
6222
|
+
}
|
|
6223
|
+
await strapi.documents(target.uid).update(updateArgsRel);
|
|
6224
|
+
if (shouldPublishRel) {
|
|
6225
|
+
try {
|
|
6226
|
+
const pubArgs = {
|
|
6227
|
+
documentId: target.documentId
|
|
6228
|
+
};
|
|
6229
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
6230
|
+
pubArgs.locale = candLocaleRel;
|
|
6231
|
+
}
|
|
6232
|
+
await strapi.documents(target.uid).publish(pubArgs);
|
|
6233
|
+
} catch (publishErr) {
|
|
6234
|
+
strapi.log.warn(
|
|
6235
|
+
`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
|
|
6236
|
+
);
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
invalidateCollectionCache(target.uid);
|
|
6240
|
+
if (attrDef.target) {
|
|
6241
|
+
invalidateCollectionCache(attrDef.target);
|
|
6242
|
+
}
|
|
6243
|
+
await recordContentHistoryVersion(strapi, {
|
|
6244
|
+
uid: target.uid,
|
|
6245
|
+
documentId: target.documentId,
|
|
6246
|
+
userId: currentUser?.id,
|
|
6247
|
+
statusOverride: shouldPublishRel ? "published" : isDraftAndPublishRel ? hadPubRel ? "modified" : "draft" : void 0
|
|
6248
|
+
});
|
|
6249
|
+
return {
|
|
6250
|
+
uid: target.uid,
|
|
6251
|
+
collectionName: displayName,
|
|
6252
|
+
documentId: target.documentId,
|
|
6253
|
+
label: entryLabel,
|
|
6254
|
+
attribute,
|
|
6255
|
+
oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
|
|
6256
|
+
newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
|
|
6257
|
+
status: "updated",
|
|
6258
|
+
message: `Successfully updated relation "${attribute}"`
|
|
6259
|
+
};
|
|
5879
6260
|
}
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
6261
|
+
let newValue = value;
|
|
6262
|
+
const currentVal = currentEntry?.[attribute];
|
|
6263
|
+
if (regexObj && typeof currentVal === "string") {
|
|
6264
|
+
newValue = currentVal.replace(regexObj, value);
|
|
6265
|
+
}
|
|
6266
|
+
const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
|
|
6267
|
+
const candLocaleScalar = target.locale || currentEntry?.locale;
|
|
6268
|
+
let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
6269
|
+
if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
|
|
6270
|
+
try {
|
|
6271
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
6272
|
+
status: "published",
|
|
6273
|
+
filters: { documentId: target.documentId },
|
|
6274
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6275
|
+
limit: 1
|
|
6276
|
+
});
|
|
6277
|
+
if (singlePub && singlePub.length > 0) {
|
|
6278
|
+
pubRecordScalar = singlePub[0];
|
|
6279
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordScalar);
|
|
6280
|
+
}
|
|
6281
|
+
} catch {
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6285
|
+
const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
|
|
6286
|
+
inspectionTargetScalar,
|
|
6287
|
+
pubRecordScalar,
|
|
6288
|
+
isDraftAndPublishScalar
|
|
6289
|
+
);
|
|
6290
|
+
const isEditingScalar = isRowInEditingStage$1(inspectionTargetScalar) || isRowInEditingStage$1(target);
|
|
6291
|
+
const shouldPublishScalar = evaluateShouldPublish({
|
|
6292
|
+
isDraftAndPublish: isDraftAndPublishScalar,
|
|
6293
|
+
hadPublishedVersion: hadPubScalar,
|
|
6294
|
+
isEditing: isEditingScalar,
|
|
6295
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
6296
|
+
publishStrategy,
|
|
6297
|
+
unreviewedConsent
|
|
6298
|
+
});
|
|
6299
|
+
const proposedEntityScalar = deepMergeEntities(currentEntry, { [attribute]: newValue });
|
|
6300
|
+
const valResultScalar = await validateEntityQuotas(strapi, target.uid, proposedEntityScalar);
|
|
6301
|
+
if (!valResultScalar.isValid) {
|
|
6302
|
+
return {
|
|
6303
|
+
uid: target.uid,
|
|
6304
|
+
collectionName: displayName,
|
|
6305
|
+
documentId: target.documentId,
|
|
6306
|
+
label: entryLabel,
|
|
6307
|
+
attribute,
|
|
6308
|
+
oldValue: currentVal ?? null,
|
|
6309
|
+
newValue,
|
|
6310
|
+
status: "error",
|
|
6311
|
+
message: valResultScalar.errorMessage
|
|
6312
|
+
};
|
|
6313
|
+
}
|
|
6314
|
+
const updateArgsScalar = {
|
|
6315
|
+
documentId: target.documentId,
|
|
6316
|
+
data: {
|
|
6317
|
+
[attribute]: newValue
|
|
6318
|
+
}
|
|
6319
|
+
};
|
|
6320
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
6321
|
+
updateArgsScalar.locale = candLocaleScalar;
|
|
6322
|
+
}
|
|
6323
|
+
await strapi.documents(target.uid).update(updateArgsScalar);
|
|
6324
|
+
if (shouldPublishScalar) {
|
|
6325
|
+
try {
|
|
6326
|
+
const pubArgs = {
|
|
6327
|
+
documentId: target.documentId
|
|
6328
|
+
};
|
|
6329
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
6330
|
+
pubArgs.locale = candLocaleScalar;
|
|
6331
|
+
}
|
|
6332
|
+
await strapi.documents(target.uid).publish(pubArgs);
|
|
6333
|
+
} catch (publishErr) {
|
|
6334
|
+
strapi.log.warn(
|
|
6335
|
+
`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}: ${formatErrorWithCause(publishErr)}`
|
|
6336
|
+
);
|
|
6337
|
+
}
|
|
6338
|
+
}
|
|
6339
|
+
await recordContentHistoryVersion(strapi, {
|
|
6340
|
+
uid: target.uid,
|
|
6341
|
+
documentId: target.documentId,
|
|
6342
|
+
userId: currentUser?.id,
|
|
6343
|
+
statusOverride: shouldPublishScalar ? "published" : isDraftAndPublishScalar ? hadPubScalar ? "modified" : "draft" : void 0
|
|
6344
|
+
});
|
|
5899
6345
|
return {
|
|
5900
6346
|
uid: target.uid,
|
|
5901
6347
|
collectionName: displayName,
|
|
5902
6348
|
documentId: target.documentId,
|
|
5903
6349
|
label: entryLabel,
|
|
5904
6350
|
attribute,
|
|
5905
|
-
oldValue:
|
|
5906
|
-
newValue
|
|
5907
|
-
status: "
|
|
5908
|
-
message:
|
|
6351
|
+
oldValue: currentVal ?? null,
|
|
6352
|
+
newValue,
|
|
6353
|
+
status: "updated",
|
|
6354
|
+
message: `Successfully updated ${attribute}`
|
|
6355
|
+
};
|
|
6356
|
+
} else {
|
|
6357
|
+
return {
|
|
6358
|
+
uid: target.uid,
|
|
6359
|
+
collectionName: displayName,
|
|
6360
|
+
documentId: target.documentId,
|
|
6361
|
+
label: entryLabel,
|
|
6362
|
+
attribute,
|
|
6363
|
+
status: "skipped",
|
|
6364
|
+
message: `Skipped: Attribute "${attribute}" does not exist in schema for ${displayName}`
|
|
5909
6365
|
};
|
|
5910
6366
|
}
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
5918
|
-
updateArgsComp.locale = candLocaleComp;
|
|
5919
|
-
}
|
|
5920
|
-
await strapi.documents(target.uid).update(updateArgsComp);
|
|
5921
|
-
if (shouldPublishComp) {
|
|
5922
|
-
try {
|
|
5923
|
-
const pubArgs = {
|
|
5924
|
-
documentId: target.documentId
|
|
5925
|
-
};
|
|
5926
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
5927
|
-
pubArgs.locale = candLocaleComp;
|
|
5928
|
-
}
|
|
5929
|
-
await strapi.documents(target.uid).publish(pubArgs);
|
|
5930
|
-
} catch (publishErr) {
|
|
5931
|
-
strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
|
|
5932
|
-
}
|
|
6367
|
+
} catch (updateErr) {
|
|
6368
|
+
const formattedErr = formatErrorWithCause(updateErr, "Failed to update record");
|
|
6369
|
+
if (isFetchFailedError(updateErr)) {
|
|
6370
|
+
strapi.log?.error?.(
|
|
6371
|
+
`[bulk-updater] Network/webhook fetch error during batch ${batchId} update of ${target.uid}/${target.documentId}: ${formattedErr}`
|
|
6372
|
+
);
|
|
5933
6373
|
}
|
|
5934
|
-
invalidateCollectionCache(target.uid);
|
|
5935
|
-
await recordContentHistoryVersion(strapi, {
|
|
5936
|
-
uid: target.uid,
|
|
5937
|
-
documentId: target.documentId,
|
|
5938
|
-
userId: currentUser?.id,
|
|
5939
|
-
statusOverride: shouldPublishComp ? "published" : isDraftAndPublishComp ? hadPubComp ? "modified" : "draft" : void 0
|
|
5940
|
-
});
|
|
5941
|
-
const dzDiffs = isRootDz && affectedMatches.length > 0 ? affectedMatches.map((m) => ({
|
|
5942
|
-
index: m.index,
|
|
5943
|
-
componentUid: m.componentUid,
|
|
5944
|
-
componentName: m.componentName,
|
|
5945
|
-
attribute: `${rootKey}[#${m.index} ${m.componentName}].${parts.slice(1).join(".")}`,
|
|
5946
|
-
oldValue: m.value,
|
|
5947
|
-
newValue: regexObj && typeof m.value === "string" ? m.value.replace(regexObj, value) : value
|
|
5948
|
-
})) : [];
|
|
5949
6374
|
return {
|
|
5950
6375
|
uid: target.uid,
|
|
5951
6376
|
collectionName: displayName,
|
|
5952
6377
|
documentId: target.documentId,
|
|
5953
|
-
label:
|
|
6378
|
+
label: `Entry #${target.documentId}`,
|
|
5954
6379
|
attribute,
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
status: "updated",
|
|
5958
|
-
message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
|
|
5959
|
-
dynamicZoneDiffs: dzDiffs
|
|
6380
|
+
status: "error",
|
|
6381
|
+
message: formattedErr
|
|
5960
6382
|
};
|
|
5961
6383
|
}
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
6384
|
+
});
|
|
6385
|
+
const chunkResults = await Promise.all(chunkPromises);
|
|
6386
|
+
for (const res of chunkResults) {
|
|
6387
|
+
if (res.status === "updated") updatedCount++;
|
|
6388
|
+
else if (res.status === "skipped") skippedCount++;
|
|
6389
|
+
results.push(res);
|
|
6390
|
+
}
|
|
6391
|
+
jobState.processedCount = results.length;
|
|
6392
|
+
jobState.updatedCount = updatedCount;
|
|
6393
|
+
jobState.skippedCount = skippedCount;
|
|
6394
|
+
jobState.failedCount = results.filter((r) => r.status === "error").length;
|
|
6395
|
+
if (i + CHUNK_SIZE < targets.length) {
|
|
6396
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
6397
|
+
}
|
|
6398
|
+
}
|
|
6399
|
+
const affectedUids = new Set(targets.map((t) => t.uid));
|
|
6400
|
+
affectedUids.forEach((uid) => {
|
|
6401
|
+
invalidateCollectionCache(uid);
|
|
6402
|
+
});
|
|
6403
|
+
const failedCount = results.filter((r) => r.status === "error").length;
|
|
6404
|
+
jobState.failedCount = failedCount;
|
|
6405
|
+
jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6406
|
+
jobState.isLive = updatedCount > 0;
|
|
6407
|
+
jobState.status = failedCount === 0 && updatedCount > 0 ? "successful" : failedCount > 0 && updatedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
|
|
6408
|
+
jobState.results = results.map((r) => ({
|
|
6409
|
+
...r,
|
|
6410
|
+
isLive: r.status === "updated"
|
|
6411
|
+
}));
|
|
6412
|
+
const flattenedDiffs = [];
|
|
6413
|
+
for (const r of results) {
|
|
6414
|
+
if (effectiveEditMode === "grid") {
|
|
6415
|
+
flattenedDiffs.push(r);
|
|
6416
|
+
} else if (r.dynamicZoneDiffs && r.dynamicZoneDiffs.length > 0) {
|
|
6417
|
+
for (const dz of r.dynamicZoneDiffs) {
|
|
6418
|
+
flattenedDiffs.push({
|
|
6419
|
+
uid: r.uid,
|
|
6420
|
+
collectionName: r.collectionName,
|
|
6421
|
+
documentId: r.documentId,
|
|
6422
|
+
label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
|
|
6423
|
+
attribute: dz.attribute,
|
|
6424
|
+
oldValue: dz.oldValue,
|
|
6425
|
+
newValue: dz.newValue,
|
|
6426
|
+
status: "updated",
|
|
6427
|
+
message: `Updated ${dz.attribute}`
|
|
5967
6428
|
});
|
|
5968
|
-
const currentRel = currentEntryWithPopulate?.[attribute];
|
|
5969
|
-
let oldDocIds = [];
|
|
5970
|
-
let oldDisplay = "";
|
|
5971
|
-
if (isMulti && Array.isArray(currentRel)) {
|
|
5972
|
-
oldDocIds = currentRel.map((r) => r.documentId).filter(Boolean);
|
|
5973
|
-
oldDisplay = currentRel.map((r) => r.name || r.title || r.email || r.documentId).join(", ") || "(empty)";
|
|
5974
|
-
} else if (currentRel) {
|
|
5975
|
-
oldDocIds = currentRel.documentId ? [currentRel.documentId] : [];
|
|
5976
|
-
oldDisplay = currentRel.name || currentRel.title || currentRel.email || currentRel.documentId || "(empty)";
|
|
5977
|
-
} else {
|
|
5978
|
-
oldDisplay = "(unlinked / none)";
|
|
5979
|
-
}
|
|
5980
|
-
let mode = "set";
|
|
5981
|
-
let targetDocIds = [];
|
|
5982
|
-
let newDisplay = "";
|
|
5983
|
-
if (value === "__clear__" || value === "") {
|
|
5984
|
-
mode = "clear";
|
|
5985
|
-
newDisplay = "(cleared / unlinked)";
|
|
5986
|
-
} else {
|
|
5987
|
-
try {
|
|
5988
|
-
const parsed2 = JSON.parse(value);
|
|
5989
|
-
if (parsed2 && typeof parsed2 === "object" && parsed2.mode) {
|
|
5990
|
-
mode = parsed2.mode;
|
|
5991
|
-
targetDocIds = Array.isArray(parsed2.documentIds) ? parsed2.documentIds : parsed2.documentId ? [parsed2.documentId] : [];
|
|
5992
|
-
newDisplay = parsed2.label || targetDocIds.join(", ") || `[${mode}]`;
|
|
5993
|
-
} else if (Array.isArray(parsed2)) {
|
|
5994
|
-
targetDocIds = parsed2;
|
|
5995
|
-
newDisplay = targetDocIds.join(", ");
|
|
5996
|
-
} else {
|
|
5997
|
-
targetDocIds = [value];
|
|
5998
|
-
newDisplay = value;
|
|
5999
|
-
}
|
|
6000
|
-
} catch {
|
|
6001
|
-
targetDocIds = [value];
|
|
6002
|
-
newDisplay = value;
|
|
6003
|
-
}
|
|
6004
|
-
}
|
|
6005
|
-
let relationPayload;
|
|
6006
|
-
if (mode === "clear") {
|
|
6007
|
-
relationPayload = isMulti ? { set: [] } : null;
|
|
6008
|
-
} else if (mode === "set") {
|
|
6009
|
-
relationPayload = isMulti ? { set: targetDocIds } : targetDocIds[0] || null;
|
|
6010
|
-
} else if (mode === "connect") {
|
|
6011
|
-
relationPayload = { connect: targetDocIds };
|
|
6012
|
-
} else if (mode === "disconnect") {
|
|
6013
|
-
relationPayload = { disconnect: targetDocIds };
|
|
6014
|
-
}
|
|
6015
|
-
const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
|
|
6016
|
-
const candLocaleRel = target.locale || currentEntry?.locale;
|
|
6017
|
-
let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
6018
|
-
if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
|
|
6019
|
-
try {
|
|
6020
|
-
const singlePub = await strapi.documents(target.uid).findMany({
|
|
6021
|
-
status: "published",
|
|
6022
|
-
filters: { documentId: target.documentId },
|
|
6023
|
-
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6024
|
-
limit: 1
|
|
6025
|
-
});
|
|
6026
|
-
if (singlePub && singlePub.length > 0) {
|
|
6027
|
-
pubRecordRel = singlePub[0];
|
|
6028
|
-
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordRel);
|
|
6029
|
-
}
|
|
6030
|
-
} catch {
|
|
6031
|
-
}
|
|
6032
|
-
}
|
|
6033
|
-
const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6034
|
-
const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
|
|
6035
|
-
inspectionTargetRel,
|
|
6036
|
-
pubRecordRel,
|
|
6037
|
-
isDraftAndPublishRel
|
|
6038
|
-
);
|
|
6039
|
-
const isEditingRel = isRowInEditingStage$1(inspectionTargetRel) || isRowInEditingStage$1(target);
|
|
6040
|
-
const shouldPublishRel = evaluateShouldPublish({
|
|
6041
|
-
isDraftAndPublish: isDraftAndPublishRel,
|
|
6042
|
-
hadPublishedVersion: hadPubRel,
|
|
6043
|
-
isEditing: isEditingRel,
|
|
6044
|
-
publishOnApproval: Boolean(publishOnApproval),
|
|
6045
|
-
publishStrategy,
|
|
6046
|
-
unreviewedConsent
|
|
6047
|
-
});
|
|
6048
|
-
const proposedEntityRel = deepMergeEntities(currentEntry, { [attribute]: relationPayload });
|
|
6049
|
-
const valResultRel = await validateEntityQuotas(strapi, target.uid, proposedEntityRel);
|
|
6050
|
-
if (!valResultRel.isValid) {
|
|
6051
|
-
return {
|
|
6052
|
-
uid: target.uid,
|
|
6053
|
-
collectionName: displayName,
|
|
6054
|
-
documentId: target.documentId,
|
|
6055
|
-
label: entryLabel,
|
|
6056
|
-
attribute,
|
|
6057
|
-
oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
|
|
6058
|
-
newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
|
|
6059
|
-
status: "error",
|
|
6060
|
-
message: valResultRel.errorMessage
|
|
6061
|
-
};
|
|
6062
|
-
}
|
|
6063
|
-
const updateArgsRel = {
|
|
6064
|
-
documentId: target.documentId,
|
|
6065
|
-
data: {
|
|
6066
|
-
[attribute]: relationPayload
|
|
6067
|
-
}
|
|
6068
|
-
};
|
|
6069
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
6070
|
-
updateArgsRel.locale = candLocaleRel;
|
|
6071
|
-
}
|
|
6072
|
-
await strapi.documents(target.uid).update(updateArgsRel);
|
|
6073
|
-
if (shouldPublishRel) {
|
|
6074
|
-
try {
|
|
6075
|
-
const pubArgs = {
|
|
6076
|
-
documentId: target.documentId
|
|
6077
|
-
};
|
|
6078
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
6079
|
-
pubArgs.locale = candLocaleRel;
|
|
6080
|
-
}
|
|
6081
|
-
await strapi.documents(target.uid).publish(pubArgs);
|
|
6082
|
-
} catch (publishErr) {
|
|
6083
|
-
strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
|
|
6084
|
-
}
|
|
6085
|
-
}
|
|
6086
|
-
invalidateCollectionCache(target.uid);
|
|
6087
|
-
if (attrDef.target) {
|
|
6088
|
-
invalidateCollectionCache(attrDef.target);
|
|
6089
|
-
}
|
|
6090
|
-
await recordContentHistoryVersion(strapi, {
|
|
6091
|
-
uid: target.uid,
|
|
6092
|
-
documentId: target.documentId,
|
|
6093
|
-
userId: currentUser?.id,
|
|
6094
|
-
statusOverride: shouldPublishRel ? "published" : isDraftAndPublishRel ? hadPubRel ? "modified" : "draft" : void 0
|
|
6095
|
-
});
|
|
6096
|
-
return {
|
|
6097
|
-
uid: target.uid,
|
|
6098
|
-
collectionName: displayName,
|
|
6099
|
-
documentId: target.documentId,
|
|
6100
|
-
label: entryLabel,
|
|
6101
|
-
attribute,
|
|
6102
|
-
oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
|
|
6103
|
-
newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
|
|
6104
|
-
status: "updated",
|
|
6105
|
-
message: `Successfully updated relation "${attribute}"`
|
|
6106
|
-
};
|
|
6107
|
-
}
|
|
6108
|
-
let newValue = value;
|
|
6109
|
-
const currentVal = currentEntry?.[attribute];
|
|
6110
|
-
if (regexObj && typeof currentVal === "string") {
|
|
6111
|
-
newValue = currentVal.replace(regexObj, value);
|
|
6112
|
-
}
|
|
6113
|
-
const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
|
|
6114
|
-
const candLocaleScalar = target.locale || currentEntry?.locale;
|
|
6115
|
-
let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
6116
|
-
if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
|
|
6117
|
-
try {
|
|
6118
|
-
const singlePub = await strapi.documents(target.uid).findMany({
|
|
6119
|
-
status: "published",
|
|
6120
|
-
filters: { documentId: target.documentId },
|
|
6121
|
-
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6122
|
-
limit: 1
|
|
6123
|
-
});
|
|
6124
|
-
if (singlePub && singlePub.length > 0) {
|
|
6125
|
-
pubRecordScalar = singlePub[0];
|
|
6126
|
-
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordScalar);
|
|
6127
|
-
}
|
|
6128
|
-
} catch {
|
|
6129
|
-
}
|
|
6130
|
-
}
|
|
6131
|
-
const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6132
|
-
const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
|
|
6133
|
-
inspectionTargetScalar,
|
|
6134
|
-
pubRecordScalar,
|
|
6135
|
-
isDraftAndPublishScalar
|
|
6136
|
-
);
|
|
6137
|
-
const isEditingScalar = isRowInEditingStage$1(inspectionTargetScalar) || isRowInEditingStage$1(target);
|
|
6138
|
-
const shouldPublishScalar = evaluateShouldPublish({
|
|
6139
|
-
isDraftAndPublish: isDraftAndPublishScalar,
|
|
6140
|
-
hadPublishedVersion: hadPubScalar,
|
|
6141
|
-
isEditing: isEditingScalar,
|
|
6142
|
-
publishOnApproval: Boolean(publishOnApproval),
|
|
6143
|
-
publishStrategy,
|
|
6144
|
-
unreviewedConsent
|
|
6145
|
-
});
|
|
6146
|
-
const proposedEntityScalar = deepMergeEntities(currentEntry, { [attribute]: newValue });
|
|
6147
|
-
const valResultScalar = await validateEntityQuotas(strapi, target.uid, proposedEntityScalar);
|
|
6148
|
-
if (!valResultScalar.isValid) {
|
|
6149
|
-
return {
|
|
6150
|
-
uid: target.uid,
|
|
6151
|
-
collectionName: displayName,
|
|
6152
|
-
documentId: target.documentId,
|
|
6153
|
-
label: entryLabel,
|
|
6154
|
-
attribute,
|
|
6155
|
-
oldValue: currentVal ?? null,
|
|
6156
|
-
newValue,
|
|
6157
|
-
status: "error",
|
|
6158
|
-
message: valResultScalar.errorMessage
|
|
6159
|
-
};
|
|
6160
|
-
}
|
|
6161
|
-
const updateArgsScalar = {
|
|
6162
|
-
documentId: target.documentId,
|
|
6163
|
-
data: {
|
|
6164
|
-
[attribute]: newValue
|
|
6165
|
-
}
|
|
6166
|
-
};
|
|
6167
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
6168
|
-
updateArgsScalar.locale = candLocaleScalar;
|
|
6169
6429
|
}
|
|
6170
|
-
await strapi.documents(target.uid).update(updateArgsScalar);
|
|
6171
|
-
if (shouldPublishScalar) {
|
|
6172
|
-
try {
|
|
6173
|
-
const pubArgs = {
|
|
6174
|
-
documentId: target.documentId
|
|
6175
|
-
};
|
|
6176
|
-
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
6177
|
-
pubArgs.locale = candLocaleScalar;
|
|
6178
|
-
}
|
|
6179
|
-
await strapi.documents(target.uid).publish(pubArgs);
|
|
6180
|
-
} catch (publishErr) {
|
|
6181
|
-
strapi.log.warn(`[bulk-updater] Failed to auto-publish ${target.uid}/${target.documentId}:`, publishErr);
|
|
6182
|
-
}
|
|
6183
|
-
}
|
|
6184
|
-
await recordContentHistoryVersion(strapi, {
|
|
6185
|
-
uid: target.uid,
|
|
6186
|
-
documentId: target.documentId,
|
|
6187
|
-
userId: currentUser?.id,
|
|
6188
|
-
statusOverride: shouldPublishScalar ? "published" : isDraftAndPublishScalar ? hadPubScalar ? "modified" : "draft" : void 0
|
|
6189
|
-
});
|
|
6190
|
-
return {
|
|
6191
|
-
uid: target.uid,
|
|
6192
|
-
collectionName: displayName,
|
|
6193
|
-
documentId: target.documentId,
|
|
6194
|
-
label: entryLabel,
|
|
6195
|
-
attribute,
|
|
6196
|
-
oldValue: currentVal ?? null,
|
|
6197
|
-
newValue,
|
|
6198
|
-
status: "updated",
|
|
6199
|
-
message: `Successfully updated ${attribute}`
|
|
6200
|
-
};
|
|
6201
6430
|
} else {
|
|
6202
|
-
|
|
6203
|
-
uid: target.uid,
|
|
6204
|
-
collectionName: displayName,
|
|
6205
|
-
documentId: target.documentId,
|
|
6206
|
-
label: entryLabel,
|
|
6207
|
-
attribute,
|
|
6208
|
-
status: "skipped",
|
|
6209
|
-
message: `Skipped: Attribute "${attribute}" does not exist in schema for ${displayName}`
|
|
6210
|
-
};
|
|
6431
|
+
flattenedDiffs.push(r);
|
|
6211
6432
|
}
|
|
6212
|
-
} catch (updateErr) {
|
|
6213
|
-
return {
|
|
6214
|
-
uid: target.uid,
|
|
6215
|
-
collectionName: displayName,
|
|
6216
|
-
documentId: target.documentId,
|
|
6217
|
-
label: `Entry #${target.documentId}`,
|
|
6218
|
-
attribute,
|
|
6219
|
-
status: "error",
|
|
6220
|
-
message: updateErr.message
|
|
6221
|
-
};
|
|
6222
6433
|
}
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
...r,
|
|
6246
|
-
isLive: r.status === "updated"
|
|
6247
|
-
}));
|
|
6248
|
-
const flattenedDiffs = [];
|
|
6249
|
-
for (const r of results) {
|
|
6250
|
-
if (effectiveEditMode === "grid") {
|
|
6251
|
-
flattenedDiffs.push(r);
|
|
6252
|
-
} else if (r.dynamicZoneDiffs && r.dynamicZoneDiffs.length > 0) {
|
|
6253
|
-
for (const dz of r.dynamicZoneDiffs) {
|
|
6254
|
-
flattenedDiffs.push({
|
|
6255
|
-
uid: r.uid,
|
|
6256
|
-
collectionName: r.collectionName,
|
|
6257
|
-
documentId: r.documentId,
|
|
6258
|
-
label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
|
|
6259
|
-
attribute: dz.attribute,
|
|
6260
|
-
oldValue: dz.oldValue,
|
|
6261
|
-
newValue: dz.newValue,
|
|
6262
|
-
status: "updated",
|
|
6263
|
-
message: `Updated ${dz.attribute}`
|
|
6264
|
-
});
|
|
6434
|
+
const batchSummary = {
|
|
6435
|
+
batchId,
|
|
6436
|
+
attribute,
|
|
6437
|
+
value: effectiveSummaryVal,
|
|
6438
|
+
editMode: effectiveEditMode,
|
|
6439
|
+
updatedCount,
|
|
6440
|
+
skippedCount,
|
|
6441
|
+
totalTargets: targets.length,
|
|
6442
|
+
publishOnApproval,
|
|
6443
|
+
publishStrategy,
|
|
6444
|
+
unreviewedConsent
|
|
6445
|
+
};
|
|
6446
|
+
try {
|
|
6447
|
+
await strapi.plugin("bulk-updater").service("audit").recordBatch(
|
|
6448
|
+
batchSummary,
|
|
6449
|
+
flattenedDiffs,
|
|
6450
|
+
currentUser
|
|
6451
|
+
);
|
|
6452
|
+
} catch (auditErr) {
|
|
6453
|
+
strapi.log?.warn?.(
|
|
6454
|
+
`[bulk-updater] Non-fatal audit logging failure for batch ${batchId}: ${formatErrorWithCause(auditErr)}`
|
|
6455
|
+
);
|
|
6265
6456
|
}
|
|
6266
|
-
|
|
6267
|
-
|
|
6457
|
+
return {
|
|
6458
|
+
success: true,
|
|
6459
|
+
batchId,
|
|
6460
|
+
attribute,
|
|
6461
|
+
value: effectiveSummaryVal,
|
|
6462
|
+
editMode: effectiveEditMode,
|
|
6463
|
+
updatedCount,
|
|
6464
|
+
skippedCount,
|
|
6465
|
+
failedCount,
|
|
6466
|
+
totalTargets: targets.length,
|
|
6467
|
+
isLive: jobState.isLive,
|
|
6468
|
+
status: jobState.status,
|
|
6469
|
+
results
|
|
6470
|
+
};
|
|
6471
|
+
} catch (fatalErr) {
|
|
6472
|
+
const formattedFatal = formatErrorWithCause(fatalErr, "Batch execution failed");
|
|
6473
|
+
jobState.status = "failed";
|
|
6474
|
+
jobState.error = formattedFatal;
|
|
6475
|
+
jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6476
|
+
strapi.log?.error?.(`[bulk-updater] Batch ${batchId} aborted with error: ${formattedFatal}`);
|
|
6477
|
+
throw fatalErr;
|
|
6268
6478
|
}
|
|
6269
|
-
}
|
|
6270
|
-
const batchSummary = {
|
|
6271
|
-
batchId,
|
|
6272
|
-
attribute,
|
|
6273
|
-
value: effectiveSummaryVal,
|
|
6274
|
-
editMode: effectiveEditMode,
|
|
6275
|
-
updatedCount,
|
|
6276
|
-
skippedCount,
|
|
6277
|
-
totalTargets: targets.length,
|
|
6278
|
-
publishOnApproval,
|
|
6279
|
-
publishStrategy,
|
|
6280
|
-
unreviewedConsent
|
|
6281
|
-
};
|
|
6282
|
-
await strapi.plugin("bulk-updater").service("audit").recordBatch(
|
|
6283
|
-
batchSummary,
|
|
6284
|
-
flattenedDiffs,
|
|
6285
|
-
currentUser
|
|
6286
|
-
);
|
|
6287
|
-
return {
|
|
6288
|
-
success: true,
|
|
6289
|
-
batchId,
|
|
6290
|
-
attribute,
|
|
6291
|
-
value: effectiveSummaryVal,
|
|
6292
|
-
editMode: effectiveEditMode,
|
|
6293
|
-
updatedCount,
|
|
6294
|
-
skippedCount,
|
|
6295
|
-
failedCount,
|
|
6296
|
-
totalTargets: targets.length,
|
|
6297
|
-
isLive: jobState.isLive,
|
|
6298
|
-
status: jobState.status,
|
|
6299
|
-
results
|
|
6300
|
-
};
|
|
6479
|
+
});
|
|
6301
6480
|
}
|
|
6302
6481
|
async function executePublishBatchInternal(strapi, {
|
|
6303
6482
|
selectedEntries = [],
|
|
@@ -6351,120 +6530,146 @@ async function executePublishBatchInternal(strapi, {
|
|
|
6351
6530
|
results: []
|
|
6352
6531
|
};
|
|
6353
6532
|
batchJobsMap.set(batchId, jobState);
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
const
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6533
|
+
return await trackActiveBulkOperation(async () => {
|
|
6534
|
+
try {
|
|
6535
|
+
const targets = Array.from(targetsMap.values());
|
|
6536
|
+
const CHUNK_SIZE = getBatchConcurrency(strapi);
|
|
6537
|
+
for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
|
|
6538
|
+
const chunk = targets.slice(i, i + CHUNK_SIZE);
|
|
6539
|
+
const chunkPromises = chunk.map(async (target) => {
|
|
6540
|
+
try {
|
|
6541
|
+
const contentType = strapi.contentTypes[target.uid];
|
|
6542
|
+
const displayName = contentType?.info?.displayName || target.uid;
|
|
6543
|
+
const isDraftAndPublish = Boolean(contentType?.options?.draftAndPublish);
|
|
6544
|
+
let existingDoc = null;
|
|
6545
|
+
try {
|
|
6546
|
+
existingDoc = await strapi.documents(target.uid).findOne({
|
|
6547
|
+
documentId: target.documentId
|
|
6548
|
+
});
|
|
6549
|
+
} catch {
|
|
6550
|
+
existingDoc = null;
|
|
6551
|
+
}
|
|
6552
|
+
const entryLabel = existingDoc?.name || existingDoc?.title || existingDoc?.label || existingDoc?.documentId || `Entry #${target.documentId}`;
|
|
6553
|
+
if (!isDraftAndPublish) {
|
|
6554
|
+
return {
|
|
6555
|
+
uid: target.uid,
|
|
6556
|
+
collectionName: displayName,
|
|
6557
|
+
documentId: target.documentId,
|
|
6558
|
+
label: entryLabel,
|
|
6559
|
+
attribute: "(publish)",
|
|
6560
|
+
status: "skipped",
|
|
6561
|
+
message: `Skipped: Draft & Publish is disabled for collection ${displayName}`
|
|
6562
|
+
};
|
|
6563
|
+
}
|
|
6564
|
+
const isAlreadyPublished = Boolean(existingDoc?.publishedAt);
|
|
6565
|
+
await strapi.documents(target.uid).publish({
|
|
6566
|
+
documentId: target.documentId
|
|
6567
|
+
});
|
|
6568
|
+
invalidateCollectionCache(target.uid);
|
|
6569
|
+
await recordContentHistoryVersion(strapi, {
|
|
6570
|
+
uid: target.uid,
|
|
6571
|
+
documentId: target.documentId,
|
|
6572
|
+
userId: currentUser?.id,
|
|
6573
|
+
statusOverride: "published"
|
|
6574
|
+
});
|
|
6575
|
+
return {
|
|
6576
|
+
uid: target.uid,
|
|
6577
|
+
collectionName: displayName,
|
|
6578
|
+
documentId: target.documentId,
|
|
6579
|
+
label: entryLabel,
|
|
6580
|
+
attribute: "(publish)",
|
|
6581
|
+
oldValue: isAlreadyPublished ? "published" : "draft",
|
|
6582
|
+
newValue: "published",
|
|
6583
|
+
status: "updated",
|
|
6584
|
+
message: isAlreadyPublished ? "Re-published latest version live" : "Successfully published to live"
|
|
6585
|
+
};
|
|
6586
|
+
} catch (pubErr) {
|
|
6587
|
+
const formattedPubErr = formatErrorWithCause(pubErr, "Failed to publish entry");
|
|
6588
|
+
if (isFetchFailedError(pubErr)) {
|
|
6589
|
+
strapi.log?.error?.(
|
|
6590
|
+
`[bulk-updater] Network/webhook fetch error during batch publish ${batchId} of ${target.uid}/${target.documentId}: ${formattedPubErr}`
|
|
6591
|
+
);
|
|
6592
|
+
}
|
|
6593
|
+
return {
|
|
6594
|
+
uid: target.uid,
|
|
6595
|
+
collectionName: strapi.contentTypes[target.uid]?.info?.displayName || target.uid,
|
|
6596
|
+
documentId: target.documentId,
|
|
6597
|
+
label: `Entry #${target.documentId}`,
|
|
6598
|
+
attribute: "(publish)",
|
|
6599
|
+
status: "error",
|
|
6600
|
+
message: formattedPubErr
|
|
6601
|
+
};
|
|
6602
|
+
}
|
|
6393
6603
|
});
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6604
|
+
const chunkResults = await Promise.all(chunkPromises);
|
|
6605
|
+
for (const res of chunkResults) {
|
|
6606
|
+
if (res.status === "updated") publishedCount++;
|
|
6607
|
+
else if (res.status === "skipped") skippedCount++;
|
|
6608
|
+
results.push(res);
|
|
6609
|
+
}
|
|
6610
|
+
jobState.processedCount = results.length;
|
|
6611
|
+
jobState.updatedCount = publishedCount;
|
|
6612
|
+
jobState.skippedCount = skippedCount;
|
|
6613
|
+
jobState.failedCount = results.filter((r) => r.status === "error").length;
|
|
6614
|
+
if (i + CHUNK_SIZE < targets.length) {
|
|
6615
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
6616
|
+
}
|
|
6617
|
+
}
|
|
6618
|
+
const affectedUids = new Set(targets.map((t) => t.uid));
|
|
6619
|
+
affectedUids.forEach((uid) => {
|
|
6620
|
+
invalidateCollectionCache(uid);
|
|
6621
|
+
});
|
|
6622
|
+
const failedCount = results.filter((r) => r.status === "error").length;
|
|
6623
|
+
jobState.failedCount = failedCount;
|
|
6624
|
+
jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6625
|
+
jobState.isLive = publishedCount > 0;
|
|
6626
|
+
jobState.status = failedCount === 0 && publishedCount > 0 ? "successful" : failedCount > 0 && publishedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
|
|
6627
|
+
jobState.results = results.map((r) => ({
|
|
6628
|
+
...r,
|
|
6629
|
+
isLive: r.status === "updated"
|
|
6630
|
+
}));
|
|
6631
|
+
const batchSummary = {
|
|
6632
|
+
batchId,
|
|
6633
|
+
attribute: "(publish)",
|
|
6634
|
+
value: "published",
|
|
6635
|
+
updatedCount: publishedCount,
|
|
6636
|
+
skippedCount,
|
|
6637
|
+
totalTargets: targetsMap.size,
|
|
6638
|
+
publishOnApproval: true,
|
|
6639
|
+
unreviewedConsent
|
|
6640
|
+
};
|
|
6641
|
+
try {
|
|
6642
|
+
await strapi.plugin("bulk-updater").service("audit").recordBatch(
|
|
6643
|
+
batchSummary,
|
|
6644
|
+
results,
|
|
6645
|
+
currentUser
|
|
6646
|
+
);
|
|
6647
|
+
} catch (auditErr) {
|
|
6648
|
+
strapi.log?.warn?.(
|
|
6649
|
+
`[bulk-updater] Non-fatal audit logging failure for publish batch ${batchId}: ${formatErrorWithCause(auditErr)}`
|
|
6650
|
+
);
|
|
6415
6651
|
}
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6652
|
+
return {
|
|
6653
|
+
success: true,
|
|
6654
|
+
batchId,
|
|
6655
|
+
publishedCount,
|
|
6656
|
+
updatedCount: publishedCount,
|
|
6657
|
+
skippedCount,
|
|
6658
|
+
failedCount,
|
|
6659
|
+
totalTargets: targetsMap.size,
|
|
6660
|
+
isLive: publishedCount > 0,
|
|
6661
|
+
status: jobState.status,
|
|
6662
|
+
results
|
|
6663
|
+
};
|
|
6664
|
+
} catch (fatalErr) {
|
|
6665
|
+
const formattedFatal = formatErrorWithCause(fatalErr, "Batch publish failed");
|
|
6666
|
+
jobState.status = "failed";
|
|
6667
|
+
jobState.error = formattedFatal;
|
|
6668
|
+
jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6669
|
+
strapi.log?.error?.(`[bulk-updater] Publish batch ${batchId} aborted with error: ${formattedFatal}`);
|
|
6670
|
+
throw fatalErr;
|
|
6671
|
+
}
|
|
6431
6672
|
});
|
|
6432
|
-
const failedCount = results.filter((r) => r.status === "error").length;
|
|
6433
|
-
jobState.failedCount = failedCount;
|
|
6434
|
-
jobState.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6435
|
-
jobState.isLive = publishedCount > 0;
|
|
6436
|
-
jobState.status = failedCount === 0 && publishedCount > 0 ? "successful" : failedCount > 0 && publishedCount > 0 ? "partial_failure" : failedCount > 0 ? "failed" : "successful";
|
|
6437
|
-
jobState.results = results.map((r) => ({
|
|
6438
|
-
...r,
|
|
6439
|
-
isLive: r.status === "updated"
|
|
6440
|
-
}));
|
|
6441
|
-
const batchSummary = {
|
|
6442
|
-
batchId,
|
|
6443
|
-
attribute: "(publish)",
|
|
6444
|
-
value: "published",
|
|
6445
|
-
updatedCount: publishedCount,
|
|
6446
|
-
skippedCount,
|
|
6447
|
-
totalTargets: targetsMap.size,
|
|
6448
|
-
publishOnApproval: true,
|
|
6449
|
-
unreviewedConsent
|
|
6450
|
-
};
|
|
6451
|
-
await strapi.plugin("bulk-updater").service("audit").recordBatch(
|
|
6452
|
-
batchSummary,
|
|
6453
|
-
results,
|
|
6454
|
-
currentUser
|
|
6455
|
-
);
|
|
6456
|
-
return {
|
|
6457
|
-
success: true,
|
|
6458
|
-
batchId,
|
|
6459
|
-
publishedCount,
|
|
6460
|
-
updatedCount: publishedCount,
|
|
6461
|
-
skippedCount,
|
|
6462
|
-
failedCount,
|
|
6463
|
-
totalTargets: targetsMap.size,
|
|
6464
|
-
isLive: publishedCount > 0,
|
|
6465
|
-
status: jobState.status,
|
|
6466
|
-
results
|
|
6467
|
-
};
|
|
6468
6673
|
}
|
|
6469
6674
|
async function executeBatchByPayload(strapi, batch, currentUser) {
|
|
6470
6675
|
if (batch.payload?.action === "csv_import") {
|
|
@@ -9682,6 +9887,9 @@ function extractDetailedErrorMessage(err) {
|
|
|
9682
9887
|
if (err.details?.message) {
|
|
9683
9888
|
return err.details.message;
|
|
9684
9889
|
}
|
|
9890
|
+
if (isFetchFailedError(err) || err.cause) {
|
|
9891
|
+
return formatErrorWithCause(err, "Error processing row");
|
|
9892
|
+
}
|
|
9685
9893
|
if (err.message && err.message !== "[object Object]") {
|
|
9686
9894
|
return err.message;
|
|
9687
9895
|
}
|
|
@@ -9962,7 +10170,9 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
|
|
|
9962
10170
|
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
9963
10171
|
await strapi.documents(uid).publish(pubArgs);
|
|
9964
10172
|
} catch (pubErr) {
|
|
9965
|
-
strapi.log.warn(
|
|
10173
|
+
strapi.log.warn(
|
|
10174
|
+
`[bulk-updater] Auto-publish failed for ${uid}/${resolvedDocId}: ${formatErrorWithCause(pubErr)}`
|
|
10175
|
+
);
|
|
9966
10176
|
}
|
|
9967
10177
|
}
|
|
9968
10178
|
try {
|
|
@@ -10080,7 +10290,9 @@ async function executeCreateMutation(strapi, ct, uid, docId, row, rowNumber, opt
|
|
|
10080
10290
|
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
10081
10291
|
await strapi.documents(uid).publish(pubArgs);
|
|
10082
10292
|
} catch (pubErr) {
|
|
10083
|
-
strapi.log.warn(
|
|
10293
|
+
strapi.log.warn(
|
|
10294
|
+
`[bulk-updater] Auto-publish failed for ${uid}/${newDocId}: ${formatErrorWithCause(pubErr)}`
|
|
10295
|
+
);
|
|
10084
10296
|
}
|
|
10085
10297
|
}
|
|
10086
10298
|
try {
|
|
@@ -10111,177 +10323,121 @@ async function executeCreateMutation(strapi, ct, uid, docId, row, rowNumber, opt
|
|
|
10111
10323
|
}
|
|
10112
10324
|
}
|
|
10113
10325
|
async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10326
|
+
return await trackActiveBulkOperation(async () => {
|
|
10327
|
+
const attrs = ct.attributes || {};
|
|
10328
|
+
const { mode = "auto", publish = true, publishStrategy = "safe", user, originalHeaders } = options;
|
|
10329
|
+
const isDraftAndPublish = Boolean(ct.options?.draftAndPublish);
|
|
10330
|
+
const docIdsInChunk = rows.map((r) => extractDocId(r)).filter(Boolean);
|
|
10331
|
+
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
10332
|
+
if (isDraftAndPublish && docIdsInChunk.length > 0) {
|
|
10333
|
+
try {
|
|
10334
|
+
const pubDocs = await strapi.documents(uid).findMany({
|
|
10335
|
+
status: "published",
|
|
10336
|
+
filters: { documentId: { $in: docIdsInChunk } },
|
|
10337
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
10338
|
+
limit: Math.max(docIdsInChunk.length, 100)
|
|
10339
|
+
});
|
|
10340
|
+
for (const pub of pubDocs || []) {
|
|
10341
|
+
if (pub?.documentId) {
|
|
10342
|
+
publishedCounterparts.set(String(pub.documentId), pub);
|
|
10343
|
+
if (pub.locale) {
|
|
10344
|
+
publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
|
|
10345
|
+
}
|
|
10132
10346
|
}
|
|
10133
10347
|
}
|
|
10348
|
+
} catch {
|
|
10134
10349
|
}
|
|
10135
|
-
} catch {
|
|
10136
10350
|
}
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10351
|
+
const stats = {
|
|
10352
|
+
total: rows.length,
|
|
10353
|
+
created: 0,
|
|
10354
|
+
updated: 0,
|
|
10355
|
+
skipped: 0,
|
|
10356
|
+
failed: 0,
|
|
10357
|
+
newWithoutDocId: 0,
|
|
10358
|
+
errors: [],
|
|
10359
|
+
failedRows: [],
|
|
10360
|
+
diffs: []
|
|
10361
|
+
};
|
|
10362
|
+
const batchModeInfo = detectCsvBatchExportMode(rows);
|
|
10363
|
+
if (batchModeInfo.error) {
|
|
10364
|
+
for (let i = 0; i < rows.length; i++) {
|
|
10365
|
+
const rowNumber = startRowNumber + i;
|
|
10366
|
+
const row = rows[i];
|
|
10367
|
+
const docId = extractDocId(row);
|
|
10368
|
+
stats.skipped++;
|
|
10369
|
+
if (stats.failed !== void 0) stats.failed++;
|
|
10370
|
+
recordFailedCsvRow(
|
|
10371
|
+
stats,
|
|
10372
|
+
rowNumber,
|
|
10373
|
+
row,
|
|
10374
|
+
batchModeInfo.error,
|
|
10375
|
+
docId || void 0,
|
|
10376
|
+
originalHeaders
|
|
10377
|
+
);
|
|
10378
|
+
stats.diffs.push({
|
|
10379
|
+
uid,
|
|
10380
|
+
collectionName: ct.info?.displayName || uid,
|
|
10381
|
+
documentId: docId || `(Row #${rowNumber})`,
|
|
10382
|
+
label: `Row #${rowNumber}`,
|
|
10383
|
+
attribute: "__bulk_updater_metadata",
|
|
10384
|
+
oldValue: null,
|
|
10385
|
+
newValue: null,
|
|
10386
|
+
status: "error",
|
|
10387
|
+
message: batchModeInfo.error
|
|
10388
|
+
});
|
|
10389
|
+
}
|
|
10390
|
+
return stats;
|
|
10391
|
+
}
|
|
10392
|
+
const rowOptions = {
|
|
10393
|
+
...options,
|
|
10394
|
+
expectedExportMode: batchModeInfo.mode
|
|
10395
|
+
};
|
|
10151
10396
|
for (let i = 0; i < rows.length; i++) {
|
|
10152
10397
|
const rowNumber = startRowNumber + i;
|
|
10153
10398
|
const row = rows[i];
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
collectionName: ct.info?.displayName || uid,
|
|
10168
|
-
documentId: docId || `(Row #${rowNumber})`,
|
|
10169
|
-
label: `Row #${rowNumber}`,
|
|
10170
|
-
attribute: "__bulk_updater_metadata",
|
|
10171
|
-
oldValue: null,
|
|
10172
|
-
newValue: null,
|
|
10173
|
-
status: "error",
|
|
10174
|
-
message: batchModeInfo.error
|
|
10175
|
-
});
|
|
10176
|
-
}
|
|
10177
|
-
return stats;
|
|
10178
|
-
}
|
|
10179
|
-
const rowOptions = {
|
|
10180
|
-
...options,
|
|
10181
|
-
expectedExportMode: batchModeInfo.mode
|
|
10182
|
-
};
|
|
10183
|
-
for (let i = 0; i < rows.length; i++) {
|
|
10184
|
-
const rowNumber = startRowNumber + i;
|
|
10185
|
-
const row = rows[i];
|
|
10186
|
-
let docId = extractDocId(row);
|
|
10187
|
-
const rowLocale = extractLocale(row);
|
|
10188
|
-
const effectiveLocale = getEffectiveLocale(ct, rowLocale);
|
|
10189
|
-
const isEditing = isRowInEditingStage(row);
|
|
10190
|
-
if (ct.kind === "singleType" && !docId) {
|
|
10191
|
-
try {
|
|
10192
|
-
const findSingleArgs = {};
|
|
10193
|
-
if (effectiveLocale) findSingleArgs.locale = effectiveLocale;
|
|
10194
|
-
const singleDoc = await strapi.documents(uid).findFirst(findSingleArgs);
|
|
10195
|
-
if (singleDoc?.documentId) {
|
|
10196
|
-
docId = singleDoc.documentId;
|
|
10399
|
+
let docId = extractDocId(row);
|
|
10400
|
+
const rowLocale = extractLocale(row);
|
|
10401
|
+
const effectiveLocale = getEffectiveLocale(ct, rowLocale);
|
|
10402
|
+
const isEditing = isRowInEditingStage(row);
|
|
10403
|
+
if (ct.kind === "singleType" && !docId) {
|
|
10404
|
+
try {
|
|
10405
|
+
const findSingleArgs = {};
|
|
10406
|
+
if (effectiveLocale) findSingleArgs.locale = effectiveLocale;
|
|
10407
|
+
const singleDoc = await strapi.documents(uid).findFirst(findSingleArgs);
|
|
10408
|
+
if (singleDoc?.documentId) {
|
|
10409
|
+
docId = singleDoc.documentId;
|
|
10410
|
+
}
|
|
10411
|
+
} catch {
|
|
10197
10412
|
}
|
|
10198
|
-
} catch {
|
|
10199
10413
|
}
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10222
|
-
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
}
|
|
10228
|
-
await executeUpdateMutation(
|
|
10229
|
-
strapi,
|
|
10230
|
-
ct,
|
|
10231
|
-
uid,
|
|
10232
|
-
existing,
|
|
10233
|
-
row,
|
|
10234
|
-
rowNumber,
|
|
10235
|
-
rowOptions,
|
|
10236
|
-
effectiveLocale,
|
|
10237
|
-
isEditing,
|
|
10238
|
-
isDraftAndPublish,
|
|
10239
|
-
publishedCounterparts,
|
|
10240
|
-
stats,
|
|
10241
|
-
"Updated"
|
|
10242
|
-
);
|
|
10243
|
-
} else if (mode === "create_or_override") {
|
|
10244
|
-
let existing = null;
|
|
10245
|
-
if (docId) {
|
|
10246
|
-
existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
|
|
10247
|
-
}
|
|
10248
|
-
if (existing) {
|
|
10249
|
-
await executeUpdateMutation(
|
|
10250
|
-
strapi,
|
|
10251
|
-
ct,
|
|
10252
|
-
uid,
|
|
10253
|
-
existing,
|
|
10254
|
-
row,
|
|
10255
|
-
rowNumber,
|
|
10256
|
-
rowOptions,
|
|
10257
|
-
effectiveLocale,
|
|
10258
|
-
isEditing,
|
|
10259
|
-
isDraftAndPublish,
|
|
10260
|
-
publishedCounterparts,
|
|
10261
|
-
stats,
|
|
10262
|
-
"Overridden"
|
|
10263
|
-
);
|
|
10264
|
-
} else {
|
|
10265
|
-
await executeCreateMutation(
|
|
10266
|
-
strapi,
|
|
10267
|
-
ct,
|
|
10268
|
-
uid,
|
|
10269
|
-
docId,
|
|
10270
|
-
row,
|
|
10271
|
-
rowNumber,
|
|
10272
|
-
rowOptions,
|
|
10273
|
-
effectiveLocale,
|
|
10274
|
-
isEditing,
|
|
10275
|
-
isDraftAndPublish,
|
|
10276
|
-
stats
|
|
10277
|
-
);
|
|
10278
|
-
}
|
|
10279
|
-
} else {
|
|
10280
|
-
let existing = null;
|
|
10281
|
-
if (docId) {
|
|
10282
|
-
existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
|
|
10283
|
-
}
|
|
10284
|
-
if (existing) {
|
|
10414
|
+
try {
|
|
10415
|
+
if (mode === "update") {
|
|
10416
|
+
if (!docId) {
|
|
10417
|
+
stats.skipped++;
|
|
10418
|
+
recordFailedCsvRow(
|
|
10419
|
+
stats,
|
|
10420
|
+
rowNumber,
|
|
10421
|
+
row,
|
|
10422
|
+
"Missing or invalid documentId for Update mode. (Tip: Use Smart Auto-Detect mode to auto-add entries without document IDs).",
|
|
10423
|
+
void 0,
|
|
10424
|
+
originalHeaders
|
|
10425
|
+
);
|
|
10426
|
+
continue;
|
|
10427
|
+
}
|
|
10428
|
+
const existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
|
|
10429
|
+
if (!existing) {
|
|
10430
|
+
stats.skipped++;
|
|
10431
|
+
recordFailedCsvRow(
|
|
10432
|
+
stats,
|
|
10433
|
+
rowNumber,
|
|
10434
|
+
row,
|
|
10435
|
+
`Document with ID "${docId}" not found in database.`,
|
|
10436
|
+
docId,
|
|
10437
|
+
originalHeaders
|
|
10438
|
+
);
|
|
10439
|
+
continue;
|
|
10440
|
+
}
|
|
10285
10441
|
await executeUpdateMutation(
|
|
10286
10442
|
strapi,
|
|
10287
10443
|
ct,
|
|
@@ -10297,48 +10453,114 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
10297
10453
|
stats,
|
|
10298
10454
|
"Updated"
|
|
10299
10455
|
);
|
|
10456
|
+
} else if (mode === "create_or_override") {
|
|
10457
|
+
let existing = null;
|
|
10458
|
+
if (docId) {
|
|
10459
|
+
existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
|
|
10460
|
+
}
|
|
10461
|
+
if (existing) {
|
|
10462
|
+
await executeUpdateMutation(
|
|
10463
|
+
strapi,
|
|
10464
|
+
ct,
|
|
10465
|
+
uid,
|
|
10466
|
+
existing,
|
|
10467
|
+
row,
|
|
10468
|
+
rowNumber,
|
|
10469
|
+
rowOptions,
|
|
10470
|
+
effectiveLocale,
|
|
10471
|
+
isEditing,
|
|
10472
|
+
isDraftAndPublish,
|
|
10473
|
+
publishedCounterparts,
|
|
10474
|
+
stats,
|
|
10475
|
+
"Overridden"
|
|
10476
|
+
);
|
|
10477
|
+
} else {
|
|
10478
|
+
await executeCreateMutation(
|
|
10479
|
+
strapi,
|
|
10480
|
+
ct,
|
|
10481
|
+
uid,
|
|
10482
|
+
docId,
|
|
10483
|
+
row,
|
|
10484
|
+
rowNumber,
|
|
10485
|
+
rowOptions,
|
|
10486
|
+
effectiveLocale,
|
|
10487
|
+
isEditing,
|
|
10488
|
+
isDraftAndPublish,
|
|
10489
|
+
stats
|
|
10490
|
+
);
|
|
10491
|
+
}
|
|
10300
10492
|
} else {
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10493
|
+
let existing = null;
|
|
10494
|
+
if (docId) {
|
|
10495
|
+
existing = await findExistingDocument(strapi, uid, docId, effectiveLocale);
|
|
10496
|
+
}
|
|
10497
|
+
if (existing) {
|
|
10498
|
+
await executeUpdateMutation(
|
|
10499
|
+
strapi,
|
|
10500
|
+
ct,
|
|
10501
|
+
uid,
|
|
10502
|
+
existing,
|
|
10503
|
+
row,
|
|
10504
|
+
rowNumber,
|
|
10505
|
+
rowOptions,
|
|
10506
|
+
effectiveLocale,
|
|
10507
|
+
isEditing,
|
|
10508
|
+
isDraftAndPublish,
|
|
10509
|
+
publishedCounterparts,
|
|
10510
|
+
stats,
|
|
10511
|
+
"Updated"
|
|
10512
|
+
);
|
|
10513
|
+
} else {
|
|
10514
|
+
await executeCreateMutation(
|
|
10515
|
+
strapi,
|
|
10516
|
+
ct,
|
|
10517
|
+
uid,
|
|
10518
|
+
docId,
|
|
10519
|
+
row,
|
|
10520
|
+
rowNumber,
|
|
10521
|
+
rowOptions,
|
|
10522
|
+
effectiveLocale,
|
|
10523
|
+
isEditing,
|
|
10524
|
+
isDraftAndPublish,
|
|
10525
|
+
stats
|
|
10526
|
+
);
|
|
10527
|
+
}
|
|
10528
|
+
}
|
|
10529
|
+
} catch (err) {
|
|
10530
|
+
stats.skipped++;
|
|
10531
|
+
if (stats.failed !== void 0) stats.failed++;
|
|
10532
|
+
const errMsg = sanitizeUserErrorMessage(extractDetailedErrorMessage(err));
|
|
10533
|
+
if (isFetchFailedError(err)) {
|
|
10534
|
+
strapi.log?.error?.(
|
|
10535
|
+
`[bulk-updater] Network/webhook fetch error during CSV import row ${rowNumber} (${uid}/${docId || "new"}): ${errMsg}`
|
|
10313
10536
|
);
|
|
10314
10537
|
}
|
|
10538
|
+
recordFailedCsvRow(
|
|
10539
|
+
stats,
|
|
10540
|
+
rowNumber,
|
|
10541
|
+
row,
|
|
10542
|
+
errMsg,
|
|
10543
|
+
docId || void 0,
|
|
10544
|
+
originalHeaders
|
|
10545
|
+
);
|
|
10546
|
+
stats.diffs.push({
|
|
10547
|
+
uid,
|
|
10548
|
+
collectionName: ct.info?.displayName || uid,
|
|
10549
|
+
documentId: docId || `(Row #${rowNumber})`,
|
|
10550
|
+
label: `Row #${rowNumber}`,
|
|
10551
|
+
attribute: "(record)",
|
|
10552
|
+
oldValue: null,
|
|
10553
|
+
newValue: null,
|
|
10554
|
+
status: "error",
|
|
10555
|
+
message: `Failed to process row ${rowNumber}: ${errMsg}`
|
|
10556
|
+
});
|
|
10557
|
+
}
|
|
10558
|
+
if (i > 0 && i % 10 === 0) {
|
|
10559
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
10315
10560
|
}
|
|
10316
|
-
} catch (err) {
|
|
10317
|
-
stats.skipped++;
|
|
10318
|
-
if (stats.failed !== void 0) stats.failed++;
|
|
10319
|
-
const errMsg = sanitizeUserErrorMessage(extractDetailedErrorMessage(err));
|
|
10320
|
-
recordFailedCsvRow(
|
|
10321
|
-
stats,
|
|
10322
|
-
rowNumber,
|
|
10323
|
-
row,
|
|
10324
|
-
errMsg,
|
|
10325
|
-
docId || void 0,
|
|
10326
|
-
originalHeaders
|
|
10327
|
-
);
|
|
10328
|
-
stats.diffs.push({
|
|
10329
|
-
uid,
|
|
10330
|
-
collectionName: ct.info?.displayName || uid,
|
|
10331
|
-
documentId: docId || `(Row #${rowNumber})`,
|
|
10332
|
-
label: `Row #${rowNumber}`,
|
|
10333
|
-
attribute: "(record)",
|
|
10334
|
-
oldValue: null,
|
|
10335
|
-
newValue: null,
|
|
10336
|
-
status: "error",
|
|
10337
|
-
message: `Failed to process row ${rowNumber}: ${errMsg}`
|
|
10338
|
-
});
|
|
10339
10561
|
}
|
|
10340
|
-
|
|
10341
|
-
|
|
10562
|
+
return stats;
|
|
10563
|
+
});
|
|
10342
10564
|
}
|
|
10343
10565
|
async function recordCsvAuditLog(strapi, ct, uid, batchId, stats, user, publishOnApproval, publishStrategy, unreviewedConsent) {
|
|
10344
10566
|
if (stats.updated === 0 && stats.created === 0) return;
|
|
@@ -11788,6 +12010,7 @@ const index = {
|
|
|
11788
12010
|
});
|
|
11789
12011
|
},
|
|
11790
12012
|
bootstrap({ strapi }) {
|
|
12013
|
+
installUndiciCrashGuard(strapi);
|
|
11791
12014
|
strapi.server.use(async (ctx, next) => {
|
|
11792
12015
|
try {
|
|
11793
12016
|
await next();
|
|
@@ -11810,6 +12033,9 @@ const index = {
|
|
|
11810
12033
|
}
|
|
11811
12034
|
});
|
|
11812
12035
|
strapi.documents.use(async (context, next) => {
|
|
12036
|
+
if (typeof context.uid === "string" && context.uid.startsWith("plugin::bulk-updater.")) {
|
|
12037
|
+
return await next();
|
|
12038
|
+
}
|
|
11813
12039
|
const params = context.params;
|
|
11814
12040
|
if (["create", "update"].includes(context.action)) {
|
|
11815
12041
|
const data = params?.data;
|
|
@@ -11993,9 +12219,14 @@ export {
|
|
|
11993
12219
|
extractMetadataFromRow,
|
|
11994
12220
|
extractRowFlattenedMetadata,
|
|
11995
12221
|
formatErrorCsvFilename,
|
|
12222
|
+
formatErrorWithCause,
|
|
12223
|
+
getActiveBulkOperationCount,
|
|
11996
12224
|
getAllNestedValues,
|
|
12225
|
+
getBatchConcurrency,
|
|
11997
12226
|
getDeepProp,
|
|
11998
12227
|
inspectRowMetadataMode,
|
|
12228
|
+
installUndiciCrashGuard,
|
|
12229
|
+
isFetchFailedError,
|
|
11999
12230
|
isPlainObject,
|
|
12000
12231
|
isValidDocumentId,
|
|
12001
12232
|
normalizeExportMode,
|
|
@@ -12013,12 +12244,14 @@ export {
|
|
|
12013
12244
|
resolveMediaIds,
|
|
12014
12245
|
resolveRelationPayload,
|
|
12015
12246
|
resolveTargetObjectField,
|
|
12247
|
+
sanitizeSensitiveErrorText,
|
|
12016
12248
|
sanitizeUserErrorMessage,
|
|
12017
12249
|
serializeDocumentsToCsv,
|
|
12018
12250
|
serializeFieldValue,
|
|
12019
12251
|
serializePlannedCell,
|
|
12020
12252
|
setDeepProp,
|
|
12021
12253
|
sortAuditRecordsDesc,
|
|
12254
|
+
trackActiveBulkOperation,
|
|
12022
12255
|
validateEntityQuotas,
|
|
12023
12256
|
validateRecordSchemaConstraints,
|
|
12024
12257
|
verifyDocumentIntegrity,
|