strapi-plugin-bulk-updater 1.5.2 → 1.5.4
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/_chunks/{BulkUpdater-BiSkkAHF.mjs → BulkUpdater-7YA96VJT.mjs} +118 -68
- package/dist/_chunks/BulkUpdater-7YA96VJT.mjs.map +1 -0
- package/dist/_chunks/{BulkUpdater-JZW74XM4.js → BulkUpdater-BTWJq8UX.js} +118 -68
- package/dist/_chunks/BulkUpdater-BTWJq8UX.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +133 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +133 -5
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/_chunks/BulkUpdater-BiSkkAHF.mjs.map +0 -1
- package/dist/_chunks/BulkUpdater-JZW74XM4.js.map +0 -1
package/dist/admin/index.js
CHANGED
|
@@ -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-
|
|
71
|
+
Component: () => Promise.resolve().then(() => require("../_chunks/BulkUpdater-BTWJq8UX.js")),
|
|
72
72
|
permissions: [],
|
|
73
73
|
position: 3
|
|
74
74
|
});
|
package/dist/admin/index.mjs
CHANGED
|
@@ -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-
|
|
68
|
+
Component: () => import("../_chunks/BulkUpdater-7YA96VJT.mjs"),
|
|
69
69
|
permissions: [],
|
|
70
70
|
position: 3
|
|
71
71
|
});
|
package/dist/server/index.js
CHANGED
|
@@ -365,10 +365,10 @@ const bulkUpdaterController = ({ strapi }) => ({
|
|
|
365
365
|
ctx.set("ETag", data.etag);
|
|
366
366
|
ctx.set("Cache-Control", "private, no-cache");
|
|
367
367
|
}
|
|
368
|
-
ctx.body = { success: true, ...data };
|
|
368
|
+
ctx.body = { success: true, status: "success", ...data };
|
|
369
369
|
} catch (err) {
|
|
370
370
|
ctx.status = 500;
|
|
371
|
-
ctx.body = { success: false, error: err.message };
|
|
371
|
+
ctx.body = { success: false, status: "error", error: err.message };
|
|
372
372
|
}
|
|
373
373
|
},
|
|
374
374
|
async getRelationOptions(ctx) {
|
|
@@ -970,6 +970,7 @@ function formatEntryRecord(entry) {
|
|
|
970
970
|
const formatted = {
|
|
971
971
|
id: entry.id,
|
|
972
972
|
documentId: entry.documentId,
|
|
973
|
+
status: entry.status !== void 0 ? entry.status : void 0,
|
|
973
974
|
...entry
|
|
974
975
|
};
|
|
975
976
|
if (entry.updatedAt !== void 0 && formatted.updated_at === void 0) {
|
|
@@ -992,6 +993,119 @@ function formatEntryRecord(entry) {
|
|
|
992
993
|
}
|
|
993
994
|
return formatted;
|
|
994
995
|
}
|
|
996
|
+
async function populateDocumentLifecycleStatus(strapi, uid, entries) {
|
|
997
|
+
if (!entries || !Array.isArray(entries) || entries.length === 0) {
|
|
998
|
+
return entries;
|
|
999
|
+
}
|
|
1000
|
+
const contentType = strapi?.contentTypes?.[uid];
|
|
1001
|
+
if (!contentType) {
|
|
1002
|
+
return entries;
|
|
1003
|
+
}
|
|
1004
|
+
const hasDraftAndPublish = Boolean(contentType.options?.draftAndPublish);
|
|
1005
|
+
if (!hasDraftAndPublish) {
|
|
1006
|
+
for (const entry of entries) {
|
|
1007
|
+
if (entry && typeof entry === "object") {
|
|
1008
|
+
entry.status = "published";
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return entries;
|
|
1012
|
+
}
|
|
1013
|
+
const hasSlugInSchema = Boolean(contentType.attributes?.slug);
|
|
1014
|
+
const docIds = [];
|
|
1015
|
+
const slugs = [];
|
|
1016
|
+
for (const entry of entries) {
|
|
1017
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1018
|
+
if (entry.documentId) {
|
|
1019
|
+
docIds.push(String(entry.documentId));
|
|
1020
|
+
} else if (hasSlugInSchema && entry.slug) {
|
|
1021
|
+
slugs.push(String(entry.slug));
|
|
1022
|
+
} else {
|
|
1023
|
+
entry.status = "unknown";
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
if (docIds.length === 0 && slugs.length === 0) {
|
|
1027
|
+
return entries;
|
|
1028
|
+
}
|
|
1029
|
+
let filterClause;
|
|
1030
|
+
if (docIds.length > 0 && slugs.length > 0) {
|
|
1031
|
+
filterClause = {
|
|
1032
|
+
$or: [
|
|
1033
|
+
{ documentId: { $in: docIds } },
|
|
1034
|
+
{ slug: { $in: slugs } }
|
|
1035
|
+
]
|
|
1036
|
+
};
|
|
1037
|
+
} else if (docIds.length > 0) {
|
|
1038
|
+
filterClause = { documentId: { $in: docIds } };
|
|
1039
|
+
} else {
|
|
1040
|
+
filterClause = { slug: { $in: slugs } };
|
|
1041
|
+
}
|
|
1042
|
+
const queryFields = ["documentId", "updatedAt", "publishedAt"];
|
|
1043
|
+
if (hasSlugInSchema) {
|
|
1044
|
+
queryFields.push("slug");
|
|
1045
|
+
}
|
|
1046
|
+
let publishedRecords = [];
|
|
1047
|
+
try {
|
|
1048
|
+
const docService = strapi?.documents?.(uid);
|
|
1049
|
+
if (docService?.findMany) {
|
|
1050
|
+
publishedRecords = await docService.findMany({
|
|
1051
|
+
status: "published",
|
|
1052
|
+
filters: filterClause,
|
|
1053
|
+
fields: queryFields,
|
|
1054
|
+
limit: Math.max(entries.length, 100)
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
} catch (err) {
|
|
1058
|
+
strapi?.log?.warn?.(`[bulk-updater] Failed to fetch published status for ${uid}: ${err?.message || err}`);
|
|
1059
|
+
for (const entry of entries) {
|
|
1060
|
+
if (entry && typeof entry === "object" && entry.status !== "unknown") {
|
|
1061
|
+
entry.status = "unknown";
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return entries;
|
|
1065
|
+
}
|
|
1066
|
+
const publishedByDocId = /* @__PURE__ */ new Map();
|
|
1067
|
+
const publishedBySlug = /* @__PURE__ */ new Map();
|
|
1068
|
+
for (const pub of publishedRecords || []) {
|
|
1069
|
+
if (pub?.documentId) {
|
|
1070
|
+
publishedByDocId.set(String(pub.documentId), pub);
|
|
1071
|
+
}
|
|
1072
|
+
if (pub?.slug && hasSlugInSchema) {
|
|
1073
|
+
publishedBySlug.set(String(pub.slug), pub);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
for (const entry of entries) {
|
|
1077
|
+
if (!entry || typeof entry !== "object") continue;
|
|
1078
|
+
if (entry.status === "unknown") continue;
|
|
1079
|
+
const pub = entry.documentId && publishedByDocId.get(String(entry.documentId)) || hasSlugInSchema && entry.slug && publishedBySlug.get(String(entry.slug));
|
|
1080
|
+
if (!pub) {
|
|
1081
|
+
entry.status = "draft";
|
|
1082
|
+
entry.publishedAt = null;
|
|
1083
|
+
entry.published_at = null;
|
|
1084
|
+
} else {
|
|
1085
|
+
entry.publishedAt = pub.publishedAt || pub.published_at || null;
|
|
1086
|
+
entry.published_at = entry.publishedAt;
|
|
1087
|
+
const draftUpdatedTime = new Date(entry.updatedAt || entry.updated_at || 0).getTime();
|
|
1088
|
+
const pubUpdatedTime = new Date(pub.updatedAt || pub.updated_at || 0).getTime();
|
|
1089
|
+
const pubPublishedTime = new Date(pub.publishedAt || pub.published_at || 0).getTime();
|
|
1090
|
+
const lastPublishedTime = Math.max(
|
|
1091
|
+
isNaN(pubUpdatedTime) ? 0 : pubUpdatedTime,
|
|
1092
|
+
isNaN(pubPublishedTime) ? 0 : pubPublishedTime
|
|
1093
|
+
);
|
|
1094
|
+
if (isNaN(draftUpdatedTime) || lastPublishedTime === 0) {
|
|
1095
|
+
if (pub.publishedAt) {
|
|
1096
|
+
entry.status = "published";
|
|
1097
|
+
} else {
|
|
1098
|
+
entry.status = "unknown";
|
|
1099
|
+
}
|
|
1100
|
+
} else if (draftUpdatedTime > lastPublishedTime) {
|
|
1101
|
+
entry.status = "modified";
|
|
1102
|
+
} else {
|
|
1103
|
+
entry.status = "published";
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return entries;
|
|
1108
|
+
}
|
|
995
1109
|
function resolveContentTypeField(contentType, field) {
|
|
996
1110
|
if (!field) return null;
|
|
997
1111
|
const attrs = contentType?.attributes || {};
|
|
@@ -2056,6 +2170,9 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2056
2170
|
isRunnerRunning = false;
|
|
2057
2171
|
}
|
|
2058
2172
|
}, 3e4);
|
|
2173
|
+
if (typeof runnerInterval.unref === "function") {
|
|
2174
|
+
runnerInterval.unref();
|
|
2175
|
+
}
|
|
2059
2176
|
}
|
|
2060
2177
|
return {
|
|
2061
2178
|
/**
|
|
@@ -2258,6 +2375,7 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2258
2375
|
totalCount = 0;
|
|
2259
2376
|
}
|
|
2260
2377
|
const formattedEntries = (entries || []).map(formatEntryRecord);
|
|
2378
|
+
await populateDocumentLifecycleStatus(strapi, uid, formattedEntries);
|
|
2261
2379
|
modelsCache.set(uid, {
|
|
2262
2380
|
signature,
|
|
2263
2381
|
totalCount,
|
|
@@ -2373,6 +2491,7 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2373
2491
|
if (!colHasAttribute) {
|
|
2374
2492
|
result = {
|
|
2375
2493
|
uid,
|
|
2494
|
+
status: "success",
|
|
2376
2495
|
displayName: contentType.info?.displayName || uid,
|
|
2377
2496
|
isSingleType,
|
|
2378
2497
|
draftAndPublish: Boolean(contentType.options?.draftAndPublish),
|
|
@@ -2514,12 +2633,15 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2514
2633
|
} catch {
|
|
2515
2634
|
singleDoc = null;
|
|
2516
2635
|
}
|
|
2636
|
+
const formattedEntries = singleDoc ? [formatEntryRecord(singleDoc)] : [];
|
|
2637
|
+
await populateDocumentLifecycleStatus(strapi, uid, formattedEntries);
|
|
2517
2638
|
result = {
|
|
2518
2639
|
uid,
|
|
2640
|
+
status: "success",
|
|
2519
2641
|
displayName: contentType.info?.displayName || uid,
|
|
2520
2642
|
isSingleType: true,
|
|
2521
2643
|
draftAndPublish: Boolean(contentType.options?.draftAndPublish),
|
|
2522
|
-
entries:
|
|
2644
|
+
entries: formattedEntries,
|
|
2523
2645
|
pagination: {
|
|
2524
2646
|
page: 1,
|
|
2525
2647
|
pageSize: 1,
|
|
@@ -2606,12 +2728,15 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2606
2728
|
const matchedEntries = (rawEntries || []).filter(passesDzFilter);
|
|
2607
2729
|
const totalEntries = matchedEntries.length;
|
|
2608
2730
|
const paginatedEntries = matchedEntries.slice(start, start + limit);
|
|
2731
|
+
const formattedEntries = paginatedEntries.map(formatEntryRecord);
|
|
2732
|
+
await populateDocumentLifecycleStatus(strapi, uid, formattedEntries);
|
|
2609
2733
|
result = {
|
|
2610
2734
|
uid,
|
|
2735
|
+
status: "success",
|
|
2611
2736
|
displayName: contentType.info?.displayName || uid,
|
|
2612
2737
|
isSingleType: false,
|
|
2613
2738
|
draftAndPublish: Boolean(contentType.options?.draftAndPublish),
|
|
2614
|
-
entries:
|
|
2739
|
+
entries: formattedEntries,
|
|
2615
2740
|
pagination: {
|
|
2616
2741
|
page: currentPage,
|
|
2617
2742
|
pageSize: limit,
|
|
@@ -2635,12 +2760,15 @@ const bulkUpdaterService = ({ strapi }) => {
|
|
|
2635
2760
|
filters: Object.keys(filters).length > 0 ? filters : void 0
|
|
2636
2761
|
})
|
|
2637
2762
|
]);
|
|
2763
|
+
const formattedEntries = (entries || []).map(formatEntryRecord);
|
|
2764
|
+
await populateDocumentLifecycleStatus(strapi, uid, formattedEntries);
|
|
2638
2765
|
result = {
|
|
2639
2766
|
uid,
|
|
2767
|
+
status: "success",
|
|
2640
2768
|
displayName: contentType.info?.displayName || uid,
|
|
2641
2769
|
isSingleType: false,
|
|
2642
2770
|
draftAndPublish: Boolean(contentType.options?.draftAndPublish),
|
|
2643
|
-
entries:
|
|
2771
|
+
entries: formattedEntries,
|
|
2644
2772
|
pagination: {
|
|
2645
2773
|
page: currentPage,
|
|
2646
2774
|
pageSize: limit,
|