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