D
D
DarkByte20152018-08-14 13:56:49
PHP
DarkByte2015, 2018-08-14 13:56:49

Come up with the logic of setting errors?

There is an article Article(id, name, status_id) which has been submitted for moderation. At the same time, her status changes: she was in drafts, then sent for review, then either returned or accepted.
Status is a field in the article model, but in addition to this, the history of status changes is written. Of type ArticleEvent(id, article_id, old_status_id, new_status_id).
Also, errors can be fixed on the review of the article, well, in the sense of marking errors in the article. This is a separate model related to the ArticleError(id, event_id, field_id, message) event. But only "erroneous" events have errors - which are recorded when the status changes to "returned".
The problem is the following: in order to create an error at the review stage, I need the created event about the return of the article in order to attach this error to it. But the article hasn't been returned yet!!! And not the fact that it will be returned, it may be accepted. Those. I have nothing to attach an error during installation.
I tried to do this: when an article goes into the "review" status, I create a "returned" event with a separate is_status_changed field - whether the status has really changed. But then if there are still no errors, then it must also be deleted when the article switches to the "accepted" status. And don't forget to enable/disable this flag. And there are also old articles with an old history (previously it was done a little differently) which, with the status of "review", do not have a return event. In general, this is extremely confusing. A lot of bugs.
You can also probably create a return event when creating the first error, but errors can also be deleted (suddenly created by mistake), which means that the event must be deleted. So it's even more confusing.
Can you tell me the best way to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DarkByte2015, 2018-08-15
@DarkByte2015

Everything was decided easier than ever. I began to link errors not to the return event, but to the review event. It's weird that I didn't even think of that! :D

F
Flying, 2018-08-14
@Flying

In general, such a workflow is usually implemented through state machines . There are at least two popular implementations for PHP: finite and the Symfony Workflow component . The latter definitely supports events .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question