strapi-plugin-bulk-updater 1.5.8 → 1.5.10

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.
@@ -68,7 +68,7 @@ const index = {
68
68
  id: `${PLUGIN_ID}.plugin.name`,
69
69
  defaultMessage: "Bulk Attribute Updater"
70
70
  },
71
- Component: () => Promise.resolve().then(() => require("../_chunks/BulkUpdater-ezjrkUaf.js")),
71
+ Component: () => Promise.resolve().then(() => require("../_chunks/BulkUpdater-BlSPmNFG.js")),
72
72
  permissions: [],
73
73
  position: 3
74
74
  });
@@ -65,7 +65,7 @@ const index = {
65
65
  id: `${PLUGIN_ID}.plugin.name`,
66
66
  defaultMessage: "Bulk Attribute Updater"
67
67
  },
68
- Component: () => import("../_chunks/BulkUpdater-B58N9HHk.mjs"),
68
+ Component: () => import("../_chunks/BulkUpdater-7rkObCic.mjs"),
69
69
  permissions: [],
70
70
  position: 3
71
71
  });
@@ -5611,8 +5611,14 @@ function buildDeepPopulate(attributes, allComponents, depth = 0) {
5611
5611
  }
5612
5612
  } else if (def.type === "dynamiczone") {
5613
5613
  populate[key] = true;
5614
- } else if (def.type === "relation" || def.type === "media") {
5615
- populate[key] = true;
5614
+ } else if (def.type === "relation") {
5615
+ populate[key] = {
5616
+ fields: ["documentId", "name", "title", "slug", "username", "email"]
5617
+ };
5618
+ } else if (def.type === "media") {
5619
+ populate[key] = {
5620
+ fields: ["url", "name", "mime"]
5621
+ };
5616
5622
  }
5617
5623
  }
5618
5624
  return Object.keys(populate).length > 0 ? populate : void 0;
@@ -6177,12 +6183,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6177
6183
  });
6178
6184
  continue;
6179
6185
  }
6180
- const updateArgs = {
6181
- documentId: resolvedDocId,
6182
- data: mergedPayload
6183
- };
6184
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6185
- await strapi.documents(uid).update(updateArgs);
6186
6186
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6187
6187
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6188
6188
  try {
@@ -6199,7 +6199,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6199
6199
  } catch {
6200
6200
  }
6201
6201
  }
6202
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6202
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6203
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6204
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6203
6205
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6204
6206
  inspectionExisting,
6205
6207
  pubRecord,
@@ -6213,6 +6215,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6213
6215
  publishStrategy,
6214
6216
  unreviewedConsent: options.unreviewedConsent
6215
6217
  });
6218
+ const updateArgs = {
6219
+ documentId: resolvedDocId,
6220
+ data: mergedPayload
6221
+ };
6222
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6223
+ await strapi.documents(uid).update(updateArgs);
6216
6224
  if (shouldPublish) {
6217
6225
  try {
6218
6226
  const pubArgs = { documentId: resolvedDocId };
@@ -6260,12 +6268,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6260
6268
  mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
6261
6269
  }
6262
6270
  }
6263
- const updateArgs = {
6264
- documentId: resolvedDocId,
6265
- data: mergedPayload
6266
- };
6267
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6268
- await strapi.documents(uid).update(updateArgs);
6269
6271
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6270
6272
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6271
6273
  try {
@@ -6282,7 +6284,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6282
6284
  } catch {
6283
6285
  }
6284
6286
  }
6285
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6287
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6288
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6289
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6286
6290
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6287
6291
  inspectionExisting,
6288
6292
  pubRecord,
@@ -6296,6 +6300,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6296
6300
  publishStrategy,
6297
6301
  unreviewedConsent: options.unreviewedConsent
6298
6302
  });
6303
+ const updateArgs = {
6304
+ documentId: resolvedDocId,
6305
+ data: mergedPayload
6306
+ };
6307
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6308
+ await strapi.documents(uid).update(updateArgs);
6299
6309
  if (shouldPublish) {
6300
6310
  try {
6301
6311
  const pubArgs = { documentId: resolvedDocId };
@@ -6385,12 +6395,6 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6385
6395
  mergedPayload[key] = deepMergeComponent(existing[key], payload[key]);
6386
6396
  }
6387
6397
  }
6388
- const updateArgs = {
6389
- documentId: resolvedDocId,
6390
- data: mergedPayload
6391
- };
6392
- if (effectiveLocale) updateArgs.locale = effectiveLocale;
6393
- await strapi.documents(uid).update(updateArgs);
6394
6398
  let pubRecord = effectiveLocale && publishedCounterparts.get(`${resolvedDocId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(resolvedDocId));
6395
6399
  if (!pubRecord && isDraftAndPublish && resolvedDocId) {
6396
6400
  try {
@@ -6407,7 +6411,9 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6407
6411
  } catch {
6408
6412
  }
6409
6413
  }
6410
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
6414
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
6415
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
6416
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
6411
6417
  const { hadPublishedVersion } = resolveRecordPublicationStatus(
6412
6418
  inspectionExisting,
6413
6419
  pubRecord,
@@ -6421,6 +6427,12 @@ async function processCsvRows(strapi, ct, uid, rows, startRowNumber, options) {
6421
6427
  publishStrategy,
6422
6428
  unreviewedConsent: options.unreviewedConsent
6423
6429
  });
6430
+ const updateArgs = {
6431
+ documentId: resolvedDocId,
6432
+ data: mergedPayload
6433
+ };
6434
+ if (effectiveLocale) updateArgs.locale = effectiveLocale;
6435
+ await strapi.documents(uid).update(updateArgs);
6424
6436
  if (shouldPublish) {
6425
6437
  try {
6426
6438
  const pubArgs = { documentId: resolvedDocId };
@@ -6699,7 +6711,7 @@ const csvService = ({ strapi }) => ({
6699
6711
  lines.push(fields.map((f) => escapeCsvValue(f.key)).join(","));
6700
6712
  let totalExported = 0;
6701
6713
  const maxLimit = options.limit && options.limit > 0 ? options.limit : Infinity;
6702
- const CHUNK_SIZE = 1e3;
6714
+ const BATCH_SIZE = 200;
6703
6715
  if (ct.kind === "singleType") {
6704
6716
  const findFirstArgs = {};
6705
6717
  if (deepPopulate) {
@@ -6714,15 +6726,18 @@ const csvService = ({ strapi }) => ({
6714
6726
  } else {
6715
6727
  let currentPage = 1;
6716
6728
  let hasMore = true;
6729
+ const sortClause = ct.attributes?.createdAt ? { createdAt: "desc" } : ct.attributes?.id ? { id: "desc" } : void 0;
6717
6730
  while (hasMore && totalExported < maxLimit) {
6718
6731
  const remaining = maxLimit - totalExported;
6719
- const currentBatchLimit = Math.min(CHUNK_SIZE, remaining);
6732
+ const currentBatchLimit = Math.min(BATCH_SIZE, remaining);
6720
6733
  const findPageArgs = {
6721
6734
  filters: Object.keys(filters).length > 0 ? filters : void 0,
6722
6735
  page: currentPage,
6723
- pageSize: currentBatchLimit,
6724
- sort: { createdAt: "desc" }
6736
+ pageSize: currentBatchLimit
6725
6737
  };
6738
+ if (sortClause) {
6739
+ findPageArgs.sort = sortClause;
6740
+ }
6726
6741
  if (deepPopulate) {
6727
6742
  findPageArgs.populate = deepPopulate;
6728
6743
  }
@@ -6745,6 +6760,7 @@ const csvService = ({ strapi }) => ({
6745
6760
  } else {
6746
6761
  currentPage++;
6747
6762
  }
6763
+ await new Promise((resolve) => setImmediate(resolve));
6748
6764
  }
6749
6765
  }
6750
6766
  const csvContent = "\uFEFF" + lines.join("\r\n") + "\r\n";
@@ -6837,10 +6853,23 @@ const csvService = ({ strapi }) => ({
6837
6853
  filters: { documentId: { $in: docIds } },
6838
6854
  limit: docIds.length
6839
6855
  });
6856
+ let pubSet = /* @__PURE__ */ new Set();
6857
+ if (Boolean(ct.options?.draftAndPublish)) {
6858
+ try {
6859
+ const pubDocs = await strapi.documents(uid).findMany({
6860
+ status: "published",
6861
+ filters: { documentId: { $in: docIds } },
6862
+ fields: ["documentId"],
6863
+ limit: docIds.length
6864
+ });
6865
+ pubSet = new Set((pubDocs || []).map((p) => String(p.documentId)));
6866
+ } catch {
6867
+ }
6868
+ }
6840
6869
  for (const entry of entries || []) {
6841
6870
  const titleOrName = entry.title || entry.name || entry.subject || entry.email || `Entry #${entry.documentId}`;
6842
6871
  const identifier = entry.slug || entry.email || entry.username || entry.documentId;
6843
- const isPublished = Boolean(entry.publishedAt);
6872
+ const isPublished = Boolean(entry.publishedAt) || pubSet.has(String(entry.documentId));
6844
6873
  const row = [
6845
6874
  uid,
6846
6875
  displayName,
@@ -7055,6 +7084,27 @@ const csvService = ({ strapi }) => ({
7055
7084
  };
7056
7085
  const errors = [];
7057
7086
  const warnings = [];
7087
+ const docIdsInPreflight = rows.map((r) => extractDocId(r)).filter(Boolean);
7088
+ const publishedCounterparts = /* @__PURE__ */ new Map();
7089
+ if (isDraftAndPublish && docIdsInPreflight.length > 0) {
7090
+ try {
7091
+ const pubDocs = await strapi.documents(uid).findMany({
7092
+ status: "published",
7093
+ filters: { documentId: { $in: docIdsInPreflight } },
7094
+ fields: ["documentId", "updatedAt", "publishedAt", "locale"],
7095
+ limit: Math.max(docIdsInPreflight.length, 100)
7096
+ });
7097
+ for (const pub of pubDocs || []) {
7098
+ if (pub?.documentId) {
7099
+ publishedCounterparts.set(String(pub.documentId), pub);
7100
+ if (pub.locale) {
7101
+ publishedCounterparts.set(`${pub.documentId}@@@${pub.locale}`, pub);
7102
+ }
7103
+ }
7104
+ }
7105
+ } catch {
7106
+ }
7107
+ }
7058
7108
  for (let i = 0; i < rows.length; i++) {
7059
7109
  const rowNumber = i + 2;
7060
7110
  const row = rows[i];
@@ -7069,14 +7119,16 @@ const csvService = ({ strapi }) => ({
7069
7119
  }
7070
7120
  if (existing && isDraftAndPublish) {
7071
7121
  lifecycleStats.totalChecked++;
7072
- const inspectionExisting = row.status || row.publishedAt ? { ...existing, status: row.status, publishedAt: row.publishedAt } : existing;
7122
+ const pubRecord = effectiveLocale && publishedCounterparts.get(`${docId}@@@${effectiveLocale}`) || publishedCounterparts.get(String(docId));
7123
+ const rowStatus = row.status || row.Status || row.STATUS || row["Published Status"] || row["published_status"] || row["strapi_status"];
7124
+ const rowPubAt = row.publishedAt || row.published_at || row.PublishedAt;
7125
+ const inspectionExisting = rowStatus || rowPubAt ? { ...existing, ...rowStatus ? { status: rowStatus } : {}, ...rowPubAt ? { publishedAt: rowPubAt } : {} } : existing;
7073
7126
  const { status: preStatus, hadPublishedVersion } = resolveRecordPublicationStatus(
7074
7127
  inspectionExisting,
7075
- void 0,
7128
+ pubRecord,
7076
7129
  isDraftAndPublish
7077
7130
  );
7078
- const isApproved = !isEditing && hadPublishedVersion;
7079
- if (isApproved) {
7131
+ if (!isEditing && preStatus === "published") {
7080
7132
  lifecycleStats.published++;
7081
7133
  } else if (preStatus === "modified" || hadPublishedVersion && isEditing) {
7082
7134
  lifecycleStats.modified++;