raoul2000 / yii2-workflow

A simple workflow engine for Yii2
BSD 3-Clause "New" or "Revised" License
171 stars 48 forks source link

Two workflow in a model - disable validation between the two statuses #62

Closed ilbassa closed 4 years ago

ilbassa commented 4 years ago

I have problem validating the status attribute of two workflow attached to a model.

Saving the model it try to validate the passage from status of workflow 1 (STATO attribute) to status of workflow 2 (STATO_INTERNO attribute), the error is: {"STATO_INTERNO":["Workflow validation failed : No transition found between status DomandeWorkflow/VALIDATA and DomandeWorkflowBackoffice/DALAVORARE"]}

How I can not validate passage from a workflow to another?

ilbassa commented 4 years ago

The solution I found is to detach the old behaviour and to attach the new behaviour. I also change the scenario to validate the new attribute

['STATO', WorkflowValidator::class, 'on' => self::SCENARIO_DEFAULT],
['STATO_INTERNO', WorkflowValidator::class, 'on' => self::SCENARIO_BACKOFFICE],

if($this->statusEquals(DomandeWorkflow::STATUS_PROTOCOLLATA)){
            $this->detachBehavior('simpleWorkflow');
            $this->attachBehavior('backofficeWorkflow',[
                'class'                  => SimpleWorkflowBehavior::class,
                'defaultWorkflowId'      => 'DomandeWorkflowBackoffice',
                'statusAttribute'        => 'STATO_INTERNO',
                'propagateErrorsToModel' => true,
            ]);
            $this->scenario = self::SCENARIO_BACKOFFFICE;
        }