Ad

Monitor Date And Send Email Notification To Users

- 1 answer

I have created a plugin in OctoberCMS to store users information and products expiry date.

I want to make Event fire when expiry date is close to current date and send email to the user, how can I monitor the date (should I use contrib shell command)? how do I approach this?

Regards,

Ad

Answer

Probably you need cron-jobshttps://en.wikipedia.org/wiki/Cron

Server will execute scheduler based on time you define in your cron-job, In Your case it will be good to schedule it every day.

now every day it will fire you scheduler > then it will call your Task (https://octobercms.com/docs/plugin/scheduling#introduction) with your logic.

Logic

You will fetch records with condition like :

current_date + 1/2/3 day convert that date in to timestamp and store to variable future_date

And add condition on field expiry_date

expiry_date > today_time_stamp AND expiry_date < future_date

It will give you records which are about to expire in next 1/2/3 days

now notify [send email] or fire event for these records

You can add master cron job to your server just follow this guidehttps://octobercms.com/docs/setup/installation#crontab-setup

Then you can just write you logic how you want thing to be donehttps://octobercms.com/docs/plugin/scheduling#introduction

if any doubt please comment

Ad
source: stackoverflow.com
Ad