Symfony workflow ::可以通过工作流程保护事件监听器

rma*_*lef 6 php workflow symfony twig

如果你们很多人已经测试过这个symfony workflow组件,我现在不要,但我希望你们中的一些人有:)

所以,我使用这个组件的两个对象,我想的第一个对象,以更新第二个取决于transition它的应用.

为此,我使用workflow guard listeneron my first object并尝试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
Run Code Online (Sandbox Code Playgroud)

订户

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

inf*_*iac 0

我想我遇到了和你一样的问题,并且我已经记录了 Symfony 项目的错误: https: //github.com/symfony/symfony/issues/33105