raoul2000 / yii2-workflow

A simple workflow engine for Yii2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To store workflow's in DB

vkonde opened this issue · comments

Store status in DB with workflow name and get it..

I don't no is this way is right or wrong....

i have create array as per work flow definition but i get following error.

"name": "Workflow Validation Exception", "message": "One or more end status are not defined : [\n 0 => 'UploadresultWorkflow/deleted'\n 1 => 'UploadresultWorkflow/approval'\n 2 => 'UploadresultWorkflow/approve'\n 3 => 'UploadresultWorkflow/disapprove'\n 4 => 'UploadresultWorkflow/deleted'\n]",

and this is my getDefinition()..

public function getDefinition() {

        $init = WorkflowTransition::find()
                ->where(['workflow_name' => 'visa1'])
                ->One();
        $status = WorkflowTransition::find()
                ->where(['workflow_name' => 'visa1'])
                ->All();
        $defination =  [
                    'initialStatusId' => $init->initial,
                    'status' => [
                        ]
            ];
        foreach($status as $value)
                        {

                                explode: $thePostIdArray = explode(',', $value->transition);
                                $transition['transition'] = $thePostIdArray;
                                $defination['status'][$value->initial] = $transition; 

                        }
                        return $defination;
    }
$status = WorkflowTransition::find()
                ->where(['workflow_name' => 'visa1'])
                ->All();

how can make "visa1" (i.e document type changeable ), when user uploading document. can we pass parameter.

commented

I will reply next week

fine, i have also done with this document type changeable with session,but still i want to more discuss with you.
thnk you.

commented

Hi vkonde,
I'm back from holidays and try to reply to your question. From what I understand you want to store workflow definition into DB. To do so, you should write a workflow source component dedicated to read the workflow from DB, and not from file (like the workflow source component provided with yii2-workflow).

Sometimes ago @feor58 has the same request and I advice you take a look to this issue where we discussed this subject. In this discussion I have proposed an example of implementation which is incomplete, but can give you an idea on how to implement a workflowDbSource component.

bye

yes, i had done in same way like this get all transitions from DB and return array.

hi,
but my DB structure is different and this is my getDefinition return following array :
i don't know this is the correct way but it works for me, but yet I am not assigning one workflow for multiple Document type

 public function getDefinition() {
        $workflowname = \yii::$app->session->get('workflowname');
        $init = WorkflowTransition::find()
                ->where(['workflow_name' => $workflowname])
                ->One();
        $status = WorkflowTransition::find()
                ->where(['workflow_name' => $workflowname])
                ->All();
        $defination =  [
                    'initialStatusId' => $init->initial,
                    'status' => [
                        ]
            ];
        foreach($status as $value)
                        {                           
                                explode: $thePostIdArray = explode(',', $value->transition);
                                $transition['transition'] = $thePostIdArray;
                                $defination['status'][$value->initial] = $transition;                           
                        }
        return $defination; 
    }
commented

Workflow assignation is done by setting the status to the initial status of a workflow.
If you want to assign a workflow to a Model depending on a model's attribute (the Document type) you must implement it (as it is not a built-in feature).

For example :

if( $model->type == 'TypeA') {
    $model->status = 'workflowA/draft';
} elseif( $model->type == 'TypeB') {
    $model->status = 'workflowB/draft';
} // etc ....

hi,
there is another problem in the workflow if i wants to get following,
$model = UploadResult::find()->all();
it's give me error because of the workflow model loads after calling UploadResult :
public function behaviors() { return [ \raoul2000\workflow\base\SimpleWorkflowBehavior::className() ]; }
my workflow definition set if session is set so...