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