0

I have a MySQL Table, let's say for blog posts. They have a column status which cam be active or inactive and two columns which are optional: publish date and expire date for scheduling posts.

Which solution do you recommend for changing the status depending on the publish date and expire date? Can I do this with a PHP script or cronjob ?

EDIT 30.11.16 / 16:50 Perhaps I have to be more precise about my specific problem: I have a magento store and I would like to add the possibility to schedule teasers. I want to change the existing code as little as possible.

T40
  • 9
  • 3
  • Yes, a cronjob could do this, or decide the status when you're loading the content – Pekka Nov 30 '16 at 15:17
  • When loading the content you could simply exclude any where the published date hasn't arrived or the expiry date has expired. That would save having to have a status update job. For the DB purists it might also be considered better database design - if the status is a field that can be determined purely based on the values in other fields, then it's effectively redundant since the value can be derived whenever required. – ADyson Nov 30 '16 at 15:20

1 Answers1

0

I would say, it depends, but as @ADyson sad you should't only work with a cronjob, because it show some posts that should have been expired.

But you think about to write a single class/function that handle the status and expiration / publish date logic. It will be a mess later, if you have the code copy in the cronjob and on different output pages.

I also would think about the status field, maybe it is not necessary, if you make some MySQL Selects like

...
WHERE publish_date>now() AND expire_date<now()
sebkrueger
  • 386
  • 5
  • 16