public function setFailedTransition(Identifier $identifier, Transition $transition, \Exception $e)
{
// check if it is persisted, otherwise we cannot get the current state
$message = new \stdClass();
$message->code = $e->getCode();
$message->transition = $transition->getName();
$message->message = $e->getMessage();
$message->file = $e->getFile();
$message->line = $e->getLine();
if ($this->isPersisted($identifier)) {
/*
a transition can fail even after a state has been set in the transition process,
for example when executing the code in the entry action of the new state,
making the transition partly failed.
the history will then show a succesful transition to the new state first,
and here we will then add the failure of the transition with the current state (which is the 'to' state of the transition)
and with the failure message.
In case that the transition failed before the state has been set
then this will be put in the history of transitions with the 'from' state as the current state.
*/
$state = $this->getState($identifier);
} else {
//no current state available in persistence layer.
//this is exceptional and should not happen when configured correctly and
//if the machine has been 'added' or if a transition has been (partly) mande.
//therefore, it must be the from state..
$state = $transition->getStateFrom()->getName();
}
$message->state = $state;
$this->addHistory($identifier, $state, $message, true);
}