如果你们很多人已经测试了symfony workflow
组件但我希望你们中的一些人有:)
所以,我在两个对象上使用此组件,我希望第一个对象 更新 第二个 取决于它正在应用的transition
。
为此,我使用第一个对象上的workflow guard listener
并尝试在我的第二个对象上执行workflow::apply
(使用第二个工作流程)。 ..)
问题在于,当我制作workflow::can
时,该活动已发送,并尝试在秒中应用新状态对象 ...这是非常不正常的,因为我只是问我是否可以应用某些过渡而不要求实际应用它在我的第一个对象。
framework:
workflows:
request_for_operation:
type: 'state_machine'
marking_store:
type: 'single_state'
arguments:
- 'status'
supports:
- AppBundle\Entity\RequestForOperation
places:
- draft
- pending_for_management
- in_progress
- finished
- canceled
transitions:
request_for_operations:
from: draft
to: pending_for_management
start_rfop_management:
from: pending_for_management
to: in_progress
close:
from: in_progress
to: finished
cancel:
from: [pending_for_management, in_progress]
to: canceled
operation:
type: 'state_machine'
marking_store:
type: 'single_state'
arguments:
- 'status'
supports:
- AppBundle\Entity\Operation
places:
- draft
- pending_for_management
- in_progress
- finished
- canceled
transitions:
validate_operation:
from: draft
to: pending_for_management
start_tracking:
from: pending_for_management
to: in_progress
close:
from: in_progress
to: finished
cancel:
from: [pending_for_management, in_progress]
to: canceled
class RequestForOperationListener implements EventSubscriberInterface
{
public function __construct(
OperationManager $operationManager,
UserNotifier $userNotifier
) {
$this->operationManager = $operationManager;
$this->userNotifier = $userNotifier;
}
public static function getSubscribedEvents()
{
return [
'workflow.request_for_operation.guard.request_for_operations' => ['onRequestForOperations'],
'workflow.request_for_operation.guard.start_rfop_management' => ['onStartRfopManagement'],
'workflow.request_for_operation.guard.close' => ['onClose'],
'workflow.request_for_operation.guard.cancel' => ['onCancel'],
];
}
public function onRequestForOperations(GuardEvent $event)
{
/** @var RequestForOperation $rfop */
$rfop = $event->getSubject();
//get all the operations linked to the rfop
$operations = $rfop->getOperations();
foreach ($operations as $operation) {
//set the status of the operation to 'pending_for_management'
$this->operationManager->applyTransition($operation, 'validate_operation');
//set the status of the sub-operations to 'pending_for_management'
foreach ($operation->getChildren() as $subOperation) {
$this->operationManager->applyTransition($subOperation, 'validate_operation');
}
//get the users (i.e: managers) linked to the operation and notify them (by mail or whatever)
$this->notifyAssignedUsers($operation->getUsers(), $operation);
}
}
}
答案 0 :(得分:0)
我认为我遇到了与您相同的问题,并且我已经在Symfony项目中记录了一个错误:https://github.com/symfony/symfony/issues/33105