diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 07e7ebd63e..25eacf8e06 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -205,6 +205,7 @@ module.exports = { '/3.0.0-beta.x/guides/custom-admin', '/3.0.0-beta.x/guides/client', '/3.0.0-beta.x/guides/draft', + '/3.0.0-beta.x/guides/scheduled-publication', '/3.0.0-beta.x/guides/slug', '/3.0.0-beta.x/guides/send-email', '/3.0.0-beta.x/guides/webhooks', diff --git a/docs/3.0.0-beta.x/guides/scheduled-publication.md b/docs/3.0.0-beta.x/guides/scheduled-publication.md new file mode 100644 index 0000000000..4861311335 --- /dev/null +++ b/docs/3.0.0-beta.x/guides/scheduled-publication.md @@ -0,0 +1,77 @@ +# Scheduled publication + +This guide will explain how to create an article schedule system. + +## Introduction + +This guide will use this [draft system](./draft.md) guide. You should review it first to understand the draft/published status and the **Article** API that we will use in this guide. + +What we want here is to be able to set a publication date for an article, and at this date, switch the `draft` status to `published`. + +## Example + +For this example, we will have to add a `publish_at` attribute to the **Article** Content Type. + +- Click on the Content Type Builder link in the left menu +- Select the **Article** Content Type +- Add another field + - `date` attribute named `publish_at` with `datetime` type + +And add some data with different dates and status to be able to see the publication happen. +Make sure to create some entries with a draft `status` and a `published_at` that is before the current date. + +The goal will be to check every minute if there is `draft` articles that have a `publish_at` lower that the current date. + +## Create a CRON task + +To execute a function every minutes, we will use a CRON task. + +Here is the [full documentation](../concepts/configurations.md#cron-tasks) of this feature. + +**Path —** `./config/functions/cron.js` + +```js +module.exports = { + '*/1 * * * *': () => { + console.log('1 minute later'); + }, +}; +``` + +Make sure the enabled cron config is set to true in `./config/environments/**/server.json` file. + +::: tip +Please note that Strapi's built in CRON feature will not work if you plan to use `pm2` or node based clustering. You will need to execute these CRON tasks outside of Strapi. +::: + +## Business logic + +Now we can start writting the publishing logic. The code that will fetch all `draft` **Articles** with a `published_at` that is before the current date. + +Then we will update the `status` of all these articles to `published`. + +**Path —** `./config/functions/cron.js` + +```js +module.exports = { + '*/1 * * * *': async () => { + // fetch articles to publish + const draftArticleToPublish = await strapi.api.article.services.article.find({ + status: 'draft', + publish_at_lt: new Date() + }); + + // update status of articles + draftArticleToPublish.forEach(async (article) => { + await strapi.api.article.services.article.update( + {id: article.id}, + {status: 'published'} + ); + }); + }, +}; +``` + +And tada! + + diff --git a/docs/3.0.0-beta.x/guides/slug.md b/docs/3.0.0-beta.x/guides/slug.md index 43ba379dfb..0fb8d5c05c 100644 --- a/docs/3.0.0-beta.x/guides/slug.md +++ b/docs/3.0.0-beta.x/guides/slug.md @@ -69,7 +69,7 @@ module.exports = { } }, beforeUpdate: async model => { - if (model.getUpdate().title) { + if (model.getUpdate() && model.getUpdate().title) { model.update({ slug: slugify(model.getUpdate().title), }); diff --git a/docs/3.0.0-beta.x/plugins/users-permissions.md b/docs/3.0.0-beta.x/plugins/users-permissions.md index ee04427d92..d2cbae1d53 100644 --- a/docs/3.0.0-beta.x/plugins/users-permissions.md +++ b/docs/3.0.0-beta.x/plugins/users-permissions.md @@ -221,7 +221,7 @@ Then fill the informations: ::: tab Google -### Facebook configuration +### Google configuration - Visit the Google Developer Console
[https://console.developers.google.com/](https://console.developers.google.com/) - Click on the **Select a project** dropdown in the top menu diff --git a/packages/strapi-provider-email-sendgrid/lib/index.js b/packages/strapi-provider-email-sendgrid/lib/index.js index 81f3ca05af..b6e1fa03e6 100644 --- a/packages/strapi-provider-email-sendgrid/lib/index.js +++ b/packages/strapi-provider-email-sendgrid/lib/index.js @@ -43,12 +43,14 @@ module.exports = { let msg = { from: options.from, to: options.to, - reply_to: options.replyTo, + replyTo: options.replyTo, subject: options.subject, text: options.text, html: options.html, templateId: options.templateId, dynamic_template_data: options.dynamic_template_data, + sendAt: options.sendAt, + batchId: options.batchId, }; sendgrid.send(msg, function(err) {