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.
- package/dist/server/index.js +123 -33
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +123 -33
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -5634,7 +5634,7 @@ async function resolveAndMaybePublishTarget({
|
|
|
5634
5634
|
}
|
|
5635
5635
|
}
|
|
5636
5636
|
const inspectionTarget = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
5637
|
-
const { hadPublishedVersion } = resolveRecordPublicationStatus(inspectionTarget, pubRecord, isDraftAndPublish);
|
|
5637
|
+
const { hadPublishedVersion, status: preStatus } = resolveRecordPublicationStatus(inspectionTarget, pubRecord, isDraftAndPublish);
|
|
5638
5638
|
const isEditing = isRowInEditingStage$1(inspectionTarget) || isRowInEditingStage$1(target);
|
|
5639
5639
|
const shouldPublish = evaluateShouldPublish({
|
|
5640
5640
|
isDraftAndPublish,
|
|
@@ -5648,6 +5648,7 @@ async function resolveAndMaybePublishTarget({
|
|
|
5648
5648
|
candLocale: isLocalized ? candLocale : void 0,
|
|
5649
5649
|
isDraftAndPublish,
|
|
5650
5650
|
hadPublishedVersion,
|
|
5651
|
+
previousStatus: preStatus,
|
|
5651
5652
|
shouldPublish,
|
|
5652
5653
|
async postUpdate(relatedTargetUid) {
|
|
5653
5654
|
if (shouldPublish) {
|
|
@@ -5811,6 +5812,9 @@ async function executeGridTargetUpdate({
|
|
|
5811
5812
|
oldValue: oldSummaryVal,
|
|
5812
5813
|
newValue: newSummaryVal,
|
|
5813
5814
|
status: "updated",
|
|
5815
|
+
previousStatus: lifecycle.previousStatus,
|
|
5816
|
+
hadPublishedVersion: lifecycle.hadPublishedVersion,
|
|
5817
|
+
isDraftAndPublish: lifecycle.isDraftAndPublish,
|
|
5814
5818
|
message: isMultiOcc ? `Successfully updated ${changedDiffs.length} grid occurrence(s) in ${attribute}` : `Successfully updated ${attribute}`,
|
|
5815
5819
|
dynamicZoneDiffs: isComponentNested ? changedDiffs : void 0,
|
|
5816
5820
|
gridGroupDiffs: changedDiffs.length > 1 || isComponentNested ? changedDiffs : void 0
|
|
@@ -6028,7 +6032,7 @@ async function executeBatchInternal(strapi, {
|
|
|
6028
6032
|
}
|
|
6029
6033
|
}
|
|
6030
6034
|
const inspectionTargetComp = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6031
|
-
const { hadPublishedVersion: hadPubComp } = resolveRecordPublicationStatus(
|
|
6035
|
+
const { hadPublishedVersion: hadPubComp, status: preStatusComp } = resolveRecordPublicationStatus(
|
|
6032
6036
|
inspectionTargetComp,
|
|
6033
6037
|
pubRecordComp,
|
|
6034
6038
|
isDraftAndPublishComp
|
|
@@ -6101,11 +6105,15 @@ async function executeBatchInternal(strapi, {
|
|
|
6101
6105
|
uid: target.uid,
|
|
6102
6106
|
collectionName: displayName,
|
|
6103
6107
|
documentId: target.documentId,
|
|
6108
|
+
locale: candLocaleComp,
|
|
6104
6109
|
label: entryLabel,
|
|
6105
6110
|
attribute,
|
|
6106
6111
|
oldValue: currentVal2 ?? null,
|
|
6107
6112
|
newValue: newValue2,
|
|
6108
6113
|
status: "updated",
|
|
6114
|
+
previousStatus: preStatusComp,
|
|
6115
|
+
hadPublishedVersion: hadPubComp,
|
|
6116
|
+
isDraftAndPublish: isDraftAndPublishComp,
|
|
6109
6117
|
message: isRootDz ? `Successfully updated ${affectedMatches.length} dynamic zone item(s) in ${attribute}` : `Successfully updated nested field ${attribute}`,
|
|
6110
6118
|
dynamicZoneDiffs: dzDiffs
|
|
6111
6119
|
};
|
|
@@ -6182,7 +6190,7 @@ async function executeBatchInternal(strapi, {
|
|
|
6182
6190
|
}
|
|
6183
6191
|
}
|
|
6184
6192
|
const inspectionTargetRel = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6185
|
-
const { hadPublishedVersion: hadPubRel } = resolveRecordPublicationStatus(
|
|
6193
|
+
const { hadPublishedVersion: hadPubRel, status: preStatusRel } = resolveRecordPublicationStatus(
|
|
6186
6194
|
inspectionTargetRel,
|
|
6187
6195
|
pubRecordRel,
|
|
6188
6196
|
isDraftAndPublishRel
|
|
@@ -6250,11 +6258,15 @@ async function executeBatchInternal(strapi, {
|
|
|
6250
6258
|
uid: target.uid,
|
|
6251
6259
|
collectionName: displayName,
|
|
6252
6260
|
documentId: target.documentId,
|
|
6261
|
+
locale: candLocaleRel,
|
|
6253
6262
|
label: entryLabel,
|
|
6254
6263
|
attribute,
|
|
6255
6264
|
oldValue: { isRelation: true, documentIds: oldDocIds, display: oldDisplay },
|
|
6256
6265
|
newValue: { isRelation: true, mode, documentIds: targetDocIds, display: newDisplay },
|
|
6257
6266
|
status: "updated",
|
|
6267
|
+
previousStatus: preStatusRel,
|
|
6268
|
+
hadPublishedVersion: hadPubRel,
|
|
6269
|
+
isDraftAndPublish: isDraftAndPublishRel,
|
|
6258
6270
|
message: `Successfully updated relation "${attribute}"`
|
|
6259
6271
|
};
|
|
6260
6272
|
}
|
|
@@ -6282,7 +6294,7 @@ async function executeBatchInternal(strapi, {
|
|
|
6282
6294
|
}
|
|
6283
6295
|
}
|
|
6284
6296
|
const inspectionTargetScalar = target.status || target.publishedAt ? { ...currentEntry, status: target.status, publishedAt: target.publishedAt } : currentEntry;
|
|
6285
|
-
const { hadPublishedVersion: hadPubScalar } = resolveRecordPublicationStatus(
|
|
6297
|
+
const { hadPublishedVersion: hadPubScalar, status: preStatusScalar } = resolveRecordPublicationStatus(
|
|
6286
6298
|
inspectionTargetScalar,
|
|
6287
6299
|
pubRecordScalar,
|
|
6288
6300
|
isDraftAndPublishScalar
|
|
@@ -6346,11 +6358,15 @@ async function executeBatchInternal(strapi, {
|
|
|
6346
6358
|
uid: target.uid,
|
|
6347
6359
|
collectionName: displayName,
|
|
6348
6360
|
documentId: target.documentId,
|
|
6361
|
+
locale: candLocaleScalar,
|
|
6349
6362
|
label: entryLabel,
|
|
6350
6363
|
attribute,
|
|
6351
6364
|
oldValue: currentVal ?? null,
|
|
6352
6365
|
newValue,
|
|
6353
6366
|
status: "updated",
|
|
6367
|
+
previousStatus: preStatusScalar,
|
|
6368
|
+
hadPublishedVersion: hadPubScalar,
|
|
6369
|
+
isDraftAndPublish: isDraftAndPublishScalar,
|
|
6354
6370
|
message: `Successfully updated ${attribute}`
|
|
6355
6371
|
};
|
|
6356
6372
|
} else {
|
|
@@ -6419,11 +6435,15 @@ async function executeBatchInternal(strapi, {
|
|
|
6419
6435
|
uid: r.uid,
|
|
6420
6436
|
collectionName: r.collectionName,
|
|
6421
6437
|
documentId: r.documentId,
|
|
6438
|
+
locale: r.locale,
|
|
6422
6439
|
label: `${r.label} [Block #${dz.index} (${dz.componentName})]`,
|
|
6423
6440
|
attribute: dz.attribute,
|
|
6424
6441
|
oldValue: dz.oldValue,
|
|
6425
6442
|
newValue: dz.newValue,
|
|
6426
6443
|
status: "updated",
|
|
6444
|
+
previousStatus: r.previousStatus,
|
|
6445
|
+
hadPublishedVersion: r.hadPublishedVersion,
|
|
6446
|
+
isDraftAndPublish: r.isDraftAndPublish,
|
|
6427
6447
|
message: `Updated ${dz.attribute}`
|
|
6428
6448
|
});
|
|
6429
6449
|
}
|
|
@@ -9046,21 +9066,20 @@ const auditService = ({ strapi }) => ({
|
|
|
9046
9066
|
const isDynamicZone = rootAttrDef?.type === "dynamiczone";
|
|
9047
9067
|
const isNested = item.attribute.includes(".") || item.attribute.includes("[") || isComponent || isDynamicZone || isDeepComponentField(ct, strapi.components, item.attribute);
|
|
9048
9068
|
const isLocalized = Boolean(ct?.pluginOptions?.i18n?.localized) && item.locale && item.locale !== "null" && item.locale !== "undefined";
|
|
9049
|
-
|
|
9069
|
+
const isDraftAndPublish = Boolean(ct?.options?.draftAndPublish ?? item.isDraftAndPublish);
|
|
9070
|
+
const populateOption = isNested ? buildDeepPopulate(ct.attributes, strapi.components) : void 0;
|
|
9071
|
+
const findOneArgs = { documentId: item.documentId };
|
|
9072
|
+
if (populateOption) {
|
|
9073
|
+
findOneArgs.populate = populateOption;
|
|
9074
|
+
}
|
|
9075
|
+
if (isLocalized) {
|
|
9076
|
+
findOneArgs.locale = item.locale;
|
|
9077
|
+
}
|
|
9078
|
+
const currentDoc = await strapi.documents(item.uid).findOne(findOneArgs);
|
|
9079
|
+
if (!currentDoc) {
|
|
9080
|
+
throw new Error(`Document "${item.documentId}" not found in collection "${item.uid}".`);
|
|
9081
|
+
}
|
|
9050
9082
|
if (isNested && (isComponent || isDynamicZone || rootAttrDef)) {
|
|
9051
|
-
const populateOption = buildDeepPopulate(ct.attributes, strapi.components);
|
|
9052
|
-
const findOneArgs = { documentId: item.documentId };
|
|
9053
|
-
if (populateOption) {
|
|
9054
|
-
findOneArgs.populate = populateOption;
|
|
9055
|
-
}
|
|
9056
|
-
if (isLocalized) {
|
|
9057
|
-
findOneArgs.locale = item.locale;
|
|
9058
|
-
}
|
|
9059
|
-
const currentDoc = await strapi.documents(item.uid).findOne(findOneArgs);
|
|
9060
|
-
if (!currentDoc) {
|
|
9061
|
-
throw new Error(`Document "${item.documentId}" not found in collection "${item.uid}".`);
|
|
9062
|
-
}
|
|
9063
|
-
wasPublished = Boolean(currentDoc?.publishedAt);
|
|
9064
9083
|
const isRootDz = isDynamicZone;
|
|
9065
9084
|
const existingRoot = currentDoc?.[rootKey] || (isRootDz ? [] : {});
|
|
9066
9085
|
let restoredRoot;
|
|
@@ -9126,11 +9145,6 @@ const auditService = ({ strapi }) => ({
|
|
|
9126
9145
|
}
|
|
9127
9146
|
});
|
|
9128
9147
|
} else {
|
|
9129
|
-
const currentDoc = await strapi.documents(item.uid).findOne({
|
|
9130
|
-
documentId: item.documentId,
|
|
9131
|
-
...isLocalized ? { locale: item.locale } : {}
|
|
9132
|
-
});
|
|
9133
|
-
wasPublished = Boolean(currentDoc?.publishedAt);
|
|
9134
9148
|
await strapi.documents(item.uid).update({
|
|
9135
9149
|
documentId: item.documentId,
|
|
9136
9150
|
...isLocalized ? { locale: item.locale } : {},
|
|
@@ -9139,14 +9153,85 @@ const auditService = ({ strapi }) => ({
|
|
|
9139
9153
|
}
|
|
9140
9154
|
});
|
|
9141
9155
|
}
|
|
9142
|
-
|
|
9156
|
+
let targetStatus = void 0;
|
|
9157
|
+
if (item.previousStatus === "published" || item.previousStatus === "modified" || item.previousStatus === "draft") {
|
|
9158
|
+
targetStatus = item.previousStatus;
|
|
9159
|
+
} else if (item.hadPublishedVersion === false) {
|
|
9160
|
+
targetStatus = "draft";
|
|
9161
|
+
} else if (item.hadPublishedVersion === true) {
|
|
9162
|
+
targetStatus = "published";
|
|
9163
|
+
}
|
|
9164
|
+
if (isDraftAndPublish && !targetStatus) {
|
|
9165
|
+
let publishedCounterpart = null;
|
|
9143
9166
|
try {
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9167
|
+
const docSvc = strapi.documents(item.uid);
|
|
9168
|
+
if (typeof docSvc.findMany === "function") {
|
|
9169
|
+
const pubs = await docSvc.findMany({
|
|
9170
|
+
status: "published",
|
|
9171
|
+
filters: { documentId: item.documentId },
|
|
9172
|
+
fields: ["documentId", "publishedAt"],
|
|
9173
|
+
limit: 1,
|
|
9174
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9175
|
+
});
|
|
9176
|
+
if (pubs && pubs.length > 0) {
|
|
9177
|
+
publishedCounterpart = pubs[0];
|
|
9178
|
+
}
|
|
9179
|
+
}
|
|
9180
|
+
} catch {
|
|
9181
|
+
}
|
|
9182
|
+
if (publishedCounterpart?.publishedAt || currentDoc?.publishedAt) {
|
|
9183
|
+
targetStatus = "published";
|
|
9184
|
+
} else {
|
|
9185
|
+
targetStatus = "draft";
|
|
9186
|
+
}
|
|
9187
|
+
}
|
|
9188
|
+
if (isDraftAndPublish) {
|
|
9189
|
+
const docSvc = strapi.documents(item.uid);
|
|
9190
|
+
if (targetStatus === "published") {
|
|
9191
|
+
try {
|
|
9192
|
+
if (typeof docSvc.publish === "function") {
|
|
9193
|
+
await docSvc.publish({
|
|
9194
|
+
documentId: item.documentId,
|
|
9195
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9196
|
+
});
|
|
9197
|
+
}
|
|
9198
|
+
} catch (publishErr) {
|
|
9199
|
+
strapi.log.warn(
|
|
9200
|
+
`[bulk-updater] Failed to auto-publish rollback for ${item.uid}/${item.documentId}:`,
|
|
9201
|
+
publishErr?.message
|
|
9202
|
+
);
|
|
9203
|
+
}
|
|
9204
|
+
} else if (targetStatus === "draft") {
|
|
9205
|
+
try {
|
|
9206
|
+
if (typeof docSvc.unpublish === "function") {
|
|
9207
|
+
let hasPublished = false;
|
|
9208
|
+
if (typeof docSvc.findMany === "function") {
|
|
9209
|
+
const pubs = await docSvc.findMany({
|
|
9210
|
+
status: "published",
|
|
9211
|
+
filters: { documentId: item.documentId },
|
|
9212
|
+
fields: ["documentId", "publishedAt"],
|
|
9213
|
+
limit: 1,
|
|
9214
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9215
|
+
});
|
|
9216
|
+
if (pubs && pubs.length > 0) {
|
|
9217
|
+
hasPublished = true;
|
|
9218
|
+
}
|
|
9219
|
+
} else if (currentDoc?.publishedAt) {
|
|
9220
|
+
hasPublished = true;
|
|
9221
|
+
}
|
|
9222
|
+
if (hasPublished) {
|
|
9223
|
+
await docSvc.unpublish({
|
|
9224
|
+
documentId: item.documentId,
|
|
9225
|
+
...isLocalized ? { locale: item.locale } : {}
|
|
9226
|
+
});
|
|
9227
|
+
}
|
|
9228
|
+
}
|
|
9229
|
+
} catch (unpubErr) {
|
|
9230
|
+
strapi.log.warn(
|
|
9231
|
+
`[bulk-updater] Failed to unpublish rollback for ${item.uid}/${item.documentId}:`,
|
|
9232
|
+
unpubErr?.message
|
|
9233
|
+
);
|
|
9234
|
+
}
|
|
9150
9235
|
}
|
|
9151
9236
|
}
|
|
9152
9237
|
try {
|
|
@@ -9154,7 +9239,7 @@ const auditService = ({ strapi }) => ({
|
|
|
9154
9239
|
uid: item.uid,
|
|
9155
9240
|
documentId: item.documentId,
|
|
9156
9241
|
userId,
|
|
9157
|
-
statusOverride:
|
|
9242
|
+
statusOverride: isDraftAndPublish ? targetStatus : "published"
|
|
9158
9243
|
});
|
|
9159
9244
|
} catch {
|
|
9160
9245
|
}
|
|
@@ -9172,7 +9257,8 @@ const auditService = ({ strapi }) => ({
|
|
|
9172
9257
|
label: item.label,
|
|
9173
9258
|
attribute: item.attribute,
|
|
9174
9259
|
revertedTo: item.oldValue,
|
|
9175
|
-
status: "reverted"
|
|
9260
|
+
status: "reverted",
|
|
9261
|
+
restoredLifecycleStatus: isDraftAndPublish ? targetStatus : "published"
|
|
9176
9262
|
});
|
|
9177
9263
|
} catch (err) {
|
|
9178
9264
|
rollbackDetails.push({
|
|
@@ -10119,7 +10205,7 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
|
|
|
10119
10205
|
...rowStatus ? { status: rowStatus } : {},
|
|
10120
10206
|
...rowPubAt ? { publishedAt: rowPubAt } : {}
|
|
10121
10207
|
} : existing;
|
|
10122
|
-
const { hadPublishedVersion } = resolveRecordPublicationStatus(
|
|
10208
|
+
const { hadPublishedVersion, status: preStatus } = resolveRecordPublicationStatus(
|
|
10123
10209
|
inspectionExisting,
|
|
10124
10210
|
pubRecord,
|
|
10125
10211
|
isDraftAndPublish
|
|
@@ -10206,11 +10292,15 @@ async function executeUpdateMutation(strapi, ct, uid, existing, row, rowNumber,
|
|
|
10206
10292
|
uid,
|
|
10207
10293
|
collectionName: ct.info?.displayName || uid,
|
|
10208
10294
|
documentId: resolvedDocId,
|
|
10295
|
+
locale: effectiveLocale,
|
|
10209
10296
|
label: existing.title || existing.name || `Entry #${resolvedDocId}`,
|
|
10210
10297
|
attribute: attrKey,
|
|
10211
10298
|
oldValue: oldVal,
|
|
10212
10299
|
newValue: newVal,
|
|
10213
10300
|
status: "updated",
|
|
10301
|
+
previousStatus: preStatus,
|
|
10302
|
+
hadPublishedVersion,
|
|
10303
|
+
isDraftAndPublish,
|
|
10214
10304
|
message: `${actionLabel} "${attrKey}" via CSV import (row ${rowNumber})`
|
|
10215
10305
|
});
|
|
10216
10306
|
}
|