strapi-plugin-bulk-updater 1.5.6 → 1.5.8
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-7YA96VJT.mjs → BulkUpdater-B58N9HHk.mjs} +21 -3
- package/dist/_chunks/BulkUpdater-B58N9HHk.mjs.map +1 -0
- package/dist/_chunks/{BulkUpdater-BTWJq8UX.js → BulkUpdater-ezjrkUaf.js} +21 -3
- package/dist/_chunks/BulkUpdater-ezjrkUaf.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +363 -161
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +363 -161
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-7YA96VJT.mjs.map +0 -1
- package/dist/_chunks/BulkUpdater-BTWJq8UX.js.map +0 -1
package/dist/server/index.mjs
CHANGED
|
@@ -990,87 +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
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
}
|
|
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);
|
|
1011
1010
|
}
|
|
1012
|
-
return String(val.name || val.title || val.status || val.label || "").trim();
|
|
1013
1011
|
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
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
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
if (!stageName) {
|
|
1029
|
+
stageName = trimmed;
|
|
1030
|
+
}
|
|
1031
|
+
} else {
|
|
1032
|
+
stageName = String(c).trim();
|
|
1033
|
+
}
|
|
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;
|
|
1022
1038
|
}
|
|
1023
|
-
} catch {
|
|
1024
1039
|
}
|
|
1025
1040
|
}
|
|
1026
|
-
return trimmed;
|
|
1027
1041
|
}
|
|
1028
|
-
return
|
|
1029
|
-
}
|
|
1030
|
-
function isStageApproved(stageVal) {
|
|
1031
|
-
const name = extractStageName(stageVal);
|
|
1032
|
-
return name.toLowerCase() === "approved";
|
|
1033
|
-
}
|
|
1034
|
-
function isStageEditingOrPending(stageVal) {
|
|
1035
|
-
const name = extractStageName(stageVal).toLowerCase();
|
|
1036
|
-
return name === "editing" || name === "in review" || name === "in_review" || name === "pending review" || name === "pending_review";
|
|
1042
|
+
return false;
|
|
1037
1043
|
}
|
|
1038
|
-
function
|
|
1044
|
+
function resolveRecordPublicationStatus(entry, publishedRecord, isDraftAndPublish) {
|
|
1045
|
+
if (isDraftAndPublish === false) {
|
|
1046
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1047
|
+
}
|
|
1039
1048
|
if (!entry || typeof entry !== "object") {
|
|
1040
|
-
return {
|
|
1049
|
+
return { status: "unknown", hadPublishedVersion: false };
|
|
1041
1050
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
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
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
const pub = publishedRecord || (entry.publishedAt ? entry : null);
|
|
1064
|
+
if (!pub) {
|
|
1065
|
+
return { status: "draft", hadPublishedVersion: false };
|
|
1066
|
+
}
|
|
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 };
|
|
1079
|
+
}
|
|
1080
|
+
if (draftUpdatedTime > lastPublishedTime) {
|
|
1081
|
+
return { status: "modified", hadPublishedVersion: true };
|
|
1082
|
+
}
|
|
1083
|
+
return { status: "published", hadPublishedVersion: true };
|
|
1046
1084
|
}
|
|
1047
|
-
function
|
|
1085
|
+
function evaluateShouldPublish({
|
|
1048
1086
|
isDraftAndPublish,
|
|
1049
1087
|
hadPublishedVersion,
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
publish = true,
|
|
1088
|
+
isEditing,
|
|
1089
|
+
publishOnApproval = true,
|
|
1053
1090
|
publishStrategy = "safe",
|
|
1054
1091
|
unreviewedConsent = false
|
|
1055
1092
|
}) {
|
|
1056
|
-
if (!isDraftAndPublish
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1062
|
-
const isApproved = isStageApproved(stageValue);
|
|
1063
|
-
const isEditingOrPending = isStageEditingOrPending(stageValue);
|
|
1064
|
-
if (isApproved) {
|
|
1065
|
-
return true;
|
|
1066
|
-
}
|
|
1067
|
-
if (isEditingOrPending) {
|
|
1068
|
-
return false;
|
|
1069
|
-
}
|
|
1070
|
-
if (publishStrategy === "all" || unreviewedConsent) {
|
|
1071
|
-
return true;
|
|
1072
|
-
}
|
|
1073
|
-
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;
|
|
1074
1098
|
}
|
|
1075
1099
|
async function populateDocumentLifecycleStatus(strapi, uid, entries) {
|
|
1076
1100
|
if (!entries || !Array.isArray(entries) || entries.length === 0) {
|
|
@@ -1711,18 +1735,50 @@ async function executeBatchInternal(strapi, {
|
|
|
1711
1735
|
}
|
|
1712
1736
|
const targets = Array.from(targetsMap.values());
|
|
1713
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
|
+
}
|
|
1714
1775
|
const documentLoader = /* @__PURE__ */ new Map();
|
|
1715
1776
|
const getDocumentDeduplicated = (uid, documentId) => {
|
|
1716
1777
|
const loaderKey = `${uid}@@@${documentId}`;
|
|
1717
1778
|
if (!documentLoader.has(loaderKey)) {
|
|
1718
|
-
const ct = strapi.contentTypes[uid];
|
|
1719
|
-
const findOneArgs = { documentId };
|
|
1720
|
-
if (ct?.attributes?.strapi_stage) {
|
|
1721
|
-
findOneArgs.populate = ["strapi_stage"];
|
|
1722
|
-
}
|
|
1723
1779
|
documentLoader.set(
|
|
1724
1780
|
loaderKey,
|
|
1725
|
-
strapi.documents(uid).findOne(
|
|
1781
|
+
strapi.documents(uid).findOne({ documentId })
|
|
1726
1782
|
);
|
|
1727
1783
|
}
|
|
1728
1784
|
return documentLoader.get(loaderKey);
|
|
@@ -1773,29 +1829,56 @@ async function executeBatchInternal(strapi, {
|
|
|
1773
1829
|
targetIndexes,
|
|
1774
1830
|
targetComponentUid
|
|
1775
1831
|
});
|
|
1776
|
-
await strapi.documents(target.uid).update({
|
|
1777
|
-
documentId: target.documentId,
|
|
1778
|
-
data: {
|
|
1779
|
-
[rootKey]: updatedRoot
|
|
1780
|
-
}
|
|
1781
|
-
});
|
|
1782
1832
|
const isDraftAndPublishComp = Boolean(contentType?.options?.draftAndPublish);
|
|
1783
|
-
const
|
|
1784
|
-
|
|
1785
|
-
|
|
1833
|
+
const candLocaleComp = target.locale || currentEntry?.locale;
|
|
1834
|
+
let pubRecordComp = candLocaleComp && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleComp}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
1835
|
+
if (!pubRecordComp && isDraftAndPublishComp && target.documentId) {
|
|
1836
|
+
try {
|
|
1837
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
1838
|
+
status: "published",
|
|
1839
|
+
filters: { documentId: target.documentId },
|
|
1840
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
1841
|
+
limit: 1
|
|
1842
|
+
});
|
|
1843
|
+
if (singlePub && singlePub.length > 0) {
|
|
1844
|
+
pubRecordComp = singlePub[0];
|
|
1845
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordComp);
|
|
1846
|
+
}
|
|
1847
|
+
} catch {
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
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({
|
|
1786
1858
|
isDraftAndPublish: isDraftAndPublishComp,
|
|
1787
1859
|
hadPublishedVersion: hadPubComp,
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
publish: Boolean(publishOnApproval),
|
|
1860
|
+
isEditing: isEditingComp,
|
|
1861
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
1791
1862
|
publishStrategy,
|
|
1792
1863
|
unreviewedConsent
|
|
1793
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);
|
|
1794
1875
|
if (shouldPublishComp) {
|
|
1795
1876
|
try {
|
|
1796
|
-
const pubArgs = {
|
|
1797
|
-
|
|
1798
|
-
|
|
1877
|
+
const pubArgs = {
|
|
1878
|
+
documentId: target.documentId
|
|
1879
|
+
};
|
|
1880
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleComp && candLocaleComp !== "null" && candLocaleComp !== "undefined") {
|
|
1881
|
+
pubArgs.locale = candLocaleComp;
|
|
1799
1882
|
}
|
|
1800
1883
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
1801
1884
|
} catch (publishErr) {
|
|
@@ -1883,29 +1966,56 @@ async function executeBatchInternal(strapi, {
|
|
|
1883
1966
|
} else if (mode === "disconnect") {
|
|
1884
1967
|
relationPayload = { disconnect: targetDocIds };
|
|
1885
1968
|
}
|
|
1886
|
-
await strapi.documents(target.uid).update({
|
|
1887
|
-
documentId: target.documentId,
|
|
1888
|
-
data: {
|
|
1889
|
-
[attribute]: relationPayload
|
|
1890
|
-
}
|
|
1891
|
-
});
|
|
1892
1969
|
const isDraftAndPublishRel = Boolean(contentType?.options?.draftAndPublish);
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
1970
|
+
const candLocaleRel = target.locale || currentEntry?.locale;
|
|
1971
|
+
let pubRecordRel = candLocaleRel && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleRel}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
1972
|
+
if (!pubRecordRel && isDraftAndPublishRel && target.documentId) {
|
|
1973
|
+
try {
|
|
1974
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
1975
|
+
status: "published",
|
|
1976
|
+
filters: { documentId: target.documentId },
|
|
1977
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
1978
|
+
limit: 1
|
|
1979
|
+
});
|
|
1980
|
+
if (singlePub && singlePub.length > 0) {
|
|
1981
|
+
pubRecordRel = singlePub[0];
|
|
1982
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordRel);
|
|
1983
|
+
}
|
|
1984
|
+
} catch {
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
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({
|
|
1896
1995
|
isDraftAndPublish: isDraftAndPublishRel,
|
|
1897
1996
|
hadPublishedVersion: hadPubRel,
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
publish: Boolean(publishOnApproval),
|
|
1997
|
+
isEditing: isEditingRel,
|
|
1998
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
1901
1999
|
publishStrategy,
|
|
1902
2000
|
unreviewedConsent
|
|
1903
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);
|
|
1904
2012
|
if (shouldPublishRel) {
|
|
1905
2013
|
try {
|
|
1906
|
-
const pubArgs = {
|
|
1907
|
-
|
|
1908
|
-
|
|
2014
|
+
const pubArgs = {
|
|
2015
|
+
documentId: target.documentId
|
|
2016
|
+
};
|
|
2017
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleRel && candLocaleRel !== "null" && candLocaleRel !== "undefined") {
|
|
2018
|
+
pubArgs.locale = candLocaleRel;
|
|
1909
2019
|
}
|
|
1910
2020
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
1911
2021
|
} catch (publishErr) {
|
|
@@ -1939,29 +2049,56 @@ async function executeBatchInternal(strapi, {
|
|
|
1939
2049
|
if (regexObj && typeof currentVal === "string") {
|
|
1940
2050
|
newValue = currentVal.replace(regexObj, value);
|
|
1941
2051
|
}
|
|
1942
|
-
await strapi.documents(target.uid).update({
|
|
1943
|
-
documentId: target.documentId,
|
|
1944
|
-
data: {
|
|
1945
|
-
[attribute]: newValue
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
2052
|
const isDraftAndPublishScalar = Boolean(contentType?.options?.draftAndPublish);
|
|
1949
|
-
const
|
|
1950
|
-
|
|
1951
|
-
|
|
2053
|
+
const candLocaleScalar = target.locale || currentEntry?.locale;
|
|
2054
|
+
let pubRecordScalar = candLocaleScalar && publishedCounterparts.get(`${target.uid}@@@${target.documentId}@@@${candLocaleScalar}`) || publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
|
|
2055
|
+
if (!pubRecordScalar && isDraftAndPublishScalar && target.documentId) {
|
|
2056
|
+
try {
|
|
2057
|
+
const singlePub = await strapi.documents(target.uid).findMany({
|
|
2058
|
+
status: "published",
|
|
2059
|
+
filters: { documentId: target.documentId },
|
|
2060
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
2061
|
+
limit: 1
|
|
2062
|
+
});
|
|
2063
|
+
if (singlePub && singlePub.length > 0) {
|
|
2064
|
+
pubRecordScalar = singlePub[0];
|
|
2065
|
+
publishedCounterparts.set(`${target.uid}@@@${target.documentId}`, pubRecordScalar);
|
|
2066
|
+
}
|
|
2067
|
+
} catch {
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
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({
|
|
1952
2078
|
isDraftAndPublish: isDraftAndPublishScalar,
|
|
1953
2079
|
hadPublishedVersion: hadPubScalar,
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
publish: Boolean(publishOnApproval),
|
|
2080
|
+
isEditing: isEditingScalar,
|
|
2081
|
+
publishOnApproval: Boolean(publishOnApproval),
|
|
1957
2082
|
publishStrategy,
|
|
1958
2083
|
unreviewedConsent
|
|
1959
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);
|
|
1960
2095
|
if (shouldPublishScalar) {
|
|
1961
2096
|
try {
|
|
1962
|
-
const pubArgs = {
|
|
1963
|
-
|
|
1964
|
-
|
|
2097
|
+
const pubArgs = {
|
|
2098
|
+
documentId: target.documentId
|
|
2099
|
+
};
|
|
2100
|
+
if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLocaleScalar && candLocaleScalar !== "null" && candLocaleScalar !== "undefined") {
|
|
2101
|
+
pubArgs.locale = candLocaleScalar;
|
|
1965
2102
|
}
|
|
1966
2103
|
await strapi.documents(target.uid).publish(pubArgs);
|
|
1967
2104
|
} catch (publishErr) {
|
|
@@ -5380,10 +5517,6 @@ function isRowInEditingStage(row) {
|
|
|
5380
5517
|
}
|
|
5381
5518
|
return false;
|
|
5382
5519
|
}
|
|
5383
|
-
function isRowInApprovedStage(row) {
|
|
5384
|
-
if (!row || typeof row !== "object") return false;
|
|
5385
|
-
return isStageApproved(row);
|
|
5386
|
-
}
|
|
5387
5520
|
function extractDetailedErrorMessage(err) {
|
|
5388
5521
|
if (!err) return "Error processing row";
|
|
5389
5522
|
const detailsErrors = err.details?.errors || err.error?.details?.errors;
|
|
@@ -5580,7 +5713,6 @@ async function findExistingDocument(strapi, uid, targetDocId, docLocale) {
|
|
|
5580
5713
|
try {
|
|
5581
5714
|
const queryArgs = { documentId: targetDocId };
|
|
5582
5715
|
if (effectiveLocale) queryArgs.locale = effectiveLocale;
|
|
5583
|
-
if (ct?.attributes?.strapi_stage) queryArgs.populate = ["strapi_stage"];
|
|
5584
5716
|
const found = await strapi.documents(uid).findOne(queryArgs);
|
|
5585
5717
|
if (found) return found;
|
|
5586
5718
|
} catch {
|
|
@@ -5951,6 +6083,27 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
5951
6083
|
const attrs = ct.attributes || {};
|
|
5952
6084
|
const { mode = "auto", publish = true, publishStrategy = "safe", user } = options;
|
|
5953
6085
|
const isDraftAndPublish = Boolean(ct.options?.draftAndPublish);
|
|
6086
|
+
const docIdsInChunk = rows.map((r) => extractDocId(r)).filter(Boolean);
|
|
6087
|
+
const publishedCounterparts = /* @__PURE__ */ new Map();
|
|
6088
|
+
if (isDraftAndPublish && docIdsInChunk.length > 0) {
|
|
6089
|
+
try {
|
|
6090
|
+
const pubDocs = await strapi.documents(uid).findMany({
|
|
6091
|
+
status: "published",
|
|
6092
|
+
filters: { documentId: { $in: docIdsInChunk } },
|
|
6093
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6094
|
+
limit: Math.max(docIdsInChunk.length, 100)
|
|
6095
|
+
});
|
|
6096
|
+
for (const pub of pubDocs || []) {
|
|
6097
|
+
if (pub?.documentId) {
|
|
6098
|
+
publishedCounterparts.set(String(pub.documentId), pub);
|
|
6099
|
+
if (pub.locale) {
|
|
6100
|
+
publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
|
|
6101
|
+
}
|
|
6102
|
+
}
|
|
6103
|
+
}
|
|
6104
|
+
} catch {
|
|
6105
|
+
}
|
|
6106
|
+
}
|
|
5954
6107
|
const stats = {
|
|
5955
6108
|
total: rows.length,
|
|
5956
6109
|
created: 0,
|
|
@@ -6027,14 +6180,33 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6027
6180
|
};
|
|
6028
6181
|
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6029
6182
|
await strapi.documents(uid).update(updateArgs);
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6183
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6184
|
+
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6185
|
+
try {
|
|
6186
|
+
const singlePub = await strapi.documents(uid).findMany({
|
|
6187
|
+
status: "published",
|
|
6188
|
+
filters: { documentId: resolvedDocId },
|
|
6189
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6190
|
+
limit: 1
|
|
6191
|
+
});
|
|
6192
|
+
if (singlePub && singlePub.length > 0) {
|
|
6193
|
+
pubRecord = singlePub[0];
|
|
6194
|
+
publishedCounterparts.set(String(resolvedDocId), pubRecord);
|
|
6195
|
+
}
|
|
6196
|
+
} catch {
|
|
6197
|
+
}
|
|
6198
|
+
}
|
|
6199
|
+
const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
|
|
6200
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6201
|
+
inspectionExisting,
|
|
6202
|
+
pubRecord,
|
|
6203
|
+
isDraftAndPublish
|
|
6204
|
+
);
|
|
6205
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6033
6206
|
isDraftAndPublish,
|
|
6034
6207
|
hadPublishedVersion,
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
publish: Boolean(publish),
|
|
6208
|
+
isEditing,
|
|
6209
|
+
publishOnApproval: Boolean(publish),
|
|
6038
6210
|
publishStrategy,
|
|
6039
6211
|
unreviewedConsent: options.unreviewedConsent
|
|
6040
6212
|
});
|
|
@@ -6091,14 +6263,33 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6091
6263
|
};
|
|
6092
6264
|
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6093
6265
|
await strapi.documents(uid).update(updateArgs);
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6266
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6267
|
+
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6268
|
+
try {
|
|
6269
|
+
const singlePub = await strapi.documents(uid).findMany({
|
|
6270
|
+
status: "published",
|
|
6271
|
+
filters: { documentId: resolvedDocId },
|
|
6272
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6273
|
+
limit: 1
|
|
6274
|
+
});
|
|
6275
|
+
if (singlePub && singlePub.length > 0) {
|
|
6276
|
+
pubRecord = singlePub[0];
|
|
6277
|
+
publishedCounterparts.set(String(resolvedDocId), pubRecord);
|
|
6278
|
+
}
|
|
6279
|
+
} catch {
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
|
|
6283
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6284
|
+
inspectionExisting,
|
|
6285
|
+
pubRecord,
|
|
6286
|
+
isDraftAndPublish
|
|
6287
|
+
);
|
|
6288
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6097
6289
|
isDraftAndPublish,
|
|
6098
6290
|
hadPublishedVersion,
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
publish: Boolean(publish),
|
|
6291
|
+
isEditing,
|
|
6292
|
+
publishOnApproval: Boolean(publish),
|
|
6102
6293
|
publishStrategy,
|
|
6103
6294
|
unreviewedConsent: options.unreviewedConsent
|
|
6104
6295
|
});
|
|
@@ -6142,8 +6333,7 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6142
6333
|
if (effectiveLocale) createArgs.locale = effectiveLocale;
|
|
6143
6334
|
const created = await strapi.documents(uid).create(createArgs);
|
|
6144
6335
|
const newDocId = created?.documentId || docId;
|
|
6145
|
-
const
|
|
6146
|
-
const shouldPublishNew = !isEditing && !isApprovedStage && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6336
|
+
const shouldPublishNew = !isEditing && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6147
6337
|
if (shouldPublishNew && newDocId) {
|
|
6148
6338
|
try {
|
|
6149
6339
|
const pubArgs = { documentId: newDocId };
|
|
@@ -6198,14 +6388,33 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6198
6388
|
};
|
|
6199
6389
|
if (effectiveLocale) updateArgs.locale = effectiveLocale;
|
|
6200
6390
|
await strapi.documents(uid).update(updateArgs);
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6391
|
+
let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
|
|
6392
|
+
if (!pubRecord && isDraftAndPublish && resolvedDocId) {
|
|
6393
|
+
try {
|
|
6394
|
+
const singlePub = await strapi.documents(uid).findMany({
|
|
6395
|
+
status: "published",
|
|
6396
|
+
filters: { documentId: resolvedDocId },
|
|
6397
|
+
fields: ["documentId", "updatedAt", "publishedAt", "locale"],
|
|
6398
|
+
limit: 1
|
|
6399
|
+
});
|
|
6400
|
+
if (singlePub && singlePub.length > 0) {
|
|
6401
|
+
pubRecord = singlePub[0];
|
|
6402
|
+
publishedCounterparts.set(String(resolvedDocId), pubRecord);
|
|
6403
|
+
}
|
|
6404
|
+
} catch {
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
|
|
6408
|
+
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
6409
|
+
inspectionExisting,
|
|
6410
|
+
pubRecord,
|
|
6411
|
+
isDraftAndPublish
|
|
6412
|
+
);
|
|
6413
|
+
const shouldPublish = evaluateShouldPublish({
|
|
6204
6414
|
isDraftAndPublish,
|
|
6205
6415
|
hadPublishedVersion,
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
publish: Boolean(publish),
|
|
6416
|
+
isEditing,
|
|
6417
|
+
publishOnApproval: Boolean(publish),
|
|
6209
6418
|
publishStrategy,
|
|
6210
6419
|
unreviewedConsent: options.unreviewedConsent
|
|
6211
6420
|
});
|
|
@@ -6249,8 +6458,7 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
|
|
|
6249
6458
|
if (effectiveLocale) createArgs.locale = effectiveLocale;
|
|
6250
6459
|
const created = await strapi.documents(uid).create(createArgs);
|
|
6251
6460
|
const newDocId = created?.documentId || docId;
|
|
6252
|
-
const
|
|
6253
|
-
const shouldPublishNew = !isEditing && !isApprovedStage && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6461
|
+
const shouldPublishNew = !isEditing && isDraftAndPublish && Boolean(publish) && (publishStrategy === "all" || options.unreviewedConsent ? true : false);
|
|
6254
6462
|
if (shouldPublishNew && newDocId) {
|
|
6255
6463
|
try {
|
|
6256
6464
|
const pubArgs = { documentId: newDocId };
|
|
@@ -6850,7 +7058,7 @@ const csvService = ({ strapi }) => ({
|
|
|
6850
7058
|
const docId = extractDocId(row);
|
|
6851
7059
|
const rowLocale = extractLocale(row);
|
|
6852
7060
|
const effectiveLocale = getEffectiveLocale(ct, rowLocale);
|
|
6853
|
-
isRowInEditingStage(row);
|
|
7061
|
+
const isEditing = isRowInEditingStage(row);
|
|
6854
7062
|
let rowHasError = false;
|
|
6855
7063
|
let existing = null;
|
|
6856
7064
|
if (docId) {
|
|
@@ -6858,27 +7066,21 @@ const csvService = ({ strapi }) => ({
|
|
|
6858
7066
|
}
|
|
6859
7067
|
if (existing && isDraftAndPublish) {
|
|
6860
7068
|
lifecycleStats.totalChecked++;
|
|
6861
|
-
const {
|
|
6862
|
-
const
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
publishStrategy: options.publishStrategy || "safe",
|
|
6870
|
-
unreviewedConsent: options.unreviewedConsent
|
|
6871
|
-
});
|
|
6872
|
-
if (willPublish) {
|
|
7069
|
+
const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
|
|
7070
|
+
const { status: preStatus, hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
7071
|
+
inspectionExisting,
|
|
7072
|
+
void 0,
|
|
7073
|
+
isDraftAndPublish
|
|
7074
|
+
);
|
|
7075
|
+
const isApproved = !isEditing && hadPublishedVersion;
|
|
7076
|
+
if (isApproved) {
|
|
6873
7077
|
lifecycleStats.published++;
|
|
6874
|
-
} else if (
|
|
7078
|
+
} else if (preStatus === "modified" || hadPublishedVersion && isEditing) {
|
|
6875
7079
|
lifecycleStats.modified++;
|
|
6876
7080
|
lifecycleStats.unreviewedCount++;
|
|
6877
|
-
} else
|
|
7081
|
+
} else {
|
|
6878
7082
|
lifecycleStats.draft++;
|
|
6879
7083
|
lifecycleStats.unreviewedCount++;
|
|
6880
|
-
} else {
|
|
6881
|
-
lifecycleStats.published++;
|
|
6882
7084
|
}
|
|
6883
7085
|
}
|
|
6884
7086
|
if (mode === "update") {
|