strapi-plugin-bulk-updater 1.5.7 → 1.5.9
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/_chunks/{BulkUpdater-KtGgE0LO.js → BulkUpdater-C0uR_ORS.js} +186 -98
- package/dist/_chunks/BulkUpdater-C0uR_ORS.js.map +1 -0
- package/dist/_chunks/{BulkUpdater-Ci_Uojtf.mjs → BulkUpdater-RWXTJOa6.mjs} +186 -98
- package/dist/_chunks/BulkUpdater-RWXTJOa6.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +364 -348
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +364 -348
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-Ci_Uojtf.mjs.map +0 -1
- package/dist/_chunks/BulkUpdater-KtGgE0LO.js.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -993,150 +993,111 @@ function formatEntryRecord(entry) {
|
|
|
993
993
|
}
|
|
994
994
|
return formatted;
|
|
995
995
|
}
|
|
996
|
-
function
|
|
997
|
-
if (
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
996
|
+
function isRowInEditingStage$1(row) {
|
|
997
|
+
if (!row || typeof row !== "object") return false;
|
|
998
|
+
const candidates = [
|
|
999
|
+
row.strapi_stage,
|
|
1000
|
+
row["strapi_stage"],
|
|
1001
|
+
row.strapiStage,
|
|
1002
|
+
row["Strapi Stage"],
|
|
1003
|
+
row["strapi-stage"],
|
|
1004
|
+
row.stage,
|
|
1005
|
+
row.Stage,
|
|
1006
|
+
row.review_stage,
|
|
1007
|
+
row.workflow_stage
|
|
1008
|
+
];
|
|
1009
|
+
if (row.status && typeof row.status === "string") {
|
|
1010
|
+
const s = row.status.trim().toLowerCase();
|
|
1011
|
+
if (s === "editing" || s === "in review" || s === "in_review" || s === "pending review" || s === "pending_review") {
|
|
1012
|
+
candidates.push(row.status);
|
|
1009
1013
|
}
|
|
1010
|
-
return trimmed;
|
|
1011
1014
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
"
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
"stage.name",
|
|
1028
|
-
"stage[name]",
|
|
1029
|
-
"stage_name",
|
|
1030
|
-
"Stage Name",
|
|
1031
|
-
"review_stage",
|
|
1032
|
-
"review_stage.name",
|
|
1033
|
-
"review_stage[name]",
|
|
1034
|
-
"Review Stage",
|
|
1035
|
-
"reviewStage",
|
|
1036
|
-
"workflow_stage",
|
|
1037
|
-
"workflow_stage.name",
|
|
1038
|
-
"Workflow Stage",
|
|
1039
|
-
"workflowStage"
|
|
1040
|
-
];
|
|
1041
|
-
for (const prop of candidateProps) {
|
|
1042
|
-
if (val[prop] !== void 0 && val[prop] !== null) {
|
|
1043
|
-
const fromProp = extractStageName(val[prop]);
|
|
1044
|
-
if (fromProp) return fromProp;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
const keys = Object.keys(val);
|
|
1048
|
-
for (const k of keys) {
|
|
1049
|
-
const norm = k.toLowerCase().replace(/[\s_\-\.\[\]]+/g, "");
|
|
1050
|
-
if (norm === "strapistage" || norm === "strapistagename" || norm === "stagename" || norm === "reviewstage" || norm === "reviewstagename" || norm === "workflowstage" || norm === "workflowstagename") {
|
|
1051
|
-
if (val[k] !== void 0 && val[k] !== null) {
|
|
1052
|
-
const fromNorm = extractStageName(val[k]);
|
|
1053
|
-
if (fromNorm) return fromNorm;
|
|
1015
|
+
for (const c of candidates) {
|
|
1016
|
+
if (c !== void 0 && c !== null) {
|
|
1017
|
+
let stageName = "";
|
|
1018
|
+
if (typeof c === "object") {
|
|
1019
|
+
stageName = String(c.name || c.title || c.status || c.documentId || c.id || "").trim();
|
|
1020
|
+
} else if (typeof c === "string") {
|
|
1021
|
+
const trimmed = c.trim();
|
|
1022
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
1023
|
+
try {
|
|
1024
|
+
const parsed = JSON.parse(trimmed);
|
|
1025
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
1026
|
+
stageName = String(parsed.name || parsed.title || parsed.status || parsed.documentId || parsed.id || "").trim();
|
|
1027
|
+
}
|
|
1028
|
+
} catch {
|
|
1029
|
+
}
|
|
1054
1030
|
}
|
|
1031
|
+
if (!stageName) {
|
|
1032
|
+
stageName = trimmed;
|
|
1033
|
+
}
|
|
1034
|
+
} else {
|
|
1035
|
+
stageName = String(c).trim();
|
|
1055
1036
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
val.name,
|
|
1062
|
-
val.title,
|
|
1063
|
-
val.label,
|
|
1064
|
-
val.value,
|
|
1065
|
-
val.stageName,
|
|
1066
|
-
val.stage_name,
|
|
1067
|
-
val.status
|
|
1068
|
-
];
|
|
1069
|
-
for (const sv of candidateStageValues) {
|
|
1070
|
-
if (sv !== void 0 && sv !== null && typeof sv === "string" && sv.trim()) {
|
|
1071
|
-
return sv.trim();
|
|
1037
|
+
if (stageName) {
|
|
1038
|
+
const s = stageName.toLowerCase();
|
|
1039
|
+
if (s === "editing" || s === "in review" || s === "in_review" || s === "pending review" || s === "pending_review") {
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1072
1042
|
}
|
|
1073
1043
|
}
|
|
1074
1044
|
}
|
|
1075
|
-
return
|
|
1076
|
-
}
|
|
1077
|
-
function isStageApproved(stageVal) {
|
|
1078
|
-
const name = extractStageName(stageVal);
|
|
1079
|
-
return name.toLowerCase() === "approved";
|
|
1080
|
-
}
|
|
1081
|
-
function isStageEditingOrPending(stageVal) {
|
|
1082
|
-
const name = extractStageName(stageVal).toLowerCase();
|
|
1083
|
-
return name === "editing" || name === "in review" || name === "in_review" || name === "pending review" || name === "pending_review";
|
|
1045
|
+
return false;
|
|
1084
1046
|
}
|
|
1085
|
-
function
|
|
1047
|
+
function resolveRecordPublicationStatus(entry, publishedRecord, isDraftAndPublish) {
|
|
1048
|
+
if (isDraftAndPublish === false) {
|
|
1049
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1050
|
+
}
|
|
1086
1051
|
if (!entry || typeof entry !== "object") {
|
|
1087
|
-
return {
|
|
1052
|
+
return { status: "unknown", hadPublishedVersion: false };
|
|
1088
1053
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1054
|
+
if (typeof entry.status === "string" && entry.status.trim()) {
|
|
1055
|
+
const s = entry.status.trim().toLowerCase();
|
|
1056
|
+
if (s === "published") {
|
|
1057
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1058
|
+
}
|
|
1059
|
+
if (s === "modified") {
|
|
1060
|
+
return { status: "modified", hadPublishedVersion: true };
|
|
1061
|
+
}
|
|
1062
|
+
if (s === "draft") {
|
|
1063
|
+
return { status: "draft", hadPublishedVersion: false };
|
|
1064
|
+
}
|
|
1092
1065
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1066
|
+
const pub = publishedRecord || (entry.publishedAt ? entry : null);
|
|
1067
|
+
if (!pub) {
|
|
1068
|
+
return { status: "draft", hadPublishedVersion: false };
|
|
1095
1069
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1070
|
+
const draftUpdatedTime = new Date(entry.updatedAt || entry.updated_at || 0).getTime();
|
|
1071
|
+
const pubUpdatedTime = new Date(pub.updatedAt || pub.updated_at || 0).getTime();
|
|
1072
|
+
const pubPublishedTime = new Date(pub.publishedAt || pub.published_at || 0).getTime();
|
|
1073
|
+
const lastPublishedTime = Math.max(
|
|
1074
|
+
isNaN(pubUpdatedTime) ? 0 : pubUpdatedTime,
|
|
1075
|
+
isNaN(pubPublishedTime) ? 0 : pubPublishedTime
|
|
1076
|
+
);
|
|
1077
|
+
if (isNaN(draftUpdatedTime) || lastPublishedTime === 0) {
|
|
1078
|
+
if (pub.publishedAt || pub.published_at) {
|
|
1079
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1080
|
+
}
|
|
1081
|
+
return { status: "unknown", hadPublishedVersion: false };
|
|
1098
1082
|
}
|
|
1099
|
-
if (
|
|
1100
|
-
|
|
1101
|
-
const pubUpdatedTime = new Date(publishedCounterpart.updatedAt || publishedCounterpart.updated_at || 0).getTime();
|
|
1102
|
-
const pubPublishedTime = new Date(publishedCounterpart.publishedAt || publishedCounterpart.published_at || 0).getTime();
|
|
1103
|
-
const lastPublishedTime = Math.max(
|
|
1104
|
-
isNaN(pubUpdatedTime) ? 0 : pubUpdatedTime,
|
|
1105
|
-
isNaN(pubPublishedTime) ? 0 : pubPublishedTime
|
|
1106
|
-
);
|
|
1107
|
-
const isModified = !isNaN(draftUpdatedTime) && lastPublishedTime > 0 && draftUpdatedTime > lastPublishedTime;
|
|
1108
|
-
return { hadPublishedVersion: true, isModified };
|
|
1083
|
+
if (draftUpdatedTime > lastPublishedTime) {
|
|
1084
|
+
return { status: "modified", hadPublishedVersion: true };
|
|
1109
1085
|
}
|
|
1110
|
-
|
|
1111
|
-
return { hadPublishedVersion: hasPubAt, isModified: false };
|
|
1086
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1112
1087
|
}
|
|
1113
|
-
function
|
|
1088
|
+
function evaluateShouldPublish({
|
|
1114
1089
|
isDraftAndPublish,
|
|
1115
1090
|
hadPublishedVersion,
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
publish = true,
|
|
1091
|
+
isEditing,
|
|
1092
|
+
publishOnApproval = true,
|
|
1119
1093
|
publishStrategy = "safe",
|
|
1120
1094
|
unreviewedConsent = false
|
|
1121
1095
|
}) {
|
|
1122
|
-
if (!isDraftAndPublish
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
if (
|
|
1126
|
-
|
|
1127
|
-
}
|
|
1128
|
-
const isApproved = isStageApproved(stageValue);
|
|
1129
|
-
const isEditingOrPending = isStageEditingOrPending(stageValue);
|
|
1130
|
-
if (isApproved) {
|
|
1131
|
-
return true;
|
|
1132
|
-
}
|
|
1133
|
-
if (isEditingOrPending) {
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1136
|
-
if (publishStrategy === "all" || unreviewedConsent) {
|
|
1137
|
-
return true;
|
|
1138
|
-
}
|
|
1139
|
-
return hadPublishedVersion && !isModified;
|
|
1096
|
+
if (!isDraftAndPublish) return false;
|
|
1097
|
+
if (!hadPublishedVersion) return false;
|
|
1098
|
+
if (!publishOnApproval) return false;
|
|
1099
|
+
if (isEditing) return false;
|
|
1100
|
+
return true;
|
|
1140
1101
|
}
|
|
1141
1102
|
async function populateDocumentLifecycleStatus(strapi, uid, entries) {
|
|
1142
1103
|
if (!entries || !Array.isArray(entries) || entries.length === 0) {
|
|
@@ -1777,49 +1738,56 @@ async function executeBatchInternal(strapi, {
|
|
|
1777
1738
|
}
|
|
1778
1739
|
const targets = Array.from(targetsMap.values());
|
|
1779
1740
|
const CHUNK_SIZE = 25;
|
|
1741
|
+
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
1742
|
+
const uidsWithDraftAndPublish = /* @__PURE__ */ new Set();
|
|
1743
|
+
const docIdsByUid = /* @__PURE__ */ new Map();
|
|
1744
|
+
for (const target of targets) {
|
|
1745
|
+
if (target.uid && target.documentId) {
|
|
1746
|
+
const ct = strapi.contentTypes[target.uid];
|
|
1747
|
+
if (ct?.options?.draftAndPublish) {
|
|
1748
|
+
uidsWithDraftAndPublish.add(target.uid);
|
|
1749
|
+
if (!docIdsByUid.has(target.uid)) {
|
|
1750
|
+
docIdsByUid.set(target.uid, []);
|
|
1751
|
+
}
|
|
1752
|
+
docIdsByUid.get(target.uid).push(target.documentId);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
for (const colUid of uidsWithDraftAndPublish) {
|
|
1757
|
+
const docIds = docIdsByUid.get(colUid) || [];
|
|
1758
|
+
if (docIds.length > 0) {
|
|
1759
|
+
try {
|
|
1760
|
+
const pubDocs = await strapi.documents(colUid).findMany({
|
|
1761
|
+
status: "published",
|
|
1762
|
+
filters: { documentId: { $in: docIds } },
|
|
1763
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
1764
|
+
limit: Math.max(docIds.length, 100)
|
|
1765
|
+
});
|
|
1766
|
+
for (const pub of pubDocs || []) {
|
|
1767
|
+
if (pub?.documentId) {
|
|
1768
|
+
publishedCounterparts.set(`${colUid}@@@${pub.documentId}`, pub);
|
|
1769
|
+
if (pub.locale) {
|
|
1770
|
+
publishedCounterparts.set(`${colUid}@@@${pub.documentId}@@@${pub.locale}`, pub);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
} catch {
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1780
1778
|
const documentLoader = /* @__PURE__ */ new Map();
|
|
1781
1779
|
const getDocumentDeduplicated = (uid, documentId) => {
|
|
1782
1780
|
const loaderKey = `${uid}@@@${documentId}`;
|
|
1783
1781
|
if (!documentLoader.has(loaderKey)) {
|
|
1784
|
-
strapi.contentTypes[uid];
|
|
1785
|
-
const findOneArgs = { documentId, populate: ["strapi_stage", "stage"] };
|
|
1786
1782
|
documentLoader.set(
|
|
1787
1783
|
loaderKey,
|
|
1788
|
-
strapi.documents(uid).findOne(
|
|
1784
|
+
strapi.documents(uid).findOne({ documentId })
|
|
1789
1785
|
);
|
|
1790
1786
|
}
|
|
1791
1787
|
return documentLoader.get(loaderKey);
|
|
1792
1788
|
};
|
|
1793
1789
|
for (let i = 0; i < targets.length; i += CHUNK_SIZE) {
|
|
1794
1790
|
const chunk = targets.slice(i, i + CHUNK_SIZE);
|
|
1795
|
-
const chunkByUid = /* @__PURE__ */ new Map();
|
|
1796
|
-
for (const t of chunk) {
|
|
1797
|
-
if (t.uid && t.documentId) {
|
|
1798
|
-
if (!chunkByUid.has(t.uid)) chunkByUid.set(t.uid, []);
|
|
1799
|
-
chunkByUid.get(t.uid).push(t.documentId);
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
1803
|
-
for (const [colUid, docIds] of chunkByUid.entries()) {
|
|
1804
|
-
const colCt = strapi.contentTypes[colUid];
|
|
1805
|
-
if (colCt?.options?.draftAndPublish && docIds.length > 0) {
|
|
1806
|
-
try {
|
|
1807
|
-
const pubList = await strapi.documents(colUid).findMany({
|
|
1808
|
-
status: "published",
|
|
1809
|
-
filters: { documentId: { $in: docIds } },
|
|
1810
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
1811
|
-
limit: docIds.length
|
|
1812
|
-
});
|
|
1813
|
-
for (const pub of pubList || []) {
|
|
1814
|
-
if (pub?.documentId) {
|
|
1815
|
-
publishedCounterparts.set(`${colUid}@@@${pub.documentId}`, pub);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
} catch (err) {
|
|
1819
|
-
strapi.log.warn(`[bulk-updater] Failed to pre-fetch published status for ${colUid}:`, err);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
1791
|
const chunkPromises = chunk.map(async (target) => {
|
|
1824
1792
|
const contentType = strapi.contentTypes[target.uid];
|
|
1825
1793
|
const displayName = contentType?.info?.displayName || target.uid;
|
|
@@ -1864,20 +1832,15 @@ async function executeBatchInternal(strapi, {
|
|
|
1864
1832
|
targetIndexes,
|
|
1865
1833
|
targetComponentUid
|
|
1866
1834
|
});
|
|
1867
|
-
await strapi.documents(target.uid).update({
|
|
1868
|
-
documentId: target.documentId,
|
|
1869
|
-
data: {
|
|
1870
|
-
[rootKey]: updatedRoot
|
|
1871
|
-
}
|
|
1872
|
-
});
|
|
1873
1835
|
const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
|
|
1874
|
-
|
|
1836
|
+
const candLocaleComp = target.locale || currentEntry?.locale;
|
|
1837
|
+
let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
1875
1838
|
if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
|
|
1876
1839
|
try {
|
|
1877
1840
|
const singlePub = await strapi.documents(target.uid).findMany({
|
|
1878
1841
|
status: "published",
|
|
1879
1842
|
filters: { documentId: target.documentId },
|
|
1880
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
1843
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
1881
1844
|
limit: 1
|
|
1882
1845
|
});
|
|
1883
1846
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -1888,23 +1851,37 @@ async function executeBatchInternal(strapi, {
|
|
|
1888
1851
|
}
|
|
1889
1852
|
}
|
|
1890
1853
|
const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
1891
|
-
const { hadPublishedVersion: hadPubComp
|
|
1892
|
-
|
|
1893
|
-
|
|
1854
|
+
const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
|
|
1855
|
+
inspectionTargetComp,
|
|
1856
|
+
pubRecordComp,
|
|
1857
|
+
isDraftAndPublishComp
|
|
1858
|
+
);
|
|
1859
|
+
const isEditingComp = isRowInEditingStage$1(inspectionTargetComp) || isRowInEditingStage$1(target);
|
|
1860
|
+
const shouldPublishComp = evaluateShouldPublish({
|
|
1894
1861
|
isDraftAndPublish: isDraftAndPublishComp,
|
|
1895
1862
|
hadPublishedVersion: hadPubComp,
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
publish: Boolean(publishOnApproval),
|
|
1863
|
+
isEditing: isEditingComp,
|
|
1864
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
1899
1865
|
publishStrategy,
|
|
1900
1866
|
unreviewedConsent
|
|
1901
1867
|
});
|
|
1868
|
+
const updateArgsComp = {
|
|
1869
|
+
documentId: target.documentId,
|
|
1870
|
+
data: {
|
|
1871
|
+
[rootKey]: updatedRoot
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
1875
|
+
updateArgsComp.locale = candLocaleComp;
|
|
1876
|
+
}
|
|
1877
|
+
await strapi.documents(target.uid).update(updateArgsComp);
|
|
1902
1878
|
if (shouldPublishComp) {
|
|
1903
1879
|
try {
|
|
1904
|
-
const pubArgs = {
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1880
|
+
const pubArgs = {
|
|
1881
|
+
documentId: target.documentId
|
|
1882
|
+
};
|
|
1883
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
1884
|
+
pubArgs.locale = candLocaleComp;
|
|
1908
1885
|
}
|
|
1909
1886
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
1910
1887
|
} catch (publishErr) {
|
|
@@ -1992,20 +1969,15 @@ async function executeBatchInternal(strapi, {
|
|
|
1992
1969
|
} else if (mode === "disconnect") {
|
|
1993
1970
|
relationPayload = { disconnect: targetDocIds };
|
|
1994
1971
|
}
|
|
1995
|
-
await strapi.documents(target.uid).update({
|
|
1996
|
-
documentId: target.documentId,
|
|
1997
|
-
data: {
|
|
1998
|
-
[attribute]: relationPayload
|
|
1999
|
-
}
|
|
2000
|
-
});
|
|
2001
1972
|
const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
|
|
2002
|
-
|
|
1973
|
+
const candLocaleRel = target.locale || currentEntry?.locale;
|
|
1974
|
+
let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
2003
1975
|
if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
|
|
2004
1976
|
try {
|
|
2005
1977
|
const singlePub = await strapi.documents(target.uid).findMany({
|
|
2006
1978
|
status: "published",
|
|
2007
1979
|
filters: { documentId: target.documentId },
|
|
2008
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
1980
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
2009
1981
|
limit: 1
|
|
2010
1982
|
});
|
|
2011
1983
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -2016,23 +1988,37 @@ async function executeBatchInternal(strapi, {
|
|
|
2016
1988
|
}
|
|
2017
1989
|
}
|
|
2018
1990
|
const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
2019
|
-
const { hadPublishedVersion: hadPubRel
|
|
2020
|
-
|
|
2021
|
-
|
|
1991
|
+
const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
|
|
1992
|
+
inspectionTargetRel,
|
|
1993
|
+
pubRecordRel,
|
|
1994
|
+
isDraftAndPublishRel
|
|
1995
|
+
);
|
|
1996
|
+
const isEditingRel = isRowInEditingStage$1(inspectionTargetRel) || isRowInEditingStage$1(target);
|
|
1997
|
+
const shouldPublishRel = evaluateShouldPublish({
|
|
2022
1998
|
isDraftAndPublish: isDraftAndPublishRel,
|
|
2023
1999
|
hadPublishedVersion: hadPubRel,
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
publish: Boolean(publishOnApproval),
|
|
2000
|
+
isEditing: isEditingRel,
|
|
2001
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
2027
2002
|
publishStrategy,
|
|
2028
2003
|
unreviewedConsent
|
|
2029
2004
|
});
|
|
2005
|
+
const updateArgsRel = {
|
|
2006
|
+
documentId: target.documentId,
|
|
2007
|
+
data: {
|
|
2008
|
+
[attribute]: relationPayload
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
2012
|
+
updateArgsRel.locale = candLocaleRel;
|
|
2013
|
+
}
|
|
2014
|
+
await strapi.documents(target.uid).update(updateArgsRel);
|
|
2030
2015
|
if (shouldPublishRel) {
|
|
2031
2016
|
try {
|
|
2032
|
-
const pubArgs = {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2017
|
+
const pubArgs = {
|
|
2018
|
+
documentId: target.documentId
|
|
2019
|
+
};
|
|
2020
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
2021
|
+
pubArgs.locale = candLocaleRel;
|
|
2036
2022
|
}
|
|
2037
2023
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
2038
2024
|
} catch (publishErr) {
|
|
@@ -2066,20 +2052,15 @@ async function executeBatchInternal(strapi, {
|
|
|
2066
2052
|
if (regexObj && typeof currentVal === "string") {
|
|
2067
2053
|
newValue = currentVal.replace(regexObj, value);
|
|
2068
2054
|
}
|
|
2069
|
-
await strapi.documents(target.uid).update({
|
|
2070
|
-
documentId: target.documentId,
|
|
2071
|
-
data: {
|
|
2072
|
-
[attribute]: newValue
|
|
2073
|
-
}
|
|
2074
|
-
});
|
|
2075
2055
|
const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
|
|
2076
|
-
|
|
2056
|
+
const candLocaleScalar = target.locale || currentEntry?.locale;
|
|
2057
|
+
let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
2077
2058
|
if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
|
|
2078
2059
|
try {
|
|
2079
2060
|
const singlePub = await strapi.documents(target.uid).findMany({
|
|
2080
2061
|
status: "published",
|
|
2081
2062
|
filters: { documentId: target.documentId },
|
|
2082
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
2063
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
2083
2064
|
limit: 1
|
|
2084
2065
|
});
|
|
2085
2066
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -2090,23 +2071,37 @@ async function executeBatchInternal(strapi, {
|
|
|
2090
2071
|
}
|
|
2091
2072
|
}
|
|
2092
2073
|
const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
2093
|
-
const { hadPublishedVersion: hadPubScalar
|
|
2094
|
-
|
|
2095
|
-
|
|
2074
|
+
const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
|
|
2075
|
+
inspectionTargetScalar,
|
|
2076
|
+
pubRecordScalar,
|
|
2077
|
+
isDraftAndPublishScalar
|
|
2078
|
+
);
|
|
2079
|
+
const isEditingScalar = isRowInEditingStage$1(inspectionTargetScalar) || isRowInEditingStage$1(target);
|
|
2080
|
+
const shouldPublishScalar = evaluateShouldPublish({
|
|
2096
2081
|
isDraftAndPublish: isDraftAndPublishScalar,
|
|
2097
2082
|
hadPublishedVersion: hadPubScalar,
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
publish: Boolean(publishOnApproval),
|
|
2083
|
+
isEditing: isEditingScalar,
|
|
2084
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
2101
2085
|
publishStrategy,
|
|
2102
2086
|
unreviewedConsent
|
|
2103
2087
|
});
|
|
2088
|
+
const updateArgsScalar = {
|
|
2089
|
+
documentId: target.documentId,
|
|
2090
|
+
data: {
|
|
2091
|
+
[attribute]: newValue
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
2095
|
+
updateArgsScalar.locale = candLocaleScalar;
|
|
2096
|
+
}
|
|
2097
|
+
await strapi.documents(target.uid).update(updateArgsScalar);
|
|
2104
2098
|
if (shouldPublishScalar) {
|
|
2105
2099
|
try {
|
|
2106
|
-
const pubArgs = {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2100
|
+
const pubArgs = {
|
|
2101
|
+
documentId: target.documentId
|
|
2102
|
+
};
|
|
2103
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
2104
|
+
pubArgs.locale = candLocaleScalar;
|
|
2110
2105
|
}
|
|
2111
2106
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
2112
2107
|
} catch (publishErr) {
|
|
@@ -5480,30 +5475,50 @@ function getEffectiveLocale(ct, rowLocale) {
|
|
|
5480
5475
|
}
|
|
5481
5476
|
return trimmed;
|
|
5482
5477
|
}
|
|
5483
|
-
function
|
|
5484
|
-
if (row
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5478
|
+
function isRowInEditingStage(row) {
|
|
5479
|
+
if (!row || typeof row !== "object") return false;
|
|
5480
|
+
const candidates = [
|
|
5481
|
+
row.strapi_stage,
|
|
5482
|
+
row["strapi_stage"],
|
|
5483
|
+
row.strapiStage,
|
|
5484
|
+
row["Strapi Stage"],
|
|
5485
|
+
row["strapi-stage"],
|
|
5486
|
+
row.stage,
|
|
5487
|
+
row.Stage,
|
|
5488
|
+
row.status,
|
|
5489
|
+
row.Status
|
|
5490
|
+
];
|
|
5491
|
+
for (const c of candidates) {
|
|
5492
|
+
if (c !== void 0 && c !== null) {
|
|
5493
|
+
let stageName = "";
|
|
5494
|
+
if (typeof c === "object") {
|
|
5495
|
+
stageName = String(c.name || c.title || c.status || c.documentId || c.id || "").trim();
|
|
5496
|
+
} else if (typeof c === "string") {
|
|
5497
|
+
const trimmed = c.trim();
|
|
5498
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
5499
|
+
try {
|
|
5500
|
+
const parsed = JSON.parse(trimmed);
|
|
5501
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
5502
|
+
stageName = String(parsed.name || parsed.title || parsed.status || parsed.documentId || parsed.id || "").trim();
|
|
5503
|
+
}
|
|
5504
|
+
} catch {
|
|
5505
|
+
}
|
|
5506
|
+
}
|
|
5507
|
+
if (!stageName) {
|
|
5508
|
+
stageName = trimmed;
|
|
5509
|
+
}
|
|
5510
|
+
} else {
|
|
5511
|
+
stageName = String(c).trim();
|
|
5512
|
+
}
|
|
5513
|
+
if (stageName) {
|
|
5514
|
+
const s = stageName.toLowerCase();
|
|
5515
|
+
if (s === "editing" || s === "in review" || s === "in_review" || s === "pending review" || s === "pending_review") {
|
|
5516
|
+
return true;
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5494
5519
|
}
|
|
5495
|
-
const stageNameFromExisting = extractStageName(existing);
|
|
5496
|
-
if (stageNameFromExisting) return stageNameFromExisting;
|
|
5497
5520
|
}
|
|
5498
|
-
return
|
|
5499
|
-
}
|
|
5500
|
-
function isRowInEditingStage(row, existing) {
|
|
5501
|
-
const stage = resolveStageValue(row, existing);
|
|
5502
|
-
return isStageEditingOrPending(stage);
|
|
5503
|
-
}
|
|
5504
|
-
function isRowInApprovedStage(row, existing) {
|
|
5505
|
-
const stage = resolveStageValue(row, existing);
|
|
5506
|
-
return isStageApproved(stage);
|
|
5521
|
+
return false;
|
|
5507
5522
|
}
|
|
5508
5523
|
function extractDetailedErrorMessage(err) {
|
|
5509
5524
|
if (!err) return "Error processing row";
|
|
@@ -5701,7 +5716,6 @@ async function findExistingDocument(strapi, uid, targetDocId, docLocale) {
|
|
|
5701
5716
|
try {
|
|
5702
5717
|
const queryArgs = { documentId: targetDocId };
|
|
5703
5718
|
if (effectiveLocale) queryArgs.locale = effectiveLocale;
|
|
5704
|
-
queryArgs.populate = ["strapi_stage", "stage"];
|
|
5705
5719
|
const found = await strapi.documents(uid).findOne(queryArgs);
|
|
5706
5720
|
if (found) return found;
|
|
5707
5721
|
} catch {
|
|
@@ -6072,34 +6086,36 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6072
6086
|
const attrs = ct.attributes || {};
|
|
6073
6087
|
const { mode = "auto", publish = true, publishStrategy = "safe", user } = options;
|
|
6074
6088
|
const isDraftAndPublish = Boolean(ct.options?.draftAndPublish);
|
|
6075
|
-
const stats = {
|
|
6076
|
-
total: rows.length,
|
|
6077
|
-
created: 0,
|
|
6078
|
-
updated: 0,
|
|
6079
|
-
skipped: 0,
|
|
6080
|
-
newWithoutDocId: 0,
|
|
6081
|
-
errors: [],
|
|
6082
|
-
diffs: []
|
|
6083
|
-
};
|
|
6084
6089
|
const docIdsInChunk = rows.map((r) => extractDocId(r)).filter(Boolean);
|
|
6085
6090
|
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
6086
6091
|
if (isDraftAndPublish && docIdsInChunk.length > 0) {
|
|
6087
6092
|
try {
|
|
6088
|
-
const
|
|
6093
|
+
const pubDocs = await strapi.documents(uid).findMany({
|
|
6089
6094
|
status: "published",
|
|
6090
6095
|
filters: { documentId: { $in: docIdsInChunk } },
|
|
6091
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
6092
|
-
limit: docIdsInChunk.length
|
|
6096
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6097
|
+
limit: Math.max(docIdsInChunk.length, 100)
|
|
6093
6098
|
});
|
|
6094
|
-
for (const pub of
|
|
6099
|
+
for (const pub of pubDocs || []) {
|
|
6095
6100
|
if (pub?.documentId) {
|
|
6096
6101
|
publishedCounterparts.set(String(pub.documentId), pub);
|
|
6102
|
+
if (pub.locale) {
|
|
6103
|
+
publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
|
|
6104
|
+
}
|
|
6097
6105
|
}
|
|
6098
6106
|
}
|
|
6099
|
-
} catch
|
|
6100
|
-
strapi.log.warn(`[csv] Failed to pre-fetch published status for CSV chunk:`, err);
|
|
6107
|
+
} catch {
|
|
6101
6108
|
}
|
|
6102
6109
|
}
|
|
6110
|
+
const stats = {
|
|
6111
|
+
total: rows.length,
|
|
6112
|
+
created: 0,
|
|
6113
|
+
updated: 0,
|
|
6114
|
+
skipped: 0,
|
|
6115
|
+
newWithoutDocId: 0,
|
|
6116
|
+
errors: [],
|
|
6117
|
+
diffs: []
|
|
6118
|
+
};
|
|
6103
6119
|
for (let i = 0; i < rows.length; i++) {
|
|
6104
6120
|
const rowNumber = startRowNumber + i;
|
|
6105
6121
|
const row = rows[i];
|
|
@@ -6161,19 +6177,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6161
6177
|
});
|
|
6162
6178
|
continue;
|
|
6163
6179
|
}
|
|
6164
|
-
|
|
6165
|
-
documentId: resolvedDocId,
|
|
6166
|
-
data: mergedPayload
|
|
6167
|
-
};
|
|
6168
|
-
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6169
|
-
await strapi.documents(uid).update(updateArgs);
|
|
6170
|
-
let pubRecord = publishedCounterparts.get(String(resolvedDocId));
|
|
6180
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6171
6181
|
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6172
6182
|
try {
|
|
6173
6183
|
const singlePub = await strapi.documents(uid).findMany({
|
|
6174
6184
|
status: "published",
|
|
6175
6185
|
filters: { documentId: resolvedDocId },
|
|
6176
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
6186
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6177
6187
|
limit: 1
|
|
6178
6188
|
});
|
|
6179
6189
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -6183,24 +6193,32 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6183
6193
|
} catch {
|
|
6184
6194
|
}
|
|
6185
6195
|
}
|
|
6186
|
-
const
|
|
6187
|
-
const
|
|
6188
|
-
const
|
|
6196
|
+
const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
|
|
6197
|
+
const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
|
|
6198
|
+
const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
|
|
6199
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6200
|
+
inspectionExisting,
|
|
6201
|
+
pubRecord,
|
|
6202
|
+
isDraftAndPublish
|
|
6203
|
+
);
|
|
6204
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6189
6205
|
isDraftAndPublish,
|
|
6190
6206
|
hadPublishedVersion,
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
publish: Boolean(publish),
|
|
6207
|
+
isEditing,
|
|
6208
|
+
publishOnApproval: Boolean(publish),
|
|
6194
6209
|
publishStrategy,
|
|
6195
6210
|
unreviewedConsent: options.unreviewedConsent
|
|
6196
6211
|
});
|
|
6212
|
+
const updateArgs = {
|
|
6213
|
+
documentId: resolvedDocId,
|
|
6214
|
+
data: mergedPayload
|
|
6215
|
+
};
|
|
6216
|
+
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6217
|
+
await strapi.documents(uid).update(updateArgs);
|
|
6197
6218
|
if (shouldPublish) {
|
|
6198
6219
|
try {
|
|
6199
6220
|
const pubArgs = { documentId: resolvedDocId };
|
|
6200
|
-
|
|
6201
|
-
if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") {
|
|
6202
|
-
pubArgs.locale = effectiveLocale;
|
|
6203
|
-
}
|
|
6221
|
+
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
6204
6222
|
await strapi.documents(uid).publish(pubArgs);
|
|
6205
6223
|
} catch (pubErr) {
|
|
6206
6224
|
strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
|
|
@@ -6244,19 +6262,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6244
6262
|
mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
|
|
6245
6263
|
}
|
|
6246
6264
|
}
|
|
6247
|
-
|
|
6248
|
-
documentId: resolvedDocId,
|
|
6249
|
-
data: mergedPayload
|
|
6250
|
-
};
|
|
6251
|
-
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6252
|
-
await strapi.documents(uid).update(updateArgs);
|
|
6253
|
-
let pubRecord = publishedCounterparts.get(String(resolvedDocId));
|
|
6265
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6254
6266
|
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6255
6267
|
try {
|
|
6256
6268
|
const singlePub = await strapi.documents(uid).findMany({
|
|
6257
6269
|
status: "published",
|
|
6258
6270
|
filters: { documentId: resolvedDocId },
|
|
6259
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
6271
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6260
6272
|
limit: 1
|
|
6261
6273
|
});
|
|
6262
6274
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -6266,22 +6278,32 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6266
6278
|
} catch {
|
|
6267
6279
|
}
|
|
6268
6280
|
}
|
|
6269
|
-
const
|
|
6270
|
-
const
|
|
6271
|
-
const
|
|
6281
|
+
const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
|
|
6282
|
+
const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
|
|
6283
|
+
const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
|
|
6284
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6285
|
+
inspectionExisting,
|
|
6286
|
+
pubRecord,
|
|
6287
|
+
isDraftAndPublish
|
|
6288
|
+
);
|
|
6289
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6272
6290
|
isDraftAndPublish,
|
|
6273
6291
|
hadPublishedVersion,
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
publish: Boolean(publish),
|
|
6292
|
+
isEditing,
|
|
6293
|
+
publishOnApproval: Boolean(publish),
|
|
6277
6294
|
publishStrategy,
|
|
6278
6295
|
unreviewedConsent: options.unreviewedConsent
|
|
6279
6296
|
});
|
|
6297
|
+
const updateArgs = {
|
|
6298
|
+
documentId: resolvedDocId,
|
|
6299
|
+
data: mergedPayload
|
|
6300
|
+
};
|
|
6301
|
+
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6302
|
+
await strapi.documents(uid).update(updateArgs);
|
|
6280
6303
|
if (shouldPublish) {
|
|
6281
6304
|
try {
|
|
6282
6305
|
const pubArgs = { documentId: resolvedDocId };
|
|
6283
|
-
|
|
6284
|
-
if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
|
|
6306
|
+
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
6285
6307
|
await strapi.documents(uid).publish(pubArgs);
|
|
6286
6308
|
} catch (pubErr) {
|
|
6287
6309
|
strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
|
|
@@ -6318,13 +6340,11 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6318
6340
|
if (effectiveLocale) createArgs.locale = effectiveLocale;
|
|
6319
6341
|
const created = await strapi.documents(uid).create(createArgs);
|
|
6320
6342
|
const newDocId = created?.documentId || docId;
|
|
6321
|
-
const
|
|
6322
|
-
const shouldPublishNew = !isEditing && !isApprovedStage && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6343
|
+
const shouldPublishNew = !isEditing && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6323
6344
|
if (shouldPublishNew && newDocId) {
|
|
6324
6345
|
try {
|
|
6325
6346
|
const pubArgs = { documentId: newDocId };
|
|
6326
|
-
|
|
6327
|
-
if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
|
|
6347
|
+
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
6328
6348
|
await strapi.documents(uid).publish(pubArgs);
|
|
6329
6349
|
} catch (pubErr) {
|
|
6330
6350
|
strapi.log.warn(`[bulk-updater] Auto-publish failed for ${newDocId}:`, pubErr);
|
|
@@ -6369,19 +6389,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6369
6389
|
mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
|
|
6370
6390
|
}
|
|
6371
6391
|
}
|
|
6372
|
-
|
|
6373
|
-
documentId: resolvedDocId,
|
|
6374
|
-
data: mergedPayload
|
|
6375
|
-
};
|
|
6376
|
-
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6377
|
-
await strapi.documents(uid).update(updateArgs);
|
|
6378
|
-
let pubRecord = publishedCounterparts.get(String(resolvedDocId));
|
|
6392
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6379
6393
|
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6380
6394
|
try {
|
|
6381
6395
|
const singlePub = await strapi.documents(uid).findMany({
|
|
6382
6396
|
status: "published",
|
|
6383
6397
|
filters: { documentId: resolvedDocId },
|
|
6384
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
6398
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6385
6399
|
limit: 1
|
|
6386
6400
|
});
|
|
6387
6401
|
if (singlePub && singlePub.length > 0) {
|
|
@@ -6391,22 +6405,32 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6391
6405
|
} catch {
|
|
6392
6406
|
}
|
|
6393
6407
|
}
|
|
6394
|
-
const
|
|
6395
|
-
const
|
|
6396
|
-
const
|
|
6408
|
+
const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
|
|
6409
|
+
const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
|
|
6410
|
+
const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
|
|
6411
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6412
|
+
inspectionExisting,
|
|
6413
|
+
pubRecord,
|
|
6414
|
+
isDraftAndPublish
|
|
6415
|
+
);
|
|
6416
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6397
6417
|
isDraftAndPublish,
|
|
6398
6418
|
hadPublishedVersion,
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
publish: Boolean(publish),
|
|
6419
|
+
isEditing,
|
|
6420
|
+
publishOnApproval: Boolean(publish),
|
|
6402
6421
|
publishStrategy,
|
|
6403
6422
|
unreviewedConsent: options.unreviewedConsent
|
|
6404
6423
|
});
|
|
6424
|
+
const updateArgs = {
|
|
6425
|
+
documentId: resolvedDocId,
|
|
6426
|
+
data: mergedPayload
|
|
6427
|
+
};
|
|
6428
|
+
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6429
|
+
await strapi.documents(uid).update(updateArgs);
|
|
6405
6430
|
if (shouldPublish) {
|
|
6406
6431
|
try {
|
|
6407
6432
|
const pubArgs = { documentId: resolvedDocId };
|
|
6408
|
-
|
|
6409
|
-
if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
|
|
6433
|
+
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
6410
6434
|
await strapi.documents(uid).publish(pubArgs);
|
|
6411
6435
|
} catch (pubErr) {
|
|
6412
6436
|
strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
|
|
@@ -6443,13 +6467,11 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6443
6467
|
if (effectiveLocale) createArgs.locale = effectiveLocale;
|
|
6444
6468
|
const created = await strapi.documents(uid).create(createArgs);
|
|
6445
6469
|
const newDocId = created?.documentId || docId;
|
|
6446
|
-
const
|
|
6447
|
-
const shouldPublishNew = !isEditing && !isApprovedStage && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6470
|
+
const shouldPublishNew = !isEditing && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6448
6471
|
if (shouldPublishNew && newDocId) {
|
|
6449
6472
|
try {
|
|
6450
6473
|
const pubArgs = { documentId: newDocId };
|
|
6451
|
-
|
|
6452
|
-
if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
|
|
6474
|
+
if (effectiveLocale) pubArgs.locale = effectiveLocale;
|
|
6453
6475
|
await strapi.documents(uid).publish(pubArgs);
|
|
6454
6476
|
} catch (pubErr) {
|
|
6455
6477
|
strapi.log.warn(`[bulk-updater] Auto-publish failed for ${newDocId}:`, pubErr);
|
|
@@ -6821,10 +6843,23 @@ const csvService = ({ strapi }) => ({
|
|
|
6821
6843
|
filters: { documentId: { $in: docIds } },
|
|
6822
6844
|
limit: docIds.length
|
|
6823
6845
|
});
|
|
6846
|
+
let pubSet = /* @__PURE__ */ new Set();
|
|
6847
|
+
if (Boolean(ct.options?.draftAndPublish)) {
|
|
6848
|
+
try {
|
|
6849
|
+
const pubDocs = await strapi.documents(uid).findMany({
|
|
6850
|
+
status: "published",
|
|
6851
|
+
filters: { documentId: { $in: docIds } },
|
|
6852
|
+
fields: ["documentId"],
|
|
6853
|
+
limit: docIds.length
|
|
6854
|
+
});
|
|
6855
|
+
pubSet = new Set((pubDocs || []).map((p) => String(p.documentId)));
|
|
6856
|
+
} catch {
|
|
6857
|
+
}
|
|
6858
|
+
}
|
|
6824
6859
|
for (const entry of entries || []) {
|
|
6825
6860
|
const titleOrName = entry.title || entry.name || entry.subject || entry.email || `Entry #${entry.documentId}`;
|
|
6826
6861
|
const identifier = entry.slug || entry.email || entry.username || entry.documentId;
|
|
6827
|
-
const isPublished = Boolean(entry.publishedAt);
|
|
6862
|
+
const isPublished = Boolean(entry.publishedAt) || pubSet.has(String(entry.documentId));
|
|
6828
6863
|
const row = [
|
|
6829
6864
|
uid,
|
|
6830
6865
|
displayName,
|
|
@@ -7037,34 +7072,36 @@ const csvService = ({ strapi }) => ({
|
|
|
7037
7072
|
draft: 0,
|
|
7038
7073
|
unreviewedCount: 0
|
|
7039
7074
|
};
|
|
7075
|
+
const errors = [];
|
|
7076
|
+
const warnings = [];
|
|
7040
7077
|
const docIdsInPreflight = rows.map((r) => extractDocId(r)).filter(Boolean);
|
|
7041
7078
|
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
7042
7079
|
if (isDraftAndPublish && docIdsInPreflight.length > 0) {
|
|
7043
7080
|
try {
|
|
7044
|
-
const
|
|
7081
|
+
const pubDocs = await strapi.documents(uid).findMany({
|
|
7045
7082
|
status: "published",
|
|
7046
7083
|
filters: { documentId: { $in: docIdsInPreflight } },
|
|
7047
|
-
fields: ["documentId", "updatedAt", "publishedAt"],
|
|
7048
|
-
limit: docIdsInPreflight.length
|
|
7084
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
7085
|
+
limit: Math.max(docIdsInPreflight.length, 100)
|
|
7049
7086
|
});
|
|
7050
|
-
for (const pub of
|
|
7087
|
+
for (const pub of pubDocs || []) {
|
|
7051
7088
|
if (pub?.documentId) {
|
|
7052
7089
|
publishedCounterparts.set(String(pub.documentId), pub);
|
|
7090
|
+
if (pub.locale) {
|
|
7091
|
+
publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
|
|
7092
|
+
}
|
|
7053
7093
|
}
|
|
7054
7094
|
}
|
|
7055
|
-
} catch
|
|
7056
|
-
strapi.log.warn(`[csv] Failed to pre-fetch published status for CSV preflight:`, err);
|
|
7095
|
+
} catch {
|
|
7057
7096
|
}
|
|
7058
7097
|
}
|
|
7059
|
-
const errors = [];
|
|
7060
|
-
const warnings = [];
|
|
7061
7098
|
for (let i = 0; i < rows.length; i++) {
|
|
7062
7099
|
const rowNumber = i + 2;
|
|
7063
7100
|
const row = rows[i];
|
|
7064
7101
|
const docId = extractDocId(row);
|
|
7065
7102
|
const rowLocale = extractLocale(row);
|
|
7066
7103
|
const effectiveLocale = getEffectiveLocale(ct, rowLocale);
|
|
7067
|
-
isRowInEditingStage(row);
|
|
7104
|
+
const isEditing = isRowInEditingStage(row);
|
|
7068
7105
|
let rowHasError = false;
|
|
7069
7106
|
let existing = null;
|
|
7070
7107
|
if (docId) {
|
|
@@ -7072,44 +7109,23 @@ const csvService = ({ strapi }) => ({
|
|
|
7072
7109
|
}
|
|
7073
7110
|
if (existing && isDraftAndPublish) {
|
|
7074
7111
|
lifecycleStats.totalChecked++;
|
|
7075
|
-
const
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
if (singlePub && singlePub.length > 0) {
|
|
7086
|
-
pubRecord = singlePub[0];
|
|
7087
|
-
publishedCounterparts.set(String(targetDocId), pubRecord);
|
|
7088
|
-
}
|
|
7089
|
-
} catch {
|
|
7090
|
-
}
|
|
7091
|
-
}
|
|
7092
|
-
const { hadPublishedVersion, isModified } = inspectPreUpdateStatus(existing, pubRecord);
|
|
7093
|
-
const stageVal = resolveStageValue(row, existing);
|
|
7094
|
-
const willPublish = determineShouldPublish({
|
|
7095
|
-
isDraftAndPublish,
|
|
7096
|
-
hadPublishedVersion,
|
|
7097
|
-
isModified,
|
|
7098
|
-
stageValue: stageVal,
|
|
7099
|
-
publish: true,
|
|
7100
|
-
publishStrategy: options.publishStrategy || "safe",
|
|
7101
|
-
unreviewedConsent: options.unreviewedConsent
|
|
7102
|
-
});
|
|
7103
|
-
if (willPublish) {
|
|
7112
|
+
const pubRecord = effectiveLocale && publishedCounterparts.get(`${docId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(docId));
|
|
7113
|
+
const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
|
|
7114
|
+
const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
|
|
7115
|
+
const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
|
|
7116
|
+
const { status: preStatus, hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
7117
|
+
inspectionExisting,
|
|
7118
|
+
pubRecord,
|
|
7119
|
+
isDraftAndPublish
|
|
7120
|
+
);
|
|
7121
|
+
if (!isEditing && preStatus === "published") {
|
|
7104
7122
|
lifecycleStats.published++;
|
|
7105
|
-
} else if (
|
|
7123
|
+
} else if (preStatus === "modified" || hadPublishedVersion && isEditing) {
|
|
7106
7124
|
lifecycleStats.modified++;
|
|
7107
7125
|
lifecycleStats.unreviewedCount++;
|
|
7108
|
-
} else
|
|
7126
|
+
} else {
|
|
7109
7127
|
lifecycleStats.draft++;
|
|
7110
7128
|
lifecycleStats.unreviewedCount++;
|
|
7111
|
-
} else {
|
|
7112
|
-
lifecycleStats.published++;
|
|
7113
7129
|
}
|
|
7114
7130
|
}
|
|
7115
7131
|
if (mode === "update") {
|