@strapi/content-releases 0.0.0-experimental.fb8e9fec2e10d6b55e3aee59c4eb76bb7a11432a → 0.0.0-experimental.fc1ac2acd58c8a5a858679956b6d102ac5ee4011
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/App-0Er6xxcq.mjs +1358 -0
- package/dist/_chunks/App-0Er6xxcq.mjs.map +1 -0
- package/dist/_chunks/App-C768ulk4.js +1381 -0
- package/dist/_chunks/App-C768ulk4.js.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs +51 -0
- package/dist/_chunks/PurchaseContentReleases-Clm0iACO.mjs.map +1 -0
- package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js +51 -0
- package/dist/_chunks/PurchaseContentReleases-YhAPgpG9.js.map +1 -0
- package/dist/_chunks/{en-MyLPoISH.mjs → en-WuuhP6Bn.mjs} +21 -6
- package/dist/_chunks/en-WuuhP6Bn.mjs.map +1 -0
- package/dist/_chunks/{en-gYDqKYFd.js → en-gcJJ5htG.js} +21 -6
- package/dist/_chunks/en-gcJJ5htG.js.map +1 -0
- package/dist/_chunks/{index-KJa1Rb5F.js → index-BLSMpbpZ.js} +164 -44
- package/dist/_chunks/index-BLSMpbpZ.js.map +1 -0
- package/dist/_chunks/{index-c4zRX_sg.mjs → index-fJx1up7m.mjs} +178 -58
- package/dist/_chunks/index-fJx1up7m.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/src/components/CMReleasesContainer.d.ts +1 -0
- package/dist/admin/src/components/RelativeTime.d.ts +28 -0
- package/dist/admin/src/components/ReleaseActionMenu.d.ts +26 -0
- package/dist/admin/src/components/ReleaseActionOptions.d.ts +9 -0
- package/dist/admin/src/components/ReleaseModal.d.ts +16 -0
- package/dist/admin/src/constants.d.ts +58 -0
- package/dist/admin/src/index.d.ts +3 -0
- package/dist/admin/src/pages/App.d.ts +1 -0
- package/dist/admin/src/pages/PurchaseContentReleases.d.ts +2 -0
- package/dist/admin/src/pages/ReleaseDetailsPage.d.ts +2 -0
- package/dist/admin/src/pages/ReleasesPage.d.ts +8 -0
- package/dist/admin/src/pages/tests/mockReleaseDetailsPageData.d.ts +181 -0
- package/dist/admin/src/pages/tests/mockReleasesPageData.d.ts +39 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/axios.d.ts +29 -0
- package/dist/admin/src/services/release.d.ts +369 -0
- package/dist/admin/src/store/hooks.d.ts +7 -0
- package/dist/admin/src/utils/time.d.ts +1 -0
- package/dist/server/index.js +889 -436
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +889 -436
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/constants.d.ts +12 -0
- package/dist/server/src/constants.d.ts.map +1 -0
- package/dist/server/src/content-types/index.d.ts +99 -0
- package/dist/server/src/content-types/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/index.d.ts +48 -0
- package/dist/server/src/content-types/release/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release/schema.d.ts +47 -0
- package/dist/server/src/content-types/release/schema.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/index.d.ts +50 -0
- package/dist/server/src/content-types/release-action/index.d.ts.map +1 -0
- package/dist/server/src/content-types/release-action/schema.d.ts +49 -0
- package/dist/server/src/content-types/release-action/schema.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +18 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/controllers/release-action.d.ts +9 -0
- package/dist/server/src/controllers/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/release.d.ts +11 -0
- package/dist/server/src/controllers/release.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release-action.d.ts +3 -0
- package/dist/server/src/controllers/validation/release-action.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/release.d.ts +2 -0
- package/dist/server/src/controllers/validation/release.d.ts.map +1 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/destroy.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +3838 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/migrations/index.d.ts +10 -0
- package/dist/server/src/migrations/index.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +35 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/routes/release-action.d.ts +18 -0
- package/dist/server/src/routes/release-action.d.ts.map +1 -0
- package/dist/server/src/routes/release.d.ts +18 -0
- package/dist/server/src/routes/release.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +3572 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/release.d.ts +1812 -0
- package/dist/server/src/services/release.d.ts.map +1 -0
- package/dist/server/src/services/scheduling.d.ts +18 -0
- package/dist/server/src/services/scheduling.d.ts.map +1 -0
- package/dist/server/src/services/validation.d.ts +14 -0
- package/dist/server/src/services/validation.d.ts.map +1 -0
- package/dist/server/src/utils/index.d.ts +18 -0
- package/dist/server/src/utils/index.d.ts.map +1 -0
- package/dist/shared/contracts/release-actions.d.ts +105 -0
- package/dist/shared/contracts/release-actions.d.ts.map +1 -0
- package/dist/shared/contracts/releases.d.ts +166 -0
- package/dist/shared/contracts/releases.d.ts.map +1 -0
- package/dist/shared/types.d.ts +24 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/validation-schemas.d.ts +2 -0
- package/dist/shared/validation-schemas.d.ts.map +1 -0
- package/package.json +19 -23
- package/dist/_chunks/App-L1jSxCiL.mjs +0 -1015
- package/dist/_chunks/App-L1jSxCiL.mjs.map +0 -1
- package/dist/_chunks/App-_20W9dYa.js +0 -1037
- package/dist/_chunks/App-_20W9dYa.js.map +0 -1
- package/dist/_chunks/en-MyLPoISH.mjs.map +0 -1
- package/dist/_chunks/en-gYDqKYFd.js.map +0 -1
- package/dist/_chunks/index-KJa1Rb5F.js.map +0 -1
- package/dist/_chunks/index-c4zRX_sg.mjs.map +0 -1
package/dist/server/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const utils = require("@strapi/utils");
|
|
3
|
+
const isEqual = require("lodash/isEqual");
|
|
3
4
|
const lodash = require("lodash");
|
|
4
5
|
const _ = require("lodash/fp");
|
|
5
|
-
const
|
|
6
|
+
const nodeSchedule = require("node-schedule");
|
|
6
7
|
const yup = require("yup");
|
|
7
8
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
9
|
function _interopNamespace(e) {
|
|
@@ -23,8 +24,8 @@ function _interopNamespace(e) {
|
|
|
23
24
|
n.default = e;
|
|
24
25
|
return Object.freeze(n);
|
|
25
26
|
}
|
|
27
|
+
const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
|
|
26
28
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
27
|
-
const EE__default = /* @__PURE__ */ _interopDefault(EE);
|
|
28
29
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
29
30
|
const RELEASE_MODEL_UID = "plugin::content-releases.release";
|
|
30
31
|
const RELEASE_ACTION_MODEL_UID = "plugin::content-releases.release-action";
|
|
@@ -72,54 +73,178 @@ const ACTIONS = [
|
|
|
72
73
|
pluginName: "content-releases"
|
|
73
74
|
}
|
|
74
75
|
];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
|
77
|
+
RELEASES_PUBLISH: "releases.publish"
|
|
78
|
+
};
|
|
79
|
+
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
80
|
+
return strapi2.plugin("content-releases").service(name);
|
|
81
|
+
};
|
|
82
|
+
const getPopulatedEntry = async (contentTypeUid, entryId, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
83
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
84
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
85
|
+
const entry = await strapi2.entityService.findOne(contentTypeUid, entryId, { populate });
|
|
86
|
+
return entry;
|
|
87
|
+
};
|
|
88
|
+
const getEntryValidStatus = async (contentTypeUid, entry, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
89
|
+
try {
|
|
90
|
+
await strapi2.entityValidator.validateEntityCreation(
|
|
91
|
+
strapi2.getModel(contentTypeUid),
|
|
92
|
+
entry,
|
|
93
|
+
void 0,
|
|
94
|
+
// @ts-expect-error - FIXME: entity here is unnecessary
|
|
95
|
+
entry
|
|
96
|
+
);
|
|
97
|
+
return true;
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
91
100
|
}
|
|
92
|
-
}
|
|
101
|
+
};
|
|
93
102
|
async function deleteActionsOnDeleteContentType({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
94
103
|
const deletedContentTypes = lodash.difference(lodash.keys(oldContentTypes), lodash.keys(contentTypes2)) ?? [];
|
|
95
104
|
if (deletedContentTypes.length) {
|
|
96
|
-
await utils.
|
|
105
|
+
await utils.async.map(deletedContentTypes, async (deletedContentTypeUID) => {
|
|
97
106
|
return strapi.db?.queryBuilder(RELEASE_ACTION_MODEL_UID).delete().where({ contentType: deletedContentTypeUID }).execute();
|
|
98
107
|
});
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
|
-
|
|
110
|
+
async function migrateIsValidAndStatusReleases() {
|
|
111
|
+
const releasesWithoutStatus = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
112
|
+
where: {
|
|
113
|
+
status: null,
|
|
114
|
+
releasedAt: null
|
|
115
|
+
},
|
|
116
|
+
populate: {
|
|
117
|
+
actions: {
|
|
118
|
+
populate: {
|
|
119
|
+
entry: true
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
utils.async.map(releasesWithoutStatus, async (release2) => {
|
|
125
|
+
const actions = release2.actions;
|
|
126
|
+
const notValidatedActions = actions.filter((action) => action.isEntryValid === null);
|
|
127
|
+
for (const action of notValidatedActions) {
|
|
128
|
+
if (action.entry) {
|
|
129
|
+
const populatedEntry = await getPopulatedEntry(action.contentType, action.entry.id, {
|
|
130
|
+
strapi
|
|
131
|
+
});
|
|
132
|
+
if (populatedEntry) {
|
|
133
|
+
const isEntryValid = getEntryValidStatus(action.contentType, populatedEntry, { strapi });
|
|
134
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
135
|
+
where: {
|
|
136
|
+
id: action.id
|
|
137
|
+
},
|
|
138
|
+
data: {
|
|
139
|
+
isEntryValid
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return getService("release", { strapi }).updateReleaseStatus(release2.id);
|
|
146
|
+
});
|
|
147
|
+
const publishedReleases = await strapi.db.query(RELEASE_MODEL_UID).findMany({
|
|
148
|
+
where: {
|
|
149
|
+
status: null,
|
|
150
|
+
releasedAt: {
|
|
151
|
+
$notNull: true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
utils.async.map(publishedReleases, async (release2) => {
|
|
156
|
+
return strapi.db.query(RELEASE_MODEL_UID).update({
|
|
157
|
+
where: {
|
|
158
|
+
id: release2.id
|
|
159
|
+
},
|
|
160
|
+
data: {
|
|
161
|
+
status: "done"
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
async function revalidateChangedContentTypes({ oldContentTypes, contentTypes: contentTypes2 }) {
|
|
167
|
+
if (oldContentTypes !== void 0 && contentTypes2 !== void 0) {
|
|
168
|
+
const contentTypesWithDraftAndPublish = Object.keys(oldContentTypes);
|
|
169
|
+
const releasesAffected = /* @__PURE__ */ new Set();
|
|
170
|
+
utils.async.map(contentTypesWithDraftAndPublish, async (contentTypeUID) => {
|
|
171
|
+
const oldContentType = oldContentTypes[contentTypeUID];
|
|
172
|
+
const contentType = contentTypes2[contentTypeUID];
|
|
173
|
+
if (!isEqual__default.default(oldContentType?.attributes, contentType?.attributes)) {
|
|
174
|
+
const actions = await strapi.db.query(RELEASE_ACTION_MODEL_UID).findMany({
|
|
175
|
+
where: {
|
|
176
|
+
contentType: contentTypeUID
|
|
177
|
+
},
|
|
178
|
+
populate: {
|
|
179
|
+
entry: true,
|
|
180
|
+
release: true
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
await utils.async.map(actions, async (action) => {
|
|
184
|
+
if (action.entry) {
|
|
185
|
+
const populatedEntry = await getPopulatedEntry(contentTypeUID, action.entry.id, {
|
|
186
|
+
strapi
|
|
187
|
+
});
|
|
188
|
+
if (populatedEntry) {
|
|
189
|
+
const isEntryValid = await getEntryValidStatus(contentTypeUID, populatedEntry, {
|
|
190
|
+
strapi
|
|
191
|
+
});
|
|
192
|
+
releasesAffected.add(action.release.id);
|
|
193
|
+
await strapi.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
194
|
+
where: {
|
|
195
|
+
id: action.id
|
|
196
|
+
},
|
|
197
|
+
data: {
|
|
198
|
+
isEntryValid
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}).then(() => {
|
|
206
|
+
utils.async.map(releasesAffected, async (releaseId) => {
|
|
207
|
+
return getService("release", { strapi }).updateReleaseStatus(releaseId);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
102
212
|
const register = async ({ strapi: strapi2 }) => {
|
|
103
|
-
if (features
|
|
213
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
104
214
|
await strapi2.admin.services.permission.actionProvider.registerMany(ACTIONS);
|
|
105
|
-
strapi2.hook("strapi::content-types.
|
|
106
|
-
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType);
|
|
215
|
+
strapi2.hook("strapi::content-types.afterSync").register(deleteActionsOnDeleteContentType).register(revalidateChangedContentTypes).register(migrateIsValidAndStatusReleases);
|
|
107
216
|
}
|
|
108
217
|
};
|
|
109
|
-
const { features: features$1 } = require("@strapi/strapi/dist/utils/ee");
|
|
110
218
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
111
|
-
if (features
|
|
219
|
+
if (strapi2.ee.features.isEnabled("cms-content-releases")) {
|
|
220
|
+
const contentTypesWithDraftAndPublish = Object.keys(strapi2.contentTypes);
|
|
112
221
|
strapi2.db.lifecycles.subscribe({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
222
|
+
models: contentTypesWithDraftAndPublish,
|
|
223
|
+
async afterDelete(event) {
|
|
224
|
+
try {
|
|
225
|
+
const { model, result } = event;
|
|
226
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
227
|
+
const { id } = result;
|
|
228
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
229
|
+
where: {
|
|
230
|
+
actions: {
|
|
231
|
+
target_type: model.uid,
|
|
232
|
+
target_id: id
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
237
|
+
where: {
|
|
238
|
+
target_type: model.uid,
|
|
239
|
+
target_id: id
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
for (const release2 of releases) {
|
|
243
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
121
244
|
}
|
|
122
|
-
}
|
|
245
|
+
}
|
|
246
|
+
} catch (error) {
|
|
247
|
+
strapi2.log.error("Error while deleting release actions after entry delete", { error });
|
|
123
248
|
}
|
|
124
249
|
},
|
|
125
250
|
/**
|
|
@@ -128,7 +253,7 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
128
253
|
*/
|
|
129
254
|
async beforeDeleteMany(event) {
|
|
130
255
|
const { model, params } = event;
|
|
131
|
-
if (model.kind === "collectionType"
|
|
256
|
+
if (model.kind === "collectionType") {
|
|
132
257
|
const { where } = params;
|
|
133
258
|
const entriesToDelete = await strapi2.db.query(model.uid).findMany({ select: ["id"], where });
|
|
134
259
|
event.state.entriesToDelete = entriesToDelete;
|
|
@@ -139,20 +264,98 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
139
264
|
* We make this only after deleteMany is succesfully executed to avoid errors
|
|
140
265
|
*/
|
|
141
266
|
async afterDeleteMany(event) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
267
|
+
try {
|
|
268
|
+
const { model, state } = event;
|
|
269
|
+
const entriesToDelete = state.entriesToDelete;
|
|
270
|
+
if (entriesToDelete) {
|
|
271
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
272
|
+
where: {
|
|
273
|
+
actions: {
|
|
274
|
+
target_type: model.uid,
|
|
275
|
+
target_id: {
|
|
276
|
+
$in: entriesToDelete.map(
|
|
277
|
+
(entry) => entry.id
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
284
|
+
where: {
|
|
285
|
+
target_type: model.uid,
|
|
286
|
+
target_id: {
|
|
287
|
+
$in: entriesToDelete.map((entry) => entry.id)
|
|
288
|
+
}
|
|
150
289
|
}
|
|
290
|
+
});
|
|
291
|
+
for (const release2 of releases) {
|
|
292
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
151
293
|
}
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
strapi2.log.error("Error while deleting release actions after entry deleteMany", {
|
|
297
|
+
error
|
|
152
298
|
});
|
|
153
299
|
}
|
|
300
|
+
},
|
|
301
|
+
async afterUpdate(event) {
|
|
302
|
+
try {
|
|
303
|
+
const { model, result } = event;
|
|
304
|
+
if (model.kind === "collectionType" && model.options?.draftAndPublish) {
|
|
305
|
+
const isEntryValid = await getEntryValidStatus(
|
|
306
|
+
model.uid,
|
|
307
|
+
result,
|
|
308
|
+
{
|
|
309
|
+
strapi: strapi2
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
313
|
+
where: {
|
|
314
|
+
target_type: model.uid,
|
|
315
|
+
target_id: result.id
|
|
316
|
+
},
|
|
317
|
+
data: {
|
|
318
|
+
isEntryValid
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
322
|
+
where: {
|
|
323
|
+
actions: {
|
|
324
|
+
target_type: model.uid,
|
|
325
|
+
target_id: result.id
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
for (const release2 of releases) {
|
|
330
|
+
getService("release", { strapi: strapi2 }).updateReleaseStatus(release2.id);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} catch (error) {
|
|
334
|
+
strapi2.log.error("Error while updating release actions after entry update", { error });
|
|
335
|
+
}
|
|
154
336
|
}
|
|
155
337
|
});
|
|
338
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
339
|
+
getService("scheduling", { strapi: strapi2 }).syncFromDatabase().catch((err) => {
|
|
340
|
+
strapi2.log.error(
|
|
341
|
+
"Error while syncing scheduled jobs from the database in the content-releases plugin. This could lead to errors in the releases scheduling."
|
|
342
|
+
);
|
|
343
|
+
throw err;
|
|
344
|
+
});
|
|
345
|
+
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
|
346
|
+
strapi2.webhookStore.addAllowedEvent(key, value);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const destroy = async ({ strapi: strapi2 }) => {
|
|
352
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
353
|
+
const scheduledJobs = getService("scheduling", {
|
|
354
|
+
strapi: strapi2
|
|
355
|
+
}).getAll();
|
|
356
|
+
for (const [, job] of scheduledJobs) {
|
|
357
|
+
job.cancel();
|
|
358
|
+
}
|
|
156
359
|
}
|
|
157
360
|
};
|
|
158
361
|
const schema$1 = {
|
|
@@ -181,6 +384,17 @@ const schema$1 = {
|
|
|
181
384
|
releasedAt: {
|
|
182
385
|
type: "datetime"
|
|
183
386
|
},
|
|
387
|
+
scheduledAt: {
|
|
388
|
+
type: "datetime"
|
|
389
|
+
},
|
|
390
|
+
timezone: {
|
|
391
|
+
type: "string"
|
|
392
|
+
},
|
|
393
|
+
status: {
|
|
394
|
+
type: "enumeration",
|
|
395
|
+
enum: ["ready", "blocked", "failed", "done", "empty"],
|
|
396
|
+
required: true
|
|
397
|
+
},
|
|
184
398
|
actions: {
|
|
185
399
|
type: "relation",
|
|
186
400
|
relation: "oneToMany",
|
|
@@ -233,6 +447,9 @@ const schema = {
|
|
|
233
447
|
relation: "manyToOne",
|
|
234
448
|
target: RELEASE_MODEL_UID,
|
|
235
449
|
inversedBy: "actions"
|
|
450
|
+
},
|
|
451
|
+
isEntryValid: {
|
|
452
|
+
type: "boolean"
|
|
236
453
|
}
|
|
237
454
|
}
|
|
238
455
|
};
|
|
@@ -243,9 +460,6 @@ const contentTypes = {
|
|
|
243
460
|
release: release$1,
|
|
244
461
|
"release-action": releaseAction$1
|
|
245
462
|
};
|
|
246
|
-
const getService = (name, { strapi: strapi2 } = { strapi: global.strapi }) => {
|
|
247
|
-
return strapi2.plugin("content-releases").service(name);
|
|
248
|
-
};
|
|
249
463
|
const getGroupName = (queryValue) => {
|
|
250
464
|
switch (queryValue) {
|
|
251
465
|
case "contentType":
|
|
@@ -258,415 +472,563 @@ const getGroupName = (queryValue) => {
|
|
|
258
472
|
return "contentType.displayName";
|
|
259
473
|
}
|
|
260
474
|
};
|
|
261
|
-
const createReleaseService = ({ strapi: strapi2 }) =>
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
);
|
|
268
|
-
await Promise.all([
|
|
269
|
-
validatePendingReleasesLimit(),
|
|
270
|
-
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name)
|
|
271
|
-
]);
|
|
272
|
-
return strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
273
|
-
data: releaseWithCreatorFields
|
|
475
|
+
const createReleaseService = ({ strapi: strapi2 }) => {
|
|
476
|
+
const dispatchWebhook = (event, { isPublished, release: release2, error }) => {
|
|
477
|
+
strapi2.eventHub.emit(event, {
|
|
478
|
+
isPublished,
|
|
479
|
+
error,
|
|
480
|
+
release: release2
|
|
274
481
|
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
482
|
+
};
|
|
483
|
+
return {
|
|
484
|
+
async create(releaseData, { user }) {
|
|
485
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user })(releaseData);
|
|
486
|
+
const {
|
|
487
|
+
validatePendingReleasesLimit,
|
|
488
|
+
validateUniqueNameForPendingRelease,
|
|
489
|
+
validateScheduledAtIsLaterThanNow
|
|
490
|
+
} = getService("release-validation", { strapi: strapi2 });
|
|
491
|
+
await Promise.all([
|
|
492
|
+
validatePendingReleasesLimit(),
|
|
493
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name),
|
|
494
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
495
|
+
]);
|
|
496
|
+
const release2 = await strapi2.entityService.create(RELEASE_MODEL_UID, {
|
|
497
|
+
data: {
|
|
498
|
+
...releaseWithCreatorFields,
|
|
499
|
+
status: "empty"
|
|
289
500
|
}
|
|
501
|
+
});
|
|
502
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && releaseWithCreatorFields.scheduledAt) {
|
|
503
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
504
|
+
await schedulingService.set(release2.id, release2.scheduledAt);
|
|
290
505
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
506
|
+
strapi2.telemetry.send("didCreateContentRelease");
|
|
507
|
+
return release2;
|
|
508
|
+
},
|
|
509
|
+
async findOne(id, query = {}) {
|
|
510
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id, {
|
|
511
|
+
...query
|
|
512
|
+
});
|
|
513
|
+
return release2;
|
|
514
|
+
},
|
|
515
|
+
findPage(query) {
|
|
516
|
+
return strapi2.entityService.findPage(RELEASE_MODEL_UID, {
|
|
517
|
+
...query,
|
|
518
|
+
populate: {
|
|
519
|
+
actions: {
|
|
520
|
+
// @ts-expect-error Ignore missing properties
|
|
521
|
+
count: true
|
|
522
|
+
}
|
|
302
523
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
async findManyWithContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
527
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
528
|
+
where: {
|
|
529
|
+
actions: {
|
|
308
530
|
target_type: contentTypeUid,
|
|
309
531
|
target_id: entryId
|
|
532
|
+
},
|
|
533
|
+
releasedAt: {
|
|
534
|
+
$null: true
|
|
310
535
|
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
return releases.map((release2) => {
|
|
315
|
-
if (release2.actions?.length) {
|
|
316
|
-
const [actionForEntry] = release2.actions;
|
|
317
|
-
delete release2.actions;
|
|
318
|
-
return {
|
|
319
|
-
...release2,
|
|
320
|
-
action: actionForEntry
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
return release2;
|
|
324
|
-
});
|
|
325
|
-
},
|
|
326
|
-
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
327
|
-
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
328
|
-
where: {
|
|
329
|
-
releasedAt: {
|
|
330
|
-
$null: true
|
|
331
536
|
},
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
339
|
-
where: {
|
|
340
|
-
$or: [
|
|
341
|
-
{
|
|
342
|
-
id: {
|
|
343
|
-
$notIn: releasesRelated.map((release2) => release2.id)
|
|
537
|
+
populate: {
|
|
538
|
+
// Filter the action to get only the content type entry
|
|
539
|
+
actions: {
|
|
540
|
+
where: {
|
|
541
|
+
target_type: contentTypeUid,
|
|
542
|
+
target_id: entryId
|
|
344
543
|
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
return releases.map((release2) => {
|
|
548
|
+
if (release2.actions?.length) {
|
|
549
|
+
const [actionForEntry] = release2.actions;
|
|
550
|
+
delete release2.actions;
|
|
551
|
+
return {
|
|
552
|
+
...release2,
|
|
553
|
+
action: actionForEntry
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
return release2;
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
async findManyWithoutContentTypeEntryAttached(contentTypeUid, entryId) {
|
|
560
|
+
const releasesRelated = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
561
|
+
where: {
|
|
562
|
+
releasedAt: {
|
|
563
|
+
$null: true
|
|
345
564
|
},
|
|
346
|
-
{
|
|
347
|
-
|
|
565
|
+
actions: {
|
|
566
|
+
target_type: contentTypeUid,
|
|
567
|
+
target_id: entryId
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
572
|
+
where: {
|
|
573
|
+
$or: [
|
|
574
|
+
{
|
|
575
|
+
id: {
|
|
576
|
+
$notIn: releasesRelated.map((release2) => release2.id)
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
actions: null
|
|
581
|
+
}
|
|
582
|
+
],
|
|
583
|
+
releasedAt: {
|
|
584
|
+
$null: true
|
|
348
585
|
}
|
|
349
|
-
],
|
|
350
|
-
releasedAt: {
|
|
351
|
-
$null: true
|
|
352
586
|
}
|
|
587
|
+
});
|
|
588
|
+
return releases.map((release2) => {
|
|
589
|
+
if (release2.actions?.length) {
|
|
590
|
+
const [actionForEntry] = release2.actions;
|
|
591
|
+
delete release2.actions;
|
|
592
|
+
return {
|
|
593
|
+
...release2,
|
|
594
|
+
action: actionForEntry
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
return release2;
|
|
598
|
+
});
|
|
599
|
+
},
|
|
600
|
+
async update(id, releaseData, { user }) {
|
|
601
|
+
const releaseWithCreatorFields = await utils.setCreatorFields({ user, isEdition: true })(
|
|
602
|
+
releaseData
|
|
603
|
+
);
|
|
604
|
+
const { validateUniqueNameForPendingRelease, validateScheduledAtIsLaterThanNow } = getService(
|
|
605
|
+
"release-validation",
|
|
606
|
+
{ strapi: strapi2 }
|
|
607
|
+
);
|
|
608
|
+
await Promise.all([
|
|
609
|
+
validateUniqueNameForPendingRelease(releaseWithCreatorFields.name, id),
|
|
610
|
+
validateScheduledAtIsLaterThanNow(releaseWithCreatorFields.scheduledAt)
|
|
611
|
+
]);
|
|
612
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, id);
|
|
613
|
+
if (!release2) {
|
|
614
|
+
throw new utils.errors.NotFoundError(`No release found for id ${id}`);
|
|
353
615
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (release2.actions?.length) {
|
|
357
|
-
const [actionForEntry] = release2.actions;
|
|
358
|
-
delete release2.actions;
|
|
359
|
-
return {
|
|
360
|
-
...release2,
|
|
361
|
-
action: actionForEntry
|
|
362
|
-
};
|
|
616
|
+
if (release2.releasedAt) {
|
|
617
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
363
618
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
379
|
-
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
380
|
-
*/
|
|
381
|
-
// @ts-expect-error see above
|
|
382
|
-
data: releaseWithCreatorFields
|
|
383
|
-
});
|
|
384
|
-
return updatedRelease;
|
|
385
|
-
},
|
|
386
|
-
async createAction(releaseId, action) {
|
|
387
|
-
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
388
|
-
strapi: strapi2
|
|
389
|
-
});
|
|
390
|
-
await Promise.all([
|
|
391
|
-
validateEntryContentType(action.entry.contentType),
|
|
392
|
-
validateUniqueEntry(releaseId, action)
|
|
393
|
-
]);
|
|
394
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
395
|
-
if (!release2) {
|
|
396
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
397
|
-
}
|
|
398
|
-
if (release2.releasedAt) {
|
|
399
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
400
|
-
}
|
|
401
|
-
const { entry, type } = action;
|
|
402
|
-
return strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
403
|
-
data: {
|
|
404
|
-
type,
|
|
405
|
-
contentType: entry.contentType,
|
|
406
|
-
locale: entry.locale,
|
|
407
|
-
entry: {
|
|
408
|
-
id: entry.id,
|
|
409
|
-
__type: entry.contentType,
|
|
410
|
-
__pivot: { field: "entry" }
|
|
411
|
-
},
|
|
412
|
-
release: releaseId
|
|
413
|
-
},
|
|
414
|
-
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
415
|
-
});
|
|
416
|
-
},
|
|
417
|
-
async findActions(releaseId, query) {
|
|
418
|
-
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
419
|
-
fields: ["id"]
|
|
420
|
-
});
|
|
421
|
-
if (!release2) {
|
|
422
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
423
|
-
}
|
|
424
|
-
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
425
|
-
...query,
|
|
426
|
-
populate: {
|
|
427
|
-
entry: {
|
|
428
|
-
populate: "*"
|
|
619
|
+
const updatedRelease = await strapi2.entityService.update(RELEASE_MODEL_UID, id, {
|
|
620
|
+
/*
|
|
621
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">>
|
|
622
|
+
* is not compatible with the type we are passing here: UpdateRelease.Request['body']
|
|
623
|
+
*/
|
|
624
|
+
// @ts-expect-error see above
|
|
625
|
+
data: releaseWithCreatorFields
|
|
626
|
+
});
|
|
627
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
628
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
629
|
+
if (releaseData.scheduledAt) {
|
|
630
|
+
await schedulingService.set(id, releaseData.scheduledAt);
|
|
631
|
+
} else if (release2.scheduledAt) {
|
|
632
|
+
schedulingService.cancel(id);
|
|
429
633
|
}
|
|
430
|
-
},
|
|
431
|
-
filters: {
|
|
432
|
-
release: releaseId
|
|
433
634
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
635
|
+
this.updateReleaseStatus(id);
|
|
636
|
+
strapi2.telemetry.send("didUpdateContentRelease");
|
|
637
|
+
return updatedRelease;
|
|
638
|
+
},
|
|
639
|
+
async createAction(releaseId, action) {
|
|
640
|
+
const { validateEntryContentType, validateUniqueEntry } = getService("release-validation", {
|
|
641
|
+
strapi: strapi2
|
|
642
|
+
});
|
|
643
|
+
await Promise.all([
|
|
644
|
+
validateEntryContentType(action.entry.contentType),
|
|
645
|
+
validateUniqueEntry(releaseId, action)
|
|
646
|
+
]);
|
|
647
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId);
|
|
648
|
+
if (!release2) {
|
|
649
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
443
650
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
},
|
|
465
|
-
async getLocalesDataForActions() {
|
|
466
|
-
if (!strapi2.plugin("i18n")) {
|
|
467
|
-
return {};
|
|
468
|
-
}
|
|
469
|
-
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
470
|
-
return allLocales.reduce((acc, locale) => {
|
|
471
|
-
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
472
|
-
return acc;
|
|
473
|
-
}, {});
|
|
474
|
-
},
|
|
475
|
-
async getContentTypesDataForActions(contentTypesUids) {
|
|
476
|
-
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
477
|
-
const contentTypesData = {};
|
|
478
|
-
for (const contentTypeUid of contentTypesUids) {
|
|
479
|
-
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
480
|
-
uid: contentTypeUid
|
|
651
|
+
if (release2.releasedAt) {
|
|
652
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
653
|
+
}
|
|
654
|
+
const { entry, type } = action;
|
|
655
|
+
const populatedEntry = await getPopulatedEntry(entry.contentType, entry.id, { strapi: strapi2 });
|
|
656
|
+
const isEntryValid = await getEntryValidStatus(entry.contentType, populatedEntry, { strapi: strapi2 });
|
|
657
|
+
const releaseAction2 = await strapi2.entityService.create(RELEASE_ACTION_MODEL_UID, {
|
|
658
|
+
data: {
|
|
659
|
+
type,
|
|
660
|
+
contentType: entry.contentType,
|
|
661
|
+
locale: entry.locale,
|
|
662
|
+
isEntryValid,
|
|
663
|
+
entry: {
|
|
664
|
+
id: entry.id,
|
|
665
|
+
__type: entry.contentType,
|
|
666
|
+
__pivot: { field: "entry" }
|
|
667
|
+
},
|
|
668
|
+
release: releaseId
|
|
669
|
+
},
|
|
670
|
+
populate: { release: { fields: ["id"] }, entry: { fields: ["id"] } }
|
|
481
671
|
});
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if (!acc.includes(action.contentType)) {
|
|
492
|
-
acc.push(action.contentType);
|
|
672
|
+
this.updateReleaseStatus(releaseId);
|
|
673
|
+
return releaseAction2;
|
|
674
|
+
},
|
|
675
|
+
async findActions(releaseId, query) {
|
|
676
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
677
|
+
fields: ["id"]
|
|
678
|
+
});
|
|
679
|
+
if (!release2) {
|
|
680
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
493
681
|
}
|
|
494
|
-
return
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
682
|
+
return strapi2.entityService.findPage(RELEASE_ACTION_MODEL_UID, {
|
|
683
|
+
...query,
|
|
684
|
+
populate: {
|
|
685
|
+
entry: {
|
|
686
|
+
populate: "*"
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
filters: {
|
|
690
|
+
release: releaseId
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
async countActions(query) {
|
|
695
|
+
return strapi2.entityService.count(RELEASE_ACTION_MODEL_UID, query);
|
|
696
|
+
},
|
|
697
|
+
async groupActions(actions, groupBy) {
|
|
698
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
699
|
+
if (!acc.includes(action.contentType)) {
|
|
700
|
+
acc.push(action.contentType);
|
|
701
|
+
}
|
|
499
702
|
return acc;
|
|
500
|
-
},
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
703
|
+
}, []);
|
|
704
|
+
const allReleaseContentTypesDictionary = await this.getContentTypesDataForActions(
|
|
705
|
+
contentTypeUids
|
|
706
|
+
);
|
|
707
|
+
const allLocalesDictionary = await this.getLocalesDataForActions();
|
|
708
|
+
const formattedData = actions.map((action) => {
|
|
709
|
+
const { mainField, displayName } = allReleaseContentTypesDictionary[action.contentType];
|
|
710
|
+
return {
|
|
711
|
+
...action,
|
|
712
|
+
locale: action.locale ? allLocalesDictionary[action.locale] : null,
|
|
713
|
+
contentType: {
|
|
714
|
+
displayName,
|
|
715
|
+
mainFieldValue: action.entry[mainField],
|
|
716
|
+
uid: action.contentType
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
});
|
|
720
|
+
const groupName = getGroupName(groupBy);
|
|
721
|
+
return ___default.default.groupBy(groupName)(formattedData);
|
|
722
|
+
},
|
|
723
|
+
async getLocalesDataForActions() {
|
|
724
|
+
if (!strapi2.plugin("i18n")) {
|
|
725
|
+
return {};
|
|
726
|
+
}
|
|
727
|
+
const allLocales = await strapi2.plugin("i18n").service("locales").find() || [];
|
|
728
|
+
return allLocales.reduce((acc, locale) => {
|
|
729
|
+
acc[locale.code] = { name: locale.name, code: locale.code };
|
|
511
730
|
return acc;
|
|
512
|
-
},
|
|
513
|
-
|
|
514
|
-
)
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
731
|
+
}, {});
|
|
732
|
+
},
|
|
733
|
+
async getContentTypesDataForActions(contentTypesUids) {
|
|
734
|
+
const contentManagerContentTypeService = strapi2.plugin("content-manager").service("content-types");
|
|
735
|
+
const contentTypesData = {};
|
|
736
|
+
for (const contentTypeUid of contentTypesUids) {
|
|
737
|
+
const contentTypeConfig = await contentManagerContentTypeService.findConfiguration({
|
|
738
|
+
uid: contentTypeUid
|
|
739
|
+
});
|
|
740
|
+
contentTypesData[contentTypeUid] = {
|
|
741
|
+
mainField: contentTypeConfig.settings.mainField,
|
|
742
|
+
displayName: strapi2.getModel(contentTypeUid).info.displayName
|
|
743
|
+
};
|
|
523
744
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
await strapi2.db.transaction(async () => {
|
|
532
|
-
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
533
|
-
where: {
|
|
534
|
-
id: {
|
|
535
|
-
$in: release2.actions.map((action) => action.id)
|
|
536
|
-
}
|
|
745
|
+
return contentTypesData;
|
|
746
|
+
},
|
|
747
|
+
getContentTypeModelsFromActions(actions) {
|
|
748
|
+
const contentTypeUids = actions.reduce((acc, action) => {
|
|
749
|
+
if (!acc.includes(action.contentType)) {
|
|
750
|
+
acc.push(action.contentType);
|
|
537
751
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
752
|
+
return acc;
|
|
753
|
+
}, []);
|
|
754
|
+
const contentTypeModelsMap = contentTypeUids.reduce(
|
|
755
|
+
(acc, contentTypeUid) => {
|
|
756
|
+
acc[contentTypeUid] = strapi2.getModel(contentTypeUid);
|
|
757
|
+
return acc;
|
|
758
|
+
},
|
|
759
|
+
{}
|
|
760
|
+
);
|
|
761
|
+
return contentTypeModelsMap;
|
|
762
|
+
},
|
|
763
|
+
async getAllComponents() {
|
|
764
|
+
const contentManagerComponentsService = strapi2.plugin("content-manager").service("components");
|
|
765
|
+
const components = await contentManagerComponentsService.findAllComponents();
|
|
766
|
+
const componentsMap = components.reduce(
|
|
767
|
+
(acc, component) => {
|
|
768
|
+
acc[component.uid] = component;
|
|
769
|
+
return acc;
|
|
770
|
+
},
|
|
771
|
+
{}
|
|
772
|
+
);
|
|
773
|
+
return componentsMap;
|
|
774
|
+
},
|
|
775
|
+
async delete(releaseId) {
|
|
776
|
+
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
548
777
|
populate: {
|
|
549
778
|
actions: {
|
|
550
|
-
|
|
551
|
-
entry: {
|
|
552
|
-
fields: ["id"]
|
|
553
|
-
}
|
|
554
|
-
}
|
|
779
|
+
fields: ["id"]
|
|
555
780
|
}
|
|
556
781
|
}
|
|
782
|
+
});
|
|
783
|
+
if (!release2) {
|
|
784
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
557
785
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
561
|
-
}
|
|
562
|
-
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
563
|
-
throw new utils.errors.ValidationError("Release already published");
|
|
564
|
-
}
|
|
565
|
-
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
566
|
-
throw new utils.errors.ValidationError("No entries to publish");
|
|
567
|
-
}
|
|
568
|
-
const actions = {};
|
|
569
|
-
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
570
|
-
const contentTypeUid = action.contentType;
|
|
571
|
-
if (!actions[contentTypeUid]) {
|
|
572
|
-
actions[contentTypeUid] = {
|
|
573
|
-
entriestoPublishIds: [],
|
|
574
|
-
entriesToUnpublishIds: []
|
|
575
|
-
};
|
|
786
|
+
if (release2.releasedAt) {
|
|
787
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
576
788
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
789
|
+
await strapi2.db.transaction(async () => {
|
|
790
|
+
await strapi2.db.query(RELEASE_ACTION_MODEL_UID).deleteMany({
|
|
791
|
+
where: {
|
|
792
|
+
id: {
|
|
793
|
+
$in: release2.actions.map((action) => action.id)
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
await strapi2.entityService.delete(RELEASE_MODEL_UID, releaseId);
|
|
798
|
+
});
|
|
799
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling") && release2.scheduledAt) {
|
|
800
|
+
const schedulingService = getService("scheduling", { strapi: strapi2 });
|
|
801
|
+
await schedulingService.cancel(release2.id);
|
|
581
802
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
contentTypeUid,
|
|
803
|
+
strapi2.telemetry.send("didDeleteContentRelease");
|
|
804
|
+
return release2;
|
|
805
|
+
},
|
|
806
|
+
async publish(releaseId) {
|
|
807
|
+
try {
|
|
808
|
+
const releaseWithPopulatedActionEntries = await strapi2.entityService.findOne(
|
|
809
|
+
RELEASE_MODEL_UID,
|
|
810
|
+
releaseId,
|
|
591
811
|
{
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
812
|
+
populate: {
|
|
813
|
+
actions: {
|
|
814
|
+
populate: {
|
|
815
|
+
entry: {
|
|
816
|
+
fields: ["id"]
|
|
817
|
+
}
|
|
818
|
+
}
|
|
595
819
|
}
|
|
596
|
-
}
|
|
597
|
-
populate
|
|
820
|
+
}
|
|
598
821
|
}
|
|
599
822
|
);
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
823
|
+
if (!releaseWithPopulatedActionEntries) {
|
|
824
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
825
|
+
}
|
|
826
|
+
if (releaseWithPopulatedActionEntries.releasedAt) {
|
|
827
|
+
throw new utils.errors.ValidationError("Release already published");
|
|
828
|
+
}
|
|
829
|
+
if (releaseWithPopulatedActionEntries.actions.length === 0) {
|
|
830
|
+
throw new utils.errors.ValidationError("No entries to publish");
|
|
831
|
+
}
|
|
832
|
+
const collectionTypeActions = {};
|
|
833
|
+
const singleTypeActions = [];
|
|
834
|
+
for (const action of releaseWithPopulatedActionEntries.actions) {
|
|
835
|
+
const contentTypeUid = action.contentType;
|
|
836
|
+
if (strapi2.contentTypes[contentTypeUid].kind === "collectionType") {
|
|
837
|
+
if (!collectionTypeActions[contentTypeUid]) {
|
|
838
|
+
collectionTypeActions[contentTypeUid] = {
|
|
839
|
+
entriestoPublishIds: [],
|
|
840
|
+
entriesToUnpublishIds: []
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
if (action.type === "publish") {
|
|
844
|
+
collectionTypeActions[contentTypeUid].entriestoPublishIds.push(action.entry.id);
|
|
845
|
+
} else {
|
|
846
|
+
collectionTypeActions[contentTypeUid].entriesToUnpublishIds.push(action.entry.id);
|
|
847
|
+
}
|
|
848
|
+
} else {
|
|
849
|
+
singleTypeActions.push({
|
|
850
|
+
uid: contentTypeUid,
|
|
851
|
+
action: action.type,
|
|
852
|
+
id: action.entry.id
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const entityManagerService = strapi2.plugin("content-manager").service("entity-manager");
|
|
857
|
+
const populateBuilderService = strapi2.plugin("content-manager").service("populate-builder");
|
|
858
|
+
await strapi2.db.transaction(async () => {
|
|
859
|
+
for (const { uid, action, id } of singleTypeActions) {
|
|
860
|
+
const populate = await populateBuilderService(uid).populateDeep(Infinity).build();
|
|
861
|
+
const entry = await strapi2.entityService.findOne(uid, id, { populate });
|
|
862
|
+
try {
|
|
863
|
+
if (action === "publish") {
|
|
864
|
+
await entityManagerService.publish(entry, uid);
|
|
865
|
+
} else {
|
|
866
|
+
await entityManagerService.unpublish(entry, uid);
|
|
606
867
|
}
|
|
607
|
-
}
|
|
608
|
-
|
|
868
|
+
} catch (error) {
|
|
869
|
+
if (error instanceof utils.errors.ApplicationError && (error.message === "already.published" || error.message === "already.draft")) {
|
|
870
|
+
} else {
|
|
871
|
+
throw error;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
609
874
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
875
|
+
for (const contentTypeUid of Object.keys(collectionTypeActions)) {
|
|
876
|
+
const populate = await populateBuilderService(contentTypeUid).populateDeep(Infinity).build();
|
|
877
|
+
const { entriestoPublishIds, entriesToUnpublishIds } = collectionTypeActions[contentTypeUid];
|
|
878
|
+
const entriesToPublish = await strapi2.entityService.findMany(
|
|
879
|
+
contentTypeUid,
|
|
880
|
+
{
|
|
881
|
+
filters: {
|
|
882
|
+
id: {
|
|
883
|
+
$in: entriestoPublishIds
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
populate
|
|
887
|
+
}
|
|
888
|
+
);
|
|
889
|
+
const entriesToUnpublish = await strapi2.entityService.findMany(
|
|
890
|
+
contentTypeUid,
|
|
891
|
+
{
|
|
892
|
+
filters: {
|
|
893
|
+
id: {
|
|
894
|
+
$in: entriesToUnpublishIds
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
populate
|
|
898
|
+
}
|
|
899
|
+
);
|
|
900
|
+
if (entriesToPublish.length > 0) {
|
|
901
|
+
await entityManagerService.publishMany(entriesToPublish, contentTypeUid);
|
|
902
|
+
}
|
|
903
|
+
if (entriesToUnpublish.length > 0) {
|
|
904
|
+
await entityManagerService.unpublishMany(entriesToUnpublish, contentTypeUid);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
const release2 = await strapi2.entityService.update(RELEASE_MODEL_UID, releaseId, {
|
|
909
|
+
data: {
|
|
910
|
+
/*
|
|
911
|
+
* The type returned from the entity service: Partial<Input<"plugin::content-releases.release">> looks like it's wrong
|
|
912
|
+
*/
|
|
913
|
+
// @ts-expect-error see above
|
|
914
|
+
releasedAt: /* @__PURE__ */ new Date()
|
|
915
|
+
},
|
|
916
|
+
populate: {
|
|
917
|
+
actions: {
|
|
918
|
+
// @ts-expect-error is not expecting count but it is working
|
|
919
|
+
count: true
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
924
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
925
|
+
isPublished: true,
|
|
926
|
+
release: release2
|
|
927
|
+
});
|
|
613
928
|
}
|
|
614
|
-
|
|
615
|
-
|
|
929
|
+
strapi2.telemetry.send("didPublishContentRelease");
|
|
930
|
+
return release2;
|
|
931
|
+
} catch (error) {
|
|
932
|
+
if (strapi2.features.future.isEnabled("contentReleasesScheduling")) {
|
|
933
|
+
dispatchWebhook(ALLOWED_WEBHOOK_EVENTS.RELEASES_PUBLISH, {
|
|
934
|
+
isPublished: false,
|
|
935
|
+
error
|
|
936
|
+
});
|
|
616
937
|
}
|
|
938
|
+
strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
939
|
+
where: { id: releaseId },
|
|
940
|
+
data: {
|
|
941
|
+
status: "failed"
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
throw error;
|
|
617
945
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
946
|
+
},
|
|
947
|
+
async updateAction(actionId, releaseId, update) {
|
|
948
|
+
const updatedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).update({
|
|
949
|
+
where: {
|
|
950
|
+
id: actionId,
|
|
951
|
+
release: {
|
|
952
|
+
id: releaseId,
|
|
953
|
+
releasedAt: {
|
|
954
|
+
$null: true
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
data: update
|
|
959
|
+
});
|
|
960
|
+
if (!updatedAction) {
|
|
961
|
+
throw new utils.errors.NotFoundError(
|
|
962
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
963
|
+
);
|
|
626
964
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
965
|
+
return updatedAction;
|
|
966
|
+
},
|
|
967
|
+
async deleteAction(actionId, releaseId) {
|
|
968
|
+
const deletedAction = await strapi2.db.query(RELEASE_ACTION_MODEL_UID).delete({
|
|
969
|
+
where: {
|
|
970
|
+
id: actionId,
|
|
971
|
+
release: {
|
|
972
|
+
id: releaseId,
|
|
973
|
+
releasedAt: {
|
|
974
|
+
$null: true
|
|
975
|
+
}
|
|
638
976
|
}
|
|
639
977
|
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
978
|
+
});
|
|
979
|
+
if (!deletedAction) {
|
|
980
|
+
throw new utils.errors.NotFoundError(
|
|
981
|
+
`Action with id ${actionId} not found in release with id ${releaseId} or it is already published`
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
this.updateReleaseStatus(releaseId);
|
|
985
|
+
return deletedAction;
|
|
986
|
+
},
|
|
987
|
+
async updateReleaseStatus(releaseId) {
|
|
988
|
+
const [totalActions, invalidActions] = await Promise.all([
|
|
989
|
+
this.countActions({
|
|
990
|
+
filters: {
|
|
991
|
+
release: releaseId
|
|
992
|
+
}
|
|
993
|
+
}),
|
|
994
|
+
this.countActions({
|
|
995
|
+
filters: {
|
|
996
|
+
release: releaseId,
|
|
997
|
+
isEntryValid: false
|
|
658
998
|
}
|
|
999
|
+
})
|
|
1000
|
+
]);
|
|
1001
|
+
if (totalActions > 0) {
|
|
1002
|
+
if (invalidActions > 0) {
|
|
1003
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1004
|
+
where: {
|
|
1005
|
+
id: releaseId
|
|
1006
|
+
},
|
|
1007
|
+
data: {
|
|
1008
|
+
status: "blocked"
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
659
1011
|
}
|
|
1012
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1013
|
+
where: {
|
|
1014
|
+
id: releaseId
|
|
1015
|
+
},
|
|
1016
|
+
data: {
|
|
1017
|
+
status: "ready"
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
660
1020
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
1021
|
+
return strapi2.db.query(RELEASE_MODEL_UID).update({
|
|
1022
|
+
where: {
|
|
1023
|
+
id: releaseId
|
|
1024
|
+
},
|
|
1025
|
+
data: {
|
|
1026
|
+
status: "empty"
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
666
1029
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
});
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
670
1032
|
const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
671
1033
|
async validateUniqueEntry(releaseId, releaseActionArgs) {
|
|
672
1034
|
const release2 = await strapi2.entityService.findOne(RELEASE_MODEL_UID, releaseId, {
|
|
@@ -689,17 +1051,9 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
689
1051
|
if (!contentType) {
|
|
690
1052
|
throw new utils.errors.NotFoundError(`No content type found for uid ${contentTypeUid}`);
|
|
691
1053
|
}
|
|
692
|
-
if (!contentType.options?.draftAndPublish) {
|
|
693
|
-
throw new utils.errors.ValidationError(
|
|
694
|
-
`Content type with uid ${contentTypeUid} does not have draftAndPublish enabled`
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
1054
|
},
|
|
698
1055
|
async validatePendingReleasesLimit() {
|
|
699
|
-
const maximumPendingReleases = (
|
|
700
|
-
// @ts-expect-error - options is not typed into features
|
|
701
|
-
EE__default.default.features.get("cms-content-releases")?.options?.maximumReleases || 3
|
|
702
|
-
);
|
|
1056
|
+
const maximumPendingReleases = strapi2.ee.features.get("cms-content-releases")?.options?.maximumReleases || 3;
|
|
703
1057
|
const [, pendingReleasesCount] = await strapi2.db.query(RELEASE_MODEL_UID).findWithCount({
|
|
704
1058
|
filters: {
|
|
705
1059
|
releasedAt: {
|
|
@@ -711,27 +1065,103 @@ const createReleaseValidationService = ({ strapi: strapi2 }) => ({
|
|
|
711
1065
|
throw new utils.errors.ValidationError("You have reached the maximum number of pending releases");
|
|
712
1066
|
}
|
|
713
1067
|
},
|
|
714
|
-
async validateUniqueNameForPendingRelease(name) {
|
|
1068
|
+
async validateUniqueNameForPendingRelease(name, id) {
|
|
715
1069
|
const pendingReleases = await strapi2.entityService.findMany(RELEASE_MODEL_UID, {
|
|
716
1070
|
filters: {
|
|
717
1071
|
releasedAt: {
|
|
718
1072
|
$null: true
|
|
719
1073
|
},
|
|
720
|
-
name
|
|
1074
|
+
name,
|
|
1075
|
+
...id && { id: { $ne: id } }
|
|
721
1076
|
}
|
|
722
1077
|
});
|
|
723
1078
|
const isNameUnique = pendingReleases.length === 0;
|
|
724
1079
|
if (!isNameUnique) {
|
|
725
1080
|
throw new utils.errors.ValidationError(`Release with name ${name} already exists`);
|
|
726
1081
|
}
|
|
1082
|
+
},
|
|
1083
|
+
async validateScheduledAtIsLaterThanNow(scheduledAt) {
|
|
1084
|
+
if (scheduledAt && new Date(scheduledAt) <= /* @__PURE__ */ new Date()) {
|
|
1085
|
+
throw new utils.errors.ValidationError("Scheduled at must be later than now");
|
|
1086
|
+
}
|
|
727
1087
|
}
|
|
728
1088
|
});
|
|
1089
|
+
const createSchedulingService = ({ strapi: strapi2 }) => {
|
|
1090
|
+
const scheduledJobs = /* @__PURE__ */ new Map();
|
|
1091
|
+
return {
|
|
1092
|
+
async set(releaseId, scheduleDate) {
|
|
1093
|
+
const release2 = await strapi2.db.query(RELEASE_MODEL_UID).findOne({ where: { id: releaseId, releasedAt: null } });
|
|
1094
|
+
if (!release2) {
|
|
1095
|
+
throw new utils.errors.NotFoundError(`No release found for id ${releaseId}`);
|
|
1096
|
+
}
|
|
1097
|
+
const job = nodeSchedule.scheduleJob(scheduleDate, async () => {
|
|
1098
|
+
try {
|
|
1099
|
+
await getService("release").publish(releaseId);
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
}
|
|
1102
|
+
this.cancel(releaseId);
|
|
1103
|
+
});
|
|
1104
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1105
|
+
this.cancel(releaseId);
|
|
1106
|
+
}
|
|
1107
|
+
scheduledJobs.set(releaseId, job);
|
|
1108
|
+
return scheduledJobs;
|
|
1109
|
+
},
|
|
1110
|
+
cancel(releaseId) {
|
|
1111
|
+
if (scheduledJobs.has(releaseId)) {
|
|
1112
|
+
scheduledJobs.get(releaseId).cancel();
|
|
1113
|
+
scheduledJobs.delete(releaseId);
|
|
1114
|
+
}
|
|
1115
|
+
return scheduledJobs;
|
|
1116
|
+
},
|
|
1117
|
+
getAll() {
|
|
1118
|
+
return scheduledJobs;
|
|
1119
|
+
},
|
|
1120
|
+
/**
|
|
1121
|
+
* On bootstrap, we can use this function to make sure to sync the scheduled jobs from the database that are not yet released
|
|
1122
|
+
* This is useful in case the server was restarted and the scheduled jobs were lost
|
|
1123
|
+
* This also could be used to sync different Strapi instances in case of a cluster
|
|
1124
|
+
*/
|
|
1125
|
+
async syncFromDatabase() {
|
|
1126
|
+
const releases = await strapi2.db.query(RELEASE_MODEL_UID).findMany({
|
|
1127
|
+
where: {
|
|
1128
|
+
scheduledAt: {
|
|
1129
|
+
$gte: /* @__PURE__ */ new Date()
|
|
1130
|
+
},
|
|
1131
|
+
releasedAt: null
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
for (const release2 of releases) {
|
|
1135
|
+
this.set(release2.id, release2.scheduledAt);
|
|
1136
|
+
}
|
|
1137
|
+
return scheduledJobs;
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
};
|
|
729
1141
|
const services = {
|
|
730
1142
|
release: createReleaseService,
|
|
731
|
-
"release-validation": createReleaseValidationService
|
|
1143
|
+
"release-validation": createReleaseValidationService,
|
|
1144
|
+
...strapi.features.future.isEnabled("contentReleasesScheduling") ? { scheduling: createSchedulingService } : {}
|
|
732
1145
|
};
|
|
733
1146
|
const RELEASE_SCHEMA = yup__namespace.object().shape({
|
|
734
|
-
name: yup__namespace.string().trim().required()
|
|
1147
|
+
name: yup__namespace.string().trim().required(),
|
|
1148
|
+
scheduledAt: yup__namespace.string().nullable(),
|
|
1149
|
+
isScheduled: yup__namespace.boolean().optional(),
|
|
1150
|
+
time: yup__namespace.string().when("isScheduled", {
|
|
1151
|
+
is: true,
|
|
1152
|
+
then: yup__namespace.string().trim().required(),
|
|
1153
|
+
otherwise: yup__namespace.string().nullable()
|
|
1154
|
+
}),
|
|
1155
|
+
timezone: yup__namespace.string().when("isScheduled", {
|
|
1156
|
+
is: true,
|
|
1157
|
+
then: yup__namespace.string().required().nullable(),
|
|
1158
|
+
otherwise: yup__namespace.string().nullable()
|
|
1159
|
+
}),
|
|
1160
|
+
date: yup__namespace.string().when("isScheduled", {
|
|
1161
|
+
is: true,
|
|
1162
|
+
then: yup__namespace.string().required().nullable(),
|
|
1163
|
+
otherwise: yup__namespace.string().nullable()
|
|
1164
|
+
})
|
|
735
1165
|
}).required().noUnknown();
|
|
736
1166
|
const validateRelease = utils.validateYupSchema(RELEASE_SCHEMA);
|
|
737
1167
|
const releaseController = {
|
|
@@ -764,26 +1194,30 @@ const releaseController = {
|
|
|
764
1194
|
}
|
|
765
1195
|
};
|
|
766
1196
|
});
|
|
767
|
-
|
|
1197
|
+
const pendingReleasesCount = await strapi.query(RELEASE_MODEL_UID).count({
|
|
1198
|
+
where: {
|
|
1199
|
+
releasedAt: null
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
ctx.body = { data, meta: { pagination, pendingReleasesCount } };
|
|
768
1203
|
}
|
|
769
1204
|
},
|
|
770
1205
|
async findOne(ctx) {
|
|
771
1206
|
const id = ctx.params.id;
|
|
772
1207
|
const releaseService = getService("release", { strapi });
|
|
773
1208
|
const release2 = await releaseService.findOne(id, { populate: ["createdBy"] });
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
});
|
|
778
|
-
const sanitizedRelease = await permissionsManager.sanitizeOutput(release2);
|
|
1209
|
+
if (!release2) {
|
|
1210
|
+
throw new utils.errors.NotFoundError(`Release not found for id: ${id}`);
|
|
1211
|
+
}
|
|
779
1212
|
const count = await releaseService.countActions({
|
|
780
1213
|
filters: {
|
|
781
1214
|
release: id
|
|
782
1215
|
}
|
|
783
1216
|
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
1217
|
+
const sanitizedRelease = {
|
|
1218
|
+
...release2,
|
|
1219
|
+
createdBy: release2.createdBy ? strapi.admin.services.user.sanitizeUser(release2.createdBy) : null
|
|
1220
|
+
};
|
|
787
1221
|
const data = {
|
|
788
1222
|
...sanitizedRelease,
|
|
789
1223
|
actions: {
|
|
@@ -836,8 +1270,27 @@ const releaseController = {
|
|
|
836
1270
|
const id = ctx.params.id;
|
|
837
1271
|
const releaseService = getService("release", { strapi });
|
|
838
1272
|
const release2 = await releaseService.publish(id, { user });
|
|
1273
|
+
const [countPublishActions, countUnpublishActions] = await Promise.all([
|
|
1274
|
+
releaseService.countActions({
|
|
1275
|
+
filters: {
|
|
1276
|
+
release: id,
|
|
1277
|
+
type: "publish"
|
|
1278
|
+
}
|
|
1279
|
+
}),
|
|
1280
|
+
releaseService.countActions({
|
|
1281
|
+
filters: {
|
|
1282
|
+
release: id,
|
|
1283
|
+
type: "unpublish"
|
|
1284
|
+
}
|
|
1285
|
+
})
|
|
1286
|
+
]);
|
|
839
1287
|
ctx.body = {
|
|
840
|
-
data: release2
|
|
1288
|
+
data: release2,
|
|
1289
|
+
meta: {
|
|
1290
|
+
totalEntries: countPublishActions + countUnpublishActions,
|
|
1291
|
+
totalPublishedEntries: countPublishActions,
|
|
1292
|
+
totalUnpublishedEntries: countUnpublishActions
|
|
1293
|
+
}
|
|
841
1294
|
};
|
|
842
1295
|
}
|
|
843
1296
|
};
|
|
@@ -887,7 +1340,7 @@ const releaseActionController = {
|
|
|
887
1340
|
acc[action.contentType] = contentTypePermissionsManager.sanitizeOutput;
|
|
888
1341
|
return acc;
|
|
889
1342
|
}, {});
|
|
890
|
-
const sanitizedResults = await utils.
|
|
1343
|
+
const sanitizedResults = await utils.async.map(results, async (action) => ({
|
|
891
1344
|
...action,
|
|
892
1345
|
entry: await contentTypeOutputSanitizers[action.contentType](action.entry)
|
|
893
1346
|
}));
|
|
@@ -1103,12 +1556,12 @@ const routes = {
|
|
|
1103
1556
|
release,
|
|
1104
1557
|
"release-action": releaseAction
|
|
1105
1558
|
};
|
|
1106
|
-
const { features } = require("@strapi/strapi/dist/utils/ee");
|
|
1107
1559
|
const getPlugin = () => {
|
|
1108
|
-
if (features.isEnabled("cms-content-releases")) {
|
|
1560
|
+
if (strapi.ee.features.isEnabled("cms-content-releases")) {
|
|
1109
1561
|
return {
|
|
1110
1562
|
register,
|
|
1111
1563
|
bootstrap,
|
|
1564
|
+
destroy,
|
|
1112
1565
|
contentTypes,
|
|
1113
1566
|
services,
|
|
1114
1567
|
controllers,
|