[EXTENSION] simpleWorkflow

Hi.

Here’s my scenario.

  1. Just create a test table with two columns (id, status).

  2. Setup the simpleWorkflow as you describe in the docs.

  3. Within a command, just do:


<?php


class ProcessIncomingInvoiceInterfaceFileCommand extends CConsoleCommand {


    public function run($args) {

        $sw = new SwTest();

        echo $sw->swGetStatus()->getLabel() . PHP_EOL;

        if (!$sw->save())

            print_r($sw->getErrors ());

        yii::app()->end();

    }

}


?>



Here’s the result:


Pending

Array

(

    [status] => Array

        (

            [0] => value "" is not a valid status

        )


)



Here’s the swSwTest.php


<?php


return array(

    'initial' => 'pending',

    'node' => array(

        array('id' => 'pending',    'label' => yii::t('app', 'Pending'),    'transition' => 'processing'),

        array('id' => 'processing', 'label' => yii::t('app', 'Processing')),

    )

);

?>



Regards.

Hi jmariani,

I see no reason why this error message is raised …

  • The default initial status is correctly set (‘pending’),
  • the workflow definition is ok
  • the command code is ok

…the only thing is that I’ve never tested simpleWorkflow from within a console command. Could it be the reason why (according to your test) beforeSave is no invoked ? Maybe try the same scenario from a “regular” controller action …

Sorry but right now I’m on holiday, away from PC. I’ll not be able to work on your issue before next week.

I’ll keep you inform

ciao

B)

Hi Raoul. I’ll try to do it from a controller to see what’s going on.

I’ll keep you informed.

Regards and happy holidays!

Hi Raoul.

No luck. The same error is produced when I do that in a controller.

Regards.

Raoul, the problem seems to be that when it enters the SWValidator, the element "status" of the model is empty instead of having the default value.

Hi jmariani,

it seems I could reproduce the problem you reported … at first glance it seems to be a bug. If it is confirmed, I will release a new version as soon as possible (probably this week-end).

ciao

B)

Ok! Thank you very much!

great post. Thanks a lot for your informative useful post. Great job.

hi Raoul!

First of all this is amaizing plugin and very nice documentation! I’ve received a lot of pleasure reading it :)

I got a small question.

How to jump over some state? For example if it’s an admin, he could move Post from Draft to Published instead of Draft -> Moderated -> Published for the rest of non-admin users.

Thank you!

@jmariani : I’ve been working on a new release this week-end, but there still some work to do. Hopefully, I’ll be able to release a new version this week… sorry for the delay

@algebris : thanks for your comment ;)

Regarding your question, jumping from a status to another can be achieved by :

  • calling the method swNextStatus()

…or…

  • updating the model status attribute and saving the model.

To know what are statuses that can be reached depending on permission, you could for instance use constraints.

Constraints are conditions (basically PHP expressions) linked to statuses : the status can be reached only if the condition evaluates to TRUE.

To use your example, if only Admin user can send a Post to the PUBLISHED status, you could create a constraint on PUBLISHED that checks if current user has Admin permission.

hope this helps

ciao

Hi,

I have updated the simpleWorkflow extension which is now available in version 1.0. This release includes an important fix for the autoInsert feature and some improvements based on your posts in this topic.

I’ve tried to test it a lot but do not hesitate to reprot any issue you may find.

Changes :




Version 1.0


	fix : autoinsert into workflow (jmariani)

	enh : replace function is_a() by instanceof (kjharni)

	enh : metadata. It is now possible to add any value to node definition by using the metadata attribute.

	enh : workflow class definition. A workflow can be defined as a class that must implement method getDefinition() 

	which returns the workflow definition in its array format.

	enh : add 'leaveWorkflow' event. This event is fired whenever a component in a workflow reset its status.

	This must be done from a final status only.




…and some useful links :

  • simpleWorkflow Extension Page
  • direct download
  • Demos and Doc

I’ll try to release a “Quick Start Guide” as soon as possible …

ciao

B)

Hi, Raoul

Thank you very much for your update.

I’ll test it and let you know.

Cya!

[center][size="4"]version 1.1 of the simpleWorkflow extension has been released. [/size]

[/center]

Please check out the yii extension page for more information.

As I had enough of creating workflows manually (which can be painful if there is more than 5 statuses …[size=“1”]and if you are lazy[/size]), I’ve released a brand new Gii command that works together with a quite nice workflow editor application : yEd Graph Editor. (freeware)

Once installed, the Gii command is able to convert a workflow created by yEd and saved in graphml format, into a simpleWorkflow !!

[center] [/center][center][size="3"]check out the demo video[/size][/center]

Ok, it is still experimental and may need more test, so do not hesitate to send feedback if you find any issue using it.

Hope this will be useful

ciao

B)

[center] [/center]

Maybe somebody can help me with this, I need some guidance:

A model has an initial status PENDING, and from there you can go to VALID or ERROR.

My idea is like when I do swNextStatus(‘VALID’), a process must be triggered and depending on the result can end in VALID or ERROR, if it fails.

I think transitions task aren’t the tool, but I’m lost trying to do it with validations.

Other than that, looks like validation is now working…

Hi jmariani,

I’m afraid that what you’re trying to achieve is not possible using tasks as the value returned by a task is simply ignored. You’re describing a behavior (conditional branching) that is not built in the simpleWorkflow extension … and using validation is not the right way neither (that’s not the purpose it was designed for).

The only solution I see right now is to implement this logic in a method (or a class) external to simpleWorkflow.

Note that if a task transition return code is ignored, that is not the same with an exception being thrown during a task transition : if this occurs, the swNextStatus will "forward" the exception to the caller (your program).

What you could do is the following :

  • set your task to the PENDING -> VALID transition
  • if the task fails, it throws an exception
  • the swNextStatus() caller would catch the exception and send to owner model into ERROR

Let me know if you think this could be done…

ciao

B)

Hello Raoul,

First of all, congratulations very good job with the extension!!

I have been reviewing the documentation and is very interesting for me the workflow demo number five (http://s172418307.onlinehome.fr/project/yiiDemo/index.php?r=simpleworkflowdemo/demo5) where exists transitions between different workflows.

I would be pleased if I could take a look of the source code to see how it is implemented and how I would be able to implement a similar one on my own.

Thanks in advance:

Kike

Hi Raoul.

Thank you very much for your prompt response.

Yes, I was doing what you described, but I wanted to do something more "elegant".

I was trying also to do that using validations, so if the validation fails, I know I will switch statuses.

But the rule for “sw:PENDING_VALID” doesn’t trigger.

Regards.

Hi jamriani,

triggering a transition depending on validation result is indeed a good solution, and I think it should be implemented at a higher level than by the simpleWorkflow behavior itself. Now the problem is : why doesn’t your sw:PENDING_VALID validation rule trigger ? what is the extension version you’re using ? I will make some tests on it, just to check that there is no hidden bug messing around ;)

Hi Kike,

I’m not sure to understand what is your request, but here is a short description of inter-workflow transition with the simpleWorkflow extension.

The way inter-workflow transitions are implemented in the simpleWorkflow extension is quite … simple.

A status id used internally by the extension has always the following format : <workflow_id>/<node_id> (e.g. : “swPost/valid”, “task/assigned” …). When you work with one only workflow, you don’t have to use the fullname in your code, as long as you have defined what the “default workflow” is (this is because the extension will always use the default workflow associated to the model). So when you write :




 	$m=Post::model()->findByPk(1);

 	$m->swNextStatus('validated');



… the simpleWorkflow extension will use the default workflow that you have associated to the Post model (for example : ‘myPost’), and then create a full status id : ‘myPost/validated’.

Now if you want to jump from a workflow to another, you must use the full status id in the workflow definition array :




return array(

	'initial' => 'S1',

	'node' => array( 		

 		array(

 			'id' => 'S1',

 			'label' => 'status S1',

 			'transition'=> 'S1,S2,S3'

 		),

 		array(

 			'id' => 'S2',

 			'transition' => 'anotherWorkflow/P1'	// jump to another workflow !!

 		),

   	// etc ....

 

 	)

 );



Of course, if you want to be able to jump to the other workflow, you must provide a definittion for this workflow …

Hope this helps.

ciao

8)

hi, i have tested gii command to convert workflow but i have error: extension domxml not loaded : yEd converter requires domxml extension to process

i have dom extension loaded and i did read that domxml is not supported in php 5 (my php version is 5.4)

How can i solve this situation?

Bye!!!

Thank you very much Raoul,

That is just what I needed to know how to implement multi-workflow. I didn’t realize that the transition could be defined as workflowName/transitionNode and not only as transitionNode.

Bye!!!

Kike