Yii Framework Forum: [EXTENSION] simpleWorkflow - Yii Framework Forum

Jump to content

  • (8 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] simpleWorkflow a small workflow handler for models Rate Topic: ***** 3 Votes

#81 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 31 July 2012 - 11:25 PM

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.
0

#82 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 01 August 2012 - 02:49 AM

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)
0

#83 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 01 August 2012 - 07:09 AM

View PostRaoul, on 01 August 2012 - 02:49 AM, said:

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!
0

#84 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 01 August 2012 - 09:06 AM

Hi Raoul.

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

Regards.
0

#85 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 02 August 2012 - 09:46 AM

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.
0

#86 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 08 August 2012 - 03:08 PM

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)
0

#87 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 10 August 2012 - 02:43 PM

Ok! Thank you very much!
0

#88 User is offline   myforum2015 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 25-June 12

Posted 11 August 2012 - 12:00 AM

great post. Thanks a lot for your informative useful post. Great job.
Visit My site:
android games
0

#89 User is offline   Algebris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 01-April 10

Posted 12 August 2012 - 12:37 AM

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!
0

#90 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 12 August 2012 - 12:20 PM

@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

Posted Image
0

#91 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 15 August 2012 - 12:16 PM

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 :


I'll try to release a "Quick Start Guide" as soon as possible ....

ciao
B)
0

#92 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 15 August 2012 - 05:46 PM

Hi, Raoul

Thank you very much for your update.
I'll test it and let you know.

Cya!
0

#93 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 19 September 2012 - 03:28 PM

version 1.1 of the simpleWorkflow extension has been released.

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 ...and if you are lazy), 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 !!

check out the demo video
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)

2

#94 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 18 October 2012 - 09:17 AM

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...
0

#95 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 18 October 2012 - 11:25 AM

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)
0

#96 User is offline   Kike 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 29-April 10

Posted 18 October 2012 - 05:19 PM

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.on...kflowdemo/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
0

#97 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 19 October 2012 - 07:40 AM

View PostRaoul, on 18 October 2012 - 11:25 AM, said:

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)


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.
0

#98 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 636
  • Joined: 29-November 08
  • Location:Paris, France

Posted 21 October 2012 - 05:21 AM

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)
1

#99 User is offline   salsero 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 05-September 12
  • Location:Italia

Posted 22 October 2012 - 09:05 AM

Quote

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

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



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!!!
0

#100 User is offline   Kike 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 30
  • Joined: 29-April 10

Posted 22 October 2012 - 10:10 AM

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
0

Share this topic:


  • (8 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users