strapi-plugin-bulk-updater 1.5.7 → 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.
@@ -990,150 +990,111 @@ function formatEntryRecord(entry) {
990
990
  }
991
991
  return formatted;
992
992
  }
993
- function extractStageName(val) {
994
- if (val === void 0 || val === null) return "";
995
- if (typeof val === "string") {
996
- const trimmed = val.trim();
997
- if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
998
- try {
999
- const parsed = JSON.parse(trimmed);
1000
- if (parsed && typeof parsed === "object") {
1001
- const fromParsed = extractStageName(parsed);
1002
- if (fromParsed) return fromParsed;
1003
- }
1004
- } catch {
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
- if (typeof val === "number") {
1010
- return String(val);
1011
- }
1012
- if (typeof val === "object") {
1013
- const candidateProps = [
1014
- "strapi_stage",
1015
- "strapi_stage.name",
1016
- "strapi_stage[name]",
1017
- "strapi_stage.title",
1018
- "strapiStage",
1019
- "Strapi Stage",
1020
- "strapi-stage",
1021
- "strapi_stage_name",
1022
- "stage",
1023
- "Stage",
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
+ }
1027
+ }
1028
+ if (!stageName) {
1029
+ stageName = trimmed;
1051
1030
  }
1031
+ } else {
1032
+ stageName = String(c).trim();
1052
1033
  }
1053
- }
1054
- if (val.documentId && !val.color && !val.workflow) {
1055
- return "";
1056
- }
1057
- const candidateStageValues = [
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 inspectPreUpdateStatus(entry, publishedCounterpart) {
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 { hadPublishedVersion: false, isModified: false };
1049
+ return { status: "unknown", hadPublishedVersion: false };
1085
1050
  }
1086
- const status = String(entry.status || "").toLowerCase();
1087
- if (status === "published") {
1088
- return { hadPublishedVersion: true, isModified: false };
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
- if (status === "modified" || status === "modified draft") {
1091
- return { hadPublishedVersion: true, isModified: true };
1063
+ const pub = publishedRecord || (entry.publishedAt ? entry : null);
1064
+ if (!pub) {
1065
+ return { status: "draft", hadPublishedVersion: false };
1092
1066
  }
1093
- if (status === "draft") {
1094
- return { hadPublishedVersion: false, isModified: false };
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 (publishedCounterpart) {
1097
- const draftUpdatedTime = new Date(entry.updatedAt || entry.updated_at || 0).getTime();
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
- const hasPubAt = Boolean(entry.publishedAt || entry.published_at);
1108
- return { hadPublishedVersion: hasPubAt, isModified: false };
1083
+ return { status: "published", hadPublishedVersion: true };
1109
1084
  }
1110
- function determineShouldPublish({
1085
+ function evaluateShouldPublish({
1111
1086
  isDraftAndPublish,
1112
1087
  hadPublishedVersion,
1113
- isModified = false,
1114
- stageValue,
1115
- publish = true,
1088
+ isEditing,
1089
+ publishOnApproval = true,
1116
1090
  publishStrategy = "safe",
1117
1091
  unreviewedConsent = false
1118
1092
  }) {
1119
- if (!isDraftAndPublish || !publish) {
1120
- return false;
1121
- }
1122
- if (!hadPublishedVersion) {
1123
- return false;
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(findOneArgs)
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
- let pubRecordComp = publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
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, isModified: isModComp } = inspectPreUpdateStatus(inspectionTargetComp, pubRecordComp);
1889
- const targetStageComp = attribute.toLowerCase() === "strapi_stage" || attribute.toLowerCase() === "stage" ? value : currentEntry?.strapi_stage ?? currentEntry?.stage ?? target?.strapi_stage ?? target?.stage;
1890
- const shouldPublishComp = determineShouldPublish({
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
- isModified: isModComp,
1894
- stageValue: targetStageComp,
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 = { documentId: target.documentId };
1902
- const candLoc = target.locale || currentEntry?.locale;
1903
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLoc && candLoc !== "null" && candLoc !== "undefined") {
1904
- pubArgs.locale = candLoc;
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
- let pubRecordRel = publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
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, isModified: isModRel } = inspectPreUpdateStatus(inspectionTargetRel, pubRecordRel);
2017
- const targetStageRel = attribute.toLowerCase() === "strapi_stage" || attribute.toLowerCase() === "stage" ? value : currentEntry?.strapi_stage ?? currentEntry?.stage ?? target?.strapi_stage ?? target?.stage;
2018
- const shouldPublishRel = determineShouldPublish({
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
- isModified: isModRel,
2022
- stageValue: targetStageRel,
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 = { documentId: target.documentId };
2030
- const candLoc = target.locale || currentEntry?.locale;
2031
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLoc && candLoc !== "null" && candLoc !== "undefined") {
2032
- pubArgs.locale = candLoc;
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
- let pubRecordScalar = publishedCounterparts.get(`${target.uid}@@@${target.documentId}`);
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, isModified: isModScalar } = inspectPreUpdateStatus(inspectionTargetScalar, pubRecordScalar);
2091
- const targetStageScalar = attribute.toLowerCase() === "strapi_stage" || attribute.toLowerCase() === "stage" ? value : currentEntry?.strapi_stage ?? currentEntry?.stage ?? target?.strapi_stage ?? target?.stage;
2092
- const shouldPublishScalar = determineShouldPublish({
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
- isModified: isModScalar,
2096
- stageValue: targetStageScalar,
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 = { documentId: target.documentId };
2104
- const candLoc = target.locale || currentEntry?.locale;
2105
- if (Boolean(contentType?.pluginOptions?.i18n?.localized) && candLoc && candLoc !== "null" && candLoc !== "undefined") {
2106
- pubArgs.locale = candLoc;
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 resolveStageValue(row, existing) {
5481
- if (row && typeof row === "object") {
5482
- const stageNameFromRow = extractStageName(row);
5483
- if (stageNameFromRow) return stageNameFromRow;
5484
- }
5485
- if (existing && typeof existing === "object") {
5486
- if (existing.strapi_stage !== void 0 && existing.strapi_stage !== null) {
5487
- return existing.strapi_stage;
5488
- }
5489
- if (existing.stage !== void 0 && existing.stage !== null) {
5490
- return existing.stage;
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 void 0;
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 pubList = await strapi.documents(uid).findMany({
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 pubList || []) {
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 (err) {
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];
@@ -6164,13 +6180,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6164
6180
  };
6165
6181
  if (effectiveLocale) updateArgs.locale = effectiveLocale;
6166
6182
  await strapi.documents(uid).update(updateArgs);
6167
- let pubRecord = publishedCounterparts.get(String(resolvedDocId));
6183
+ let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6168
6184
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6169
6185
  try {
6170
6186
  const singlePub = await strapi.documents(uid).findMany({
6171
6187
  status: "published",
6172
6188
  filters: { documentId: resolvedDocId },
6173
- fields: ["documentId", "updatedAt", "publishedAt"],
6189
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6174
6190
  limit: 1
6175
6191
  });
6176
6192
  if (singlePub && singlePub.length > 0) {
@@ -6180,24 +6196,24 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6180
6196
  } catch {
6181
6197
  }
6182
6198
  }
6183
- const { hadPublishedVersion, isModified } = inspectPreUpdateStatus(existing, pubRecord);
6184
- const stageVal = resolveStageValue(row, existing);
6185
- const shouldPublish = determineShouldPublish({
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({
6186
6206
  isDraftAndPublish,
6187
6207
  hadPublishedVersion,
6188
- isModified,
6189
- stageValue: stageVal,
6190
- publish: Boolean(publish),
6208
+ isEditing,
6209
+ publishOnApproval: Boolean(publish),
6191
6210
  publishStrategy,
6192
6211
  unreviewedConsent: options.unreviewedConsent
6193
6212
  });
6194
6213
  if (shouldPublish) {
6195
6214
  try {
6196
6215
  const pubArgs = { documentId: resolvedDocId };
6197
- const isLoc = Boolean(ct?.pluginOptions?.i18n?.localized);
6198
- if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") {
6199
- pubArgs.locale = effectiveLocale;
6200
- }
6216
+ if (effectiveLocale) pubArgs.locale = effectiveLocale;
6201
6217
  await strapi.documents(uid).publish(pubArgs);
6202
6218
  } catch (pubErr) {
6203
6219
  strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
@@ -6247,13 +6263,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6247
6263
  };
6248
6264
  if (effectiveLocale) updateArgs.locale = effectiveLocale;
6249
6265
  await strapi.documents(uid).update(updateArgs);
6250
- let pubRecord = publishedCounterparts.get(String(resolvedDocId));
6266
+ let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6251
6267
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6252
6268
  try {
6253
6269
  const singlePub = await strapi.documents(uid).findMany({
6254
6270
  status: "published",
6255
6271
  filters: { documentId: resolvedDocId },
6256
- fields: ["documentId", "updatedAt", "publishedAt"],
6272
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6257
6273
  limit: 1
6258
6274
  });
6259
6275
  if (singlePub && singlePub.length > 0) {
@@ -6263,22 +6279,24 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6263
6279
  } catch {
6264
6280
  }
6265
6281
  }
6266
- const { hadPublishedVersion, isModified } = inspectPreUpdateStatus(existing, pubRecord);
6267
- const stageVal = resolveStageValue(row, existing);
6268
- const shouldPublish = determineShouldPublish({
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({
6269
6289
  isDraftAndPublish,
6270
6290
  hadPublishedVersion,
6271
- isModified,
6272
- stageValue: stageVal,
6273
- publish: Boolean(publish),
6291
+ isEditing,
6292
+ publishOnApproval: Boolean(publish),
6274
6293
  publishStrategy,
6275
6294
  unreviewedConsent: options.unreviewedConsent
6276
6295
  });
6277
6296
  if (shouldPublish) {
6278
6297
  try {
6279
6298
  const pubArgs = { documentId: resolvedDocId };
6280
- const isLoc = Boolean(ct?.pluginOptions?.i18n?.localized);
6281
- if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
6299
+ if (effectiveLocale) pubArgs.locale = effectiveLocale;
6282
6300
  await strapi.documents(uid).publish(pubArgs);
6283
6301
  } catch (pubErr) {
6284
6302
  strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
@@ -6315,13 +6333,11 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6315
6333
  if (effectiveLocale) createArgs.locale = effectiveLocale;
6316
6334
  const created = await strapi.documents(uid).create(createArgs);
6317
6335
  const newDocId = created?.documentId || docId;
6318
- const isApprovedStage = isRowInApprovedStage(row);
6319
- 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);
6320
6337
  if (shouldPublishNew && newDocId) {
6321
6338
  try {
6322
6339
  const pubArgs = { documentId: newDocId };
6323
- const isLoc = Boolean(ct?.pluginOptions?.i18n?.localized);
6324
- if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
6340
+ if (effectiveLocale) pubArgs.locale = effectiveLocale;
6325
6341
  await strapi.documents(uid).publish(pubArgs);
6326
6342
  } catch (pubErr) {
6327
6343
  strapi.log.warn(`[bulk-updater] Auto-publish failed for ${newDocId}:`, pubErr);
@@ -6372,13 +6388,13 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6372
6388
  };
6373
6389
  if (effectiveLocale) updateArgs.locale = effectiveLocale;
6374
6390
  await strapi.documents(uid).update(updateArgs);
6375
- let pubRecord = publishedCounterparts.get(String(resolvedDocId));
6391
+ let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6376
6392
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6377
6393
  try {
6378
6394
  const singlePub = await strapi.documents(uid).findMany({
6379
6395
  status: "published",
6380
6396
  filters: { documentId: resolvedDocId },
6381
- fields: ["documentId", "updatedAt", "publishedAt"],
6397
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
6382
6398
  limit: 1
6383
6399
  });
6384
6400
  if (singlePub && singlePub.length > 0) {
@@ -6388,22 +6404,24 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6388
6404
  } catch {
6389
6405
  }
6390
6406
  }
6391
- const { hadPublishedVersion, isModified } = inspectPreUpdateStatus(existing, pubRecord);
6392
- const stageVal = resolveStageValue(row, existing);
6393
- const shouldPublish = determineShouldPublish({
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({
6394
6414
  isDraftAndPublish,
6395
6415
  hadPublishedVersion,
6396
- isModified,
6397
- stageValue: stageVal,
6398
- publish: Boolean(publish),
6416
+ isEditing,
6417
+ publishOnApproval: Boolean(publish),
6399
6418
  publishStrategy,
6400
6419
  unreviewedConsent: options.unreviewedConsent
6401
6420
  });
6402
6421
  if (shouldPublish) {
6403
6422
  try {
6404
6423
  const pubArgs = { documentId: resolvedDocId };
6405
- const isLoc = Boolean(ct?.pluginOptions?.i18n?.localized);
6406
- if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
6424
+ if (effectiveLocale) pubArgs.locale = effectiveLocale;
6407
6425
  await strapi.documents(uid).publish(pubArgs);
6408
6426
  } catch (pubErr) {
6409
6427
  strapi.log.warn(`[bulk-updater] Auto-publish failed for ${resolvedDocId}:`, pubErr);
@@ -6440,13 +6458,11 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6440
6458
  if (effectiveLocale) createArgs.locale = effectiveLocale;
6441
6459
  const created = await strapi.documents(uid).create(createArgs);
6442
6460
  const newDocId = created?.documentId || docId;
6443
- const isApprovedStage = isRowInApprovedStage(row);
6444
- 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);
6445
6462
  if (shouldPublishNew && newDocId) {
6446
6463
  try {
6447
6464
  const pubArgs = { documentId: newDocId };
6448
- const isLoc = Boolean(ct?.pluginOptions?.i18n?.localized);
6449
- if (isLoc && effectiveLocale && effectiveLocale !== "null" && effectiveLocale !== "undefined") pubArgs.locale = effectiveLocale;
6465
+ if (effectiveLocale) pubArgs.locale = effectiveLocale;
6450
6466
  await strapi.documents(uid).publish(pubArgs);
6451
6467
  } catch (pubErr) {
6452
6468
  strapi.log.warn(`[bulk-updater] Auto-publish failed for ${newDocId}:`, pubErr);
@@ -7034,25 +7050,6 @@ const csvService = ({ strapi }) => ({
7034
7050
  draft: 0,
7035
7051
  unreviewedCount: 0
7036
7052
  };
7037
- const docIdsInPreflight = rows.map((r) => extractDocId(r)).filter(Boolean);
7038
- const publishedCounterparts = /* @__PURE__ */ new Map();
7039
- if (isDraftAndPublish && docIdsInPreflight.length > 0) {
7040
- try {
7041
- const pubList = await strapi.documents(uid).findMany({
7042
- status: "published",
7043
- filters: { documentId: { $in: docIdsInPreflight } },
7044
- fields: ["documentId", "updatedAt", "publishedAt"],
7045
- limit: docIdsInPreflight.length
7046
- });
7047
- for (const pub of pubList || []) {
7048
- if (pub?.documentId) {
7049
- publishedCounterparts.set(String(pub.documentId), pub);
7050
- }
7051
- }
7052
- } catch (err) {
7053
- strapi.log.warn(`[csv] Failed to pre-fetch published status for CSV preflight:`, err);
7054
- }
7055
- }
7056
7053
  const errors2 = [];
7057
7054
  const warnings = [];
7058
7055
  for (let i = 0; i < rows.length; i++) {
@@ -7061,7 +7058,7 @@ const csvService = ({ strapi }) => ({
7061
7058
  const docId = extractDocId(row);
7062
7059
  const rowLocale = extractLocale(row);
7063
7060
  const effectiveLocale = getEffectiveLocale(ct, rowLocale);
7064
- isRowInEditingStage(row);
7061
+ const isEditing = isRowInEditingStage(row);
7065
7062
  let rowHasError = false;
7066
7063
  let existing = null;
7067
7064
  if (docId) {
@@ -7069,44 +7066,21 @@ const csvService = ({ strapi }) => ({
7069
7066
  }
7070
7067
  if (existing && isDraftAndPublish) {
7071
7068
  lifecycleStats.totalChecked++;
7072
- const targetDocId = existing.documentId || docId;
7073
- let pubRecord = publishedCounterparts.get(String(targetDocId));
7074
- if (!pubRecord && isDraftAndPublish && targetDocId) {
7075
- try {
7076
- const singlePub = await strapi.documents(uid).findMany({
7077
- status: "published",
7078
- filters: { documentId: targetDocId },
7079
- fields: ["documentId", "updatedAt", "publishedAt"],
7080
- limit: 1
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) {
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) {
7101
7077
  lifecycleStats.published++;
7102
- } else if (hadPublishedVersion && (isModified || isRowInEditingStage(row))) {
7078
+ } else if (preStatus === "modified" || hadPublishedVersion && isEditing) {
7103
7079
  lifecycleStats.modified++;
7104
7080
  lifecycleStats.unreviewedCount++;
7105
- } else if (!hadPublishedVersion) {
7081
+ } else {
7106
7082
  lifecycleStats.draft++;
7107
7083
  lifecycleStats.unreviewedCount++;
7108
- } else {
7109
- lifecycleStats.published++;
7110
7084
  }
7111
7085
  }
7112
7086
  if (mode === "update") {