strapi-plugin-bulk-updater 1.6.6 → 1.6.7

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.
@@ -5638,7 +5638,7 @@ async function resolveAndMaybePublishTarget({
5638
5638
  }
5639
5639
  }
5640
5640
  const inspectionTarget = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
5641
- const { hadPublishedVersion } = resolveRecordPublicationStatus(inspectionTarget, pubRecord, isDraftAndPublish);
5641
+ const { hadPublishedVersion, status: preStatus } = resolveRecordPublicationStatus(inspectionTarget, pubRecord, isDraftAndPublish);
5642
5642
  const isEditing = isRowInEditingStage$1(inspectionTarget) || isRowInEditingStage$1(target);
5643
5643
  const shouldPublish = evaluateShouldPublish({
5644
5644
  isDraftAndPublish,
@@ -5652,6 +5652,7 @@ async function resolveAndMaybePublishTarget({
5652
5652
  candLocale: isLocalized ? candLocale : void 0,
5653
5653
  isDraftAndPublish,
5654
5654
  hadPublishedVersion,
5655
+ previousStatus: preStatus,
5655
5656
  shouldPublish,
5656
5657
  async postUpdate(relatedTargetUid) {
5657
5658
  if (shouldPublish) {
@@ -5815,6 +5816,9 @@ async function executeGridTargetUpdate({
5815
5816
  oldValue: oldSummaryVal,
5816
5817
  newValue: newSummaryVal,
5817
5818
  status: "updated",
5819
+ previousStatus: lifecycle.previousStatus,
5820
+ hadPublishedVersion: lifecycle.hadPublishedVersion,
5821
+ isDraftAndPublish: lifecycle.isDraftAndPublish,
5818
5822
  message: isMultiOcc ? `Successfully updated ${changedDiffs.length} grid occurrence(s) in ${attribute}` : `Successfully updated ${attribute}`,
5819
5823
  dynamicZoneDiffs: isComponentNested ? changedDiffs : void 0,
5820
5824
  gridGroupDiffs: changedDiffs.length > 1 || isComponentNested ? changedDiffs : void 0
@@ -6032,7 +6036,7 @@ async function executeBatchInternal(strapi, {
6032
6036
  }
6033
6037
  }
6034
6038
  const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6035
- const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
6039
+ const { hadPublishedVersion: hadPubComp, status: preStatusComp } = resolveRecordPublicationStatus(
6036
6040
  inspectionTargetComp,
6037
6041
  pubRecordComp,
6038
6042
  isDraftAndPublishComp
@@ -6105,11 +6109,15 @@ async function executeBatchInternal(strapi, {
6105
6109
  uid: target.uid,
6106
6110
  collectionName: displayName,
6107
6111
  documentId: target.documentId,
6112
+ locale: candLocaleComp,
6108
6113
  label: entryLabel,
6109
6114
  attribute,
6110
6115
  oldValue: currentVal2 ?? null,
6111
6116
  newValue: newValue2,
6112
6117
  status: "updated",
6118
+ previousStatus: preStatusComp,
6119
+ hadPublishedVersion: hadPubComp,
6120
+ isDraftAndPublish: isDraftAndPublishComp,
6113
6121
  message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
6114
6122
  dynamicZoneDiffs: dzDiffs
6115
6123
  };
@@ -6186,7 +6194,7 @@ async function executeBatchInternal(strapi, {
6186
6194
  }
6187
6195
  }
6188
6196
  const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6189
- const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
6197
+ const { hadPublishedVersion: hadPubRel, status: preStatusRel } = resolveRecordPublicationStatus(
6190
6198
  inspectionTargetRel,
6191
6199
  pubRecordRel,
6192
6200
  isDraftAndPublishRel
@@ -6254,11 +6262,15 @@ async function executeBatchInternal(strapi, {
6254
6262
  uid: target.uid,
6255
6263
  collectionName: displayName,
6256
6264
  documentId: target.documentId,
6265
+ locale: candLocaleRel,
6257
6266
  label: entryLabel,
6258
6267
  attribute,
6259
6268
  oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
6260
6269
  newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
6261
6270
  status: "updated",
6271
+ previousStatus: preStatusRel,
6272
+ hadPublishedVersion: hadPubRel,
6273
+ isDraftAndPublish: isDraftAndPublishRel,
6262
6274
  message: `Successfully updated relation "${attribute}"`
6263
6275
  };
6264
6276
  }
@@ -6286,7 +6298,7 @@ async function executeBatchInternal(strapi, {
6286
6298
  }
6287
6299
  }
6288
6300
  const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
6289
- const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
6301
+ const { hadPublishedVersion: hadPubScalar, status: preStatusScalar } = resolveRecordPublicationStatus(
6290
6302
  inspectionTargetScalar,
6291
6303
  pubRecordScalar,
6292
6304
  isDraftAndPublishScalar
@@ -6350,11 +6362,15 @@ async function executeBatchInternal(strapi, {
6350
6362
  uid: target.uid,
6351
6363
  collectionName: displayName,
6352
6364
  documentId: target.documentId,
6365
+ locale: candLocaleScalar,
6353
6366
  label: entryLabel,
6354
6367
  attribute,
6355
6368
  oldValue: currentVal ?? null,
6356
6369
  newValue,
6357
6370
  status: "updated",
6371
+ previousStatus: preStatusScalar,
6372
+ hadPublishedVersion: hadPubScalar,
6373
+ isDraftAndPublish: isDraftAndPublishScalar,
6358
6374
  message: `Successfully updated ${attribute}`
6359
6375
  };
6360
6376
  } else {
@@ -6423,11 +6439,15 @@ async function executeBatchInternal(strapi, {
6423
6439
  uid: r.uid,
6424
6440
  collectionName: r.collectionName,
6425
6441
  documentId: r.documentId,
6442
+ locale: r.locale,
6426
6443
  label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
6427
6444
  attribute: dz.attribute,
6428
6445
  oldValue: dz.oldValue,
6429
6446
  newValue: dz.newValue,
6430
6447
  status: "updated",
6448
+ previousStatus: r.previousStatus,
6449
+ hadPublishedVersion: r.hadPublishedVersion,
6450
+ isDraftAndPublish: r.isDraftAndPublish,
6431
6451
  message: `Updated ${dz.attribute}`
6432
6452
  });
6433
6453
  }
@@ -9050,21 +9070,20 @@ const auditService = ({ strapi }) => ({
9050
9070
  const isDynamicZone = rootAttrDef?.type === "dynamiczone";
9051
9071
  const isNested = item.attribute.includes(".") || item.attribute.includes("[") || isComponent || isDynamicZone || isDeepComponentField(ct, strapi.components, item.attribute);
9052
9072
  const isLocalized = Boolean(ct?.pluginOptions?.i18n?.localized) && item.locale && item.locale !== "null" && item.locale !== "undefined";
9053
- let wasPublished = false;
9073
+ const isDraftAndPublish = Boolean(ct?.options?.draftAndPublish ?? item.isDraftAndPublish);
9074
+ const populateOption = isNested ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
9075
+ const findOneArgs = { documentId: item.documentId };
9076
+ if (populateOption) {
9077
+ findOneArgs.populate = populateOption;
9078
+ }
9079
+ if (isLocalized) {
9080
+ findOneArgs.locale = item.locale;
9081
+ }
9082
+ const currentDoc = await strapi.documents(item.uid).findOne(findOneArgs);
9083
+ if (!currentDoc) {
9084
+ throw new Error(`Document "${item.documentId}" not found in collection "${item.uid}".`);
9085
+ }
9054
9086
  if (isNested && (isComponent || isDynamicZone || rootAttrDef)) {
9055
- const populateOption = buildDeepPopulate(ct.attributes, strapi.components);
9056
- const findOneArgs = { documentId: item.documentId };
9057
- if (populateOption) {
9058
- findOneArgs.populate = populateOption;
9059
- }
9060
- if (isLocalized) {
9061
- findOneArgs.locale = item.locale;
9062
- }
9063
- const currentDoc = await strapi.documents(item.uid).findOne(findOneArgs);
9064
- if (!currentDoc) {
9065
- throw new Error(`Document "${item.documentId}" not found in collection "${item.uid}".`);
9066
- }
9067
- wasPublished = Boolean(currentDoc?.publishedAt);
9068
9087
  const isRootDz = isDynamicZone;
9069
9088
  const existingRoot = currentDoc?.[rootKey] || (isRootDz ? [] : {});
9070
9089
  let restoredRoot;
@@ -9130,11 +9149,6 @@ const auditService = ({ strapi }) => ({
9130
9149
  }
9131
9150
  });
9132
9151
  } else {
9133
- const currentDoc = await strapi.documents(item.uid).findOne({
9134
- documentId: item.documentId,
9135
- ...isLocalized ? { locale: item.locale } : {}
9136
- });
9137
- wasPublished = Boolean(currentDoc?.publishedAt);
9138
9152
  await strapi.documents(item.uid).update({
9139
9153
  documentId: item.documentId,
9140
9154
  ...isLocalized ? { locale: item.locale } : {},
@@ -9143,14 +9157,85 @@ const auditService = ({ strapi }) => ({
9143
9157
  }
9144
9158
  });
9145
9159
  }
9146
- if (ct?.options?.draftAndPublish && wasPublished) {
9160
+ let targetStatus = void 0;
9161
+ if (item.previousStatus === "published" || item.previousStatus === "modified" || item.previousStatus === "draft") {
9162
+ targetStatus = item.previousStatus;
9163
+ } else if (item.hadPublishedVersion === false) {
9164
+ targetStatus = "draft";
9165
+ } else if (item.hadPublishedVersion === true) {
9166
+ targetStatus = "published";
9167
+ }
9168
+ if (isDraftAndPublish && !targetStatus) {
9169
+ let publishedCounterpart = null;
9147
9170
  try {
9148
- await strapi.documents(item.uid).publish({
9149
- documentId: item.documentId,
9150
- ...isLocalized ? { locale: item.locale } : {}
9151
- });
9152
- } catch (publishErr) {
9153
- strapi.log.warn(`[bulk-updater] Failed to auto-publish rollback for ${item.uid}/${item.documentId}:`, publishErr?.message);
9171
+ const docSvc = strapi.documents(item.uid);
9172
+ if (typeof docSvc.findMany === "function") {
9173
+ const pubs = await docSvc.findMany({
9174
+ status: "published",
9175
+ filters: { documentId: item.documentId },
9176
+ fields: ["documentId", "publishedAt"],
9177
+ limit: 1,
9178
+ ...isLocalized ? { locale: item.locale } : {}
9179
+ });
9180
+ if (pubs && pubs.length > 0) {
9181
+ publishedCounterpart = pubs[0];
9182
+ }
9183
+ }
9184
+ } catch {
9185
+ }
9186
+ if (publishedCounterpart?.publishedAt || currentDoc?.publishedAt) {
9187
+ targetStatus = "published";
9188
+ } else {
9189
+ targetStatus = "draft";
9190
+ }
9191
+ }
9192
+ if (isDraftAndPublish) {
9193
+ const docSvc = strapi.documents(item.uid);
9194
+ if (targetStatus === "published") {
9195
+ try {
9196
+ if (typeof docSvc.publish === "function") {
9197
+ await docSvc.publish({
9198
+ documentId: item.documentId,
9199
+ ...isLocalized ? { locale: item.locale } : {}
9200
+ });
9201
+ }
9202
+ } catch (publishErr) {
9203
+ strapi.log.warn(
9204
+ `[bulk-updater] Failed to auto-publish rollback for ${item.uid}/${item.documentId}:`,
9205
+ publishErr?.message
9206
+ );
9207
+ }
9208
+ } else if (targetStatus === "draft") {
9209
+ try {
9210
+ if (typeof docSvc.unpublish === "function") {
9211
+ let hasPublished = false;
9212
+ if (typeof docSvc.findMany === "function") {
9213
+ const pubs = await docSvc.findMany({
9214
+ status: "published",
9215
+ filters: { documentId: item.documentId },
9216
+ fields: ["documentId", "publishedAt"],
9217
+ limit: 1,
9218
+ ...isLocalized ? { locale: item.locale } : {}
9219
+ });
9220
+ if (pubs && pubs.length > 0) {
9221
+ hasPublished = true;
9222
+ }
9223
+ } else if (currentDoc?.publishedAt) {
9224
+ hasPublished = true;
9225
+ }
9226
+ if (hasPublished) {
9227
+ await docSvc.unpublish({
9228
+ documentId: item.documentId,
9229
+ ...isLocalized ? { locale: item.locale } : {}
9230
+ });
9231
+ }
9232
+ }
9233
+ } catch (unpubErr) {
9234
+ strapi.log.warn(
9235
+ `[bulk-updater] Failed to unpublish rollback for ${item.uid}/${item.documentId}:`,
9236
+ unpubErr?.message
9237
+ );
9238
+ }
9154
9239
  }
9155
9240
  }
9156
9241
  try {
@@ -9158,7 +9243,7 @@ const auditService = ({ strapi }) => ({
9158
9243
  uid: item.uid,
9159
9244
  documentId: item.documentId,
9160
9245
  userId,
9161
- statusOverride: ct?.options?.draftAndPublish ? wasPublished ? "published" : "draft" : void 0
9246
+ statusOverride: isDraftAndPublish ? targetStatus : "published"
9162
9247
  });
9163
9248
  } catch {
9164
9249
  }
@@ -9176,7 +9261,8 @@ const auditService = ({ strapi }) => ({
9176
9261
  label: item.label,
9177
9262
  attribute: item.attribute,
9178
9263
  revertedTo: item.oldValue,
9179
- status: "reverted"
9264
+ status: "reverted",
9265
+ restoredLifecycleStatus: isDraftAndPublish ? targetStatus : "published"
9180
9266
  });
9181
9267
  } catch (err) {
9182
9268
  rollbackDetails.push({
@@ -10123,7 +10209,7 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
10123
10209
  ...rowStatus ? { status: rowStatus } : {},
10124
10210
  ...rowPubAt ? { publishedAt: rowPubAt } : {}
10125
10211
  } : existing;
10126
- const { hadPublishedVersion } = resolveRecordPublicationStatus(
10212
+ const { hadPublishedVersion, status: preStatus } = resolveRecordPublicationStatus(
10127
10213
  inspectionExisting,
10128
10214
  pubRecord,
10129
10215
  isDraftAndPublish
@@ -10210,11 +10296,15 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
10210
10296
  uid,
10211
10297
  collectionName: ct.info?.displayName || uid,
10212
10298
  documentId: resolvedDocId,
10299
+ locale: effectiveLocale,
10213
10300
  label: existing.title || existing.name || `Entry #${resolvedDocId}`,
10214
10301
  attribute: attrKey,
10215
10302
  oldValue: oldVal,
10216
10303
  newValue: newVal,
10217
10304
  status: "updated",
10305
+ previousStatus: preStatus,
10306
+ hadPublishedVersion,
10307
+ isDraftAndPublish,
10218
10308
  message: `${actionLabel} "${attrKey}" via CSV import (row ${rowNumber})`
10219
10309
  });
10220
10310
  }