mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 00:03:40 +00:00
Publish/unpublish a mix of draft and published states
This commit is contained in:
parent
4ddac20ac9
commit
5ddfd14236
@ -274,10 +274,6 @@ module.exports = ({ strapi }) => ({
|
|||||||
// Validate entities before publishing, throw if invalid
|
// Validate entities before publishing, throw if invalid
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
entities.map((entityToUpdate) => {
|
entities.map((entityToUpdate) => {
|
||||||
if (entityToUpdate[PUBLISHED_AT_ATTRIBUTE]) {
|
|
||||||
throw new ApplicationError('already.published');
|
|
||||||
}
|
|
||||||
|
|
||||||
return strapi.entityValidator.validateEntityCreation(
|
return strapi.entityValidator.validateEntityCreation(
|
||||||
strapi.getModel(uid),
|
strapi.getModel(uid),
|
||||||
entityToUpdate,
|
entityToUpdate,
|
||||||
@ -289,7 +285,11 @@ module.exports = ({ strapi }) => ({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const where = { id: { $in: entities.map((entity) => entity.id) } };
|
// Only publish entities without a published_at date
|
||||||
|
const entitiesToPublish = entities
|
||||||
|
.filter((entity) => !entity[PUBLISHED_AT_ATTRIBUTE])
|
||||||
|
.map((entity) => entity.id);
|
||||||
|
const where = { id: { $in: entitiesToPublish } };
|
||||||
const data = {
|
const data = {
|
||||||
[PUBLISHED_AT_ATTRIBUTE]: new Date(),
|
[PUBLISHED_AT_ATTRIBUTE]: new Date(),
|
||||||
};
|
};
|
||||||
@ -315,14 +315,9 @@ module.exports = ({ strapi }) => ({
|
|||||||
if (!entities.length) {
|
if (!entities.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// Unpublish everything regardles of publish draft state
|
||||||
entities.forEach((entity) => {
|
const entitiesToUnpublish = entities.map((entity) => entity.id);
|
||||||
if (!entity[PUBLISHED_AT_ATTRIBUTE]) {
|
const where = { id: { $in: entitiesToUnpublish } };
|
||||||
throw new ApplicationError('already.draft');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const where = { id: { $in: entities.map((entity) => entity.id) } };
|
|
||||||
const data = {
|
const data = {
|
||||||
[PUBLISHED_AT_ATTRIBUTE]: null,
|
[PUBLISHED_AT_ATTRIBUTE]: null,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user