raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

Change state by timeout #51

Closed timz closed 6 years ago

timz commented 6 years ago

Hello! How to change state by this rule: If the Post is not published after 10 days after save, then assign the status of "archive" ?

raoul2000 commented 6 years ago

Hello @Timz, yii2-workflow doesn't provide a way to automatically perform a transition the way you're describing : on save the transition to the target status is applied. It can end in success or in error, but the target status once defined outside of yii2-workflow cannot be changed by yii2-workflow. Basically, yii2-workflow doesn't implement conditional transition branching.

So you will have to test the "Archive" condition before saving the Model, and if true, set its status to "Archive".

ciao 😎

KnightYoshi commented 6 years ago

More ideally you would use a cron job for this to run once a day executing a script that would query the Post table for posts with a date that is more than 10 days old and update its status to be archived.

raoul2000 commented 6 years ago

yes, that's what I would suggest ... muuuch more simple 😉