Created
May 9, 2022 18:56
-
-
Save alexandrebodin/62e5b0b446b9494c81ce672feaf0def3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const draftAndPublishSync = require('@strapi/strapi/lib/migrations/draft-publish'); | |
const { hasDraftAndPublish } = require('@strapi/utils').contentTypes; | |
module.exports = { | |
/** | |
* An asynchronous register function that runs before | |
* your application is initialized. | |
* | |
* This gives you an opportunity to extend code. | |
*/ | |
register({ strapi }) { | |
console.log('there'); | |
strapi.hook('strapi::content-types.beforeSync').delete(draftAndPublishSync.disable); | |
strapi | |
.hook('strapi::content-types.beforeSync') | |
.register(async function test({ oldContentTypes, contentTypes }) { | |
if (!oldContentTypes) { | |
return; | |
} | |
for (const uid in contentTypes) { | |
if (!oldContentTypes[uid]) { | |
continue; | |
} | |
const oldContentType = oldContentTypes[uid]; | |
const contentType = contentTypes[uid]; | |
// if d&p was disabled remove unpublish content before sync | |
if (hasDraftAndPublish(oldContentType) && !hasDraftAndPublish(contentType)) { | |
await strapi.db | |
.queryBuilder(uid) | |
.delete() | |
.where({ published_at: new Date() }) | |
.execute(); | |
} | |
} | |
}); | |
}, | |
/** | |
* An asynchronous bootstrap function that runs before | |
* your application gets started. | |
* | |
* This gives you an opportunity to set up your data model, | |
* run jobs, or perform some special logic. | |
*/ | |
bootstrap({ strapi }) {}, | |
/** | |
* An asynchronous destroy function that runs before | |
* your application gets shut down. | |
* | |
* This gives you an opportunity to gracefully stop services you run. | |
*/ | |
destroy({ strapi }) {}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment