-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC] [Workflow] WIP Create MarkingHistoryStore to allow logging of an entity's states in the entity record #28265 #28266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
IMO this is a bit too specific functionality, and the implementation is very opinionated. Maybe create a bundle instead? I use this in my projects: class WorkflowLogListener implements EventSubscriberInterface
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
'workflow.completed' => 'completed',
];
}
public function completed(Event $event)
{
$subject = $event->getSubject();
$log = new WorkflowLog();
$log
->setSubjectClass(get_class($subject))
->setSubjectId($subject->getId())
->setWorkflow($event->getWorkflowName())
->setTransition($event->getTransition()->getName())
->setFroms($event->getTransition()->getFroms())
->setTos($event->getTransition()->getTos())
;
$this->em->persist($log);
$this->em->flush();
}
} |
Sure, but that isn't on the entity itself |
Not sure why that is a problem. Create a repository, add a method to select based on the entity(class and id), use that in the controller to fetch results. |
or put three extra lines in your workflow config. If you need more detailed log, then create your own listener. Your solution poses some problems:
|
Hi, generaly a workflow state is binded to a status of an entity I do something like this on most of my workflow entities when i want to track status change on specific entity, to answer your // the setStatus is called by our implementation of MarkingStoreInterface
public function setStatus(int $status): self
{
$this->status = $status;
$this->statusLogRecords->add(new MyEntityLog($this));
return $this;
} And the This PR #29146 will also allow us to add some context, like a comment, to this log if you need documentation or whatever when the state changes :) |
I totally agree with @noniagriconomie I'm really sorry to close your first PR on Symfony, but I can not merge this PR because we are several to prefer the solution proposed by @noniagriconomie Anyway, Thanks for your work. |
…ixx) This PR was merged into the 4.3-dev branch. Discussion ---------- [Workflow] Added a context to `Workflow::apply()` | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27925 (maybe #28253 and #28266) | License | MIT | Doc PR | Commits ------- 7d5b7a3 [Workflow] Added a context to `Workflow::apply()`
see #28253
This adds the feature for entities with workflows to keep a log of its previous states along with a timestamp.