[EXTENSION] simpleWorkflow

hey Ehsanjs !

if you’re still thinking to use the workflow component provided by the EzComponents library, maybe this wiki article can be intresting for you …

bye

8)

Tanks Raoul

I am Ehsan and this article is written by myself

;)

:lol::lol::lol:

[font="Courier New"]this is a reply to comment from [b]philippfrenzel /b[/font]

Hi philippfrenzel,

could you please provide more information on your problem ? The piece of code you posted in your comment doesn’t contain any status change, so I’m not sure to understand what behavior you were expecting ? Is it a status change on the Customer or on the Event instance ?

ciao

Hi Raoul,

I found out, that it was my own fault, as I send the status-field two times from two different Workflows…

What would be very helpful is if you can pls. post the code of your workflow samples too…? Is that possible, as I try to build an action on transition, where i change the status of a related workflow too…

Anyway your extension is so cool! As I rely on business processes, a workflow management is mandantory… If I’m allowed, I will bring up some feature request within the next days?

Cheers Phil

Hi Raoul,

Thank you for the simply AMAZING job you did with simpleWorkflow. I am very new at yii, so pardon me if this is a dumb question, but it seems like there can me many situations in a workflow when a node constraint is based on TIME. Say a rule like:

"step B can only occur after step A but must occur within 3 days of start of step A."

-or-

"if Step B does not occur within 3 days of Step A then transition to Step C"

How would you code these kinds of rules? Can it be done?

Thanks Again for your generosity and great documentation!

Hi Windsor,

and thank for your comment about simpleWorkflow… I apreciate.

Regarding your question, the cases you describe could be indeed very useful to handle with workflow… unfortunatly, the simpleWorkflow extension is currently not able to handle these scenario… it has no built-in feature to change the status of an object in an "automatic" way.

In its architecture, simpleWorkflow can’t be viewed as a real workflow engine, it is only a behavior, added to Yii ActiveRecord. Moreover, the type of condition you describe on transition would require to implement different types of transitions : automatic transitions (triggered by time and.or logical conditions), manual transition (based from user action). Then, a real workflow engine should be implemented, independently for workflow items (ActiveRecord, Components), that would be called on each HTTP request in order to apply pending transitions.

This is an very intresting topic, but right now again, this is far from what simpleWorkflow is. I’ve been thinking about this kind of evolution (revolution) for the simpleWorkflow extension, and I wish I had enough time to implement my ideas …

In the meantime, the only thing I can do for you is mention this wiki article, that describes (very briefly) how to use EzComponents with Yii. This open source library provides anintresting implementation of workflow classes that maybe can help you. You can also contact Ehsanjs (the author) who may have some experience on the subject.

Sorry I could not help you more …

ciao

B)

Raoul,

Thanks for the quick reply and clear explanation. If you need some help putting your ideas into action, please reach out and email me, I have some time, but very little knowledge ;) This seems like a worthwhile and useful enhancement and I would be happy to help you in any way I can. For example, prototyping, testing, documentation, etc. Fair warning: I am by no means a “professional” developer anymore, but very willing to help and teachable. except if you ask my wife :D:slight_smile: !

Ok windosr, I take note of you offer and added you to my friend list ;)

ciao

8)

Hi All,

First of all I would like to thank Raoul for this smart, great and amazing extension witch saves me a lot of work.

Yesterday, my web app went down displaying this phperror :

include(Canceled.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

#0 /home/{…}/yii/framework/YiiBase.php(421): YiiBase::autoload()

#1 unknown(0): YiiBase::autoload("Canceled")

#2 unknown(0): spl_autoload_call("Canceled")

#3 /home/{…}/extensions/simpleWorkflow/SWNode.php(50): is_a("Canceled", "SWNode")

#4 /home/{…}/extensions/simpleWorkflow/SWNode.php(127): SWNode->__construct("Canceled", "swDemande")

#5 /home/{…}/extensions/simpleWorkflow/SWNode.php(78): SWNode->_loadTransition(array("Canceled" => "", "Submitted" => ""), "swDemande")

where "Canceled" is supposed to be a status.

This had no sense to me since the application was working fine.

I retrieved both the application and database on my computer and the application works perfectly.

I noticed that it was the is_a function witch tries le load the class file.

I figure out later that this function changed the its behaviors with the 5.3.7 release of PHP and that it was deprecated so I replaced it with the instanceof operator and the web app worked as a charm.

My provider upgrades php version from 5.2.17 to 5.3.8 and my wamp is on 5.3.0.

So may be a release is necessary to fix this issue.

Sorry for being long.

Thank you once again.

I did that too. And it works like a charm. :)

Hi to both of you,

… and thanks for the feedback. I will release a new version as soon as possible and replace is_a by instanceof following your advice ;)

cheers

B)

Hi,

That looks like a great extension.

I’m quite a newbie in Yii, so I can’t make it working.

I have an error :


include(correction.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

If I declare a node without a transition, no error…

Here is the trace :


include(correction.php) [<a href='function.include'>function.include</a>]:

failed to open stream: No such file or directory

(E:\xampp\framework\YiiBase.php:421)

Stack trace:

#0 unknown(0): spl_autoload_call()

#1

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWNode.php(50):

is_a()

#2

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWNode.php(118):

SWNode->__construct()

#3

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWNode.php(77):

SWNode->_loadTransition()

#4

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWPhpWorkflowSource.php(87):

SWNode->__construct()

#5

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWPhpWorkflowSource.php(63):

SWPhpWorkflowSource->_createWorkflow()

#6

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWPhpWorkflowSource.php(202):

SWPhpWorkflowSource->_load()

#7

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWActiveRecordBehavior.php(311):

SWPhpWorkflowSource->getInitialNode()

#8

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWActiveRecordBehavior.php(232):

SWActiveRecordBehavior->swInsertToWorkflow()

#9

E:\xampp\htdocs\LPForms\protected\extensions\simpleWorkflow\SWActiveRecordBehavior.php(208):

SWActiveRecordBehavior->initialize()

#10 E:\xampp\framework\base\CComponent.php(336):

SWActiveRecordBehavior->attach()

#11 E:\xampp\framework\base\CComponent.php(303):

DemandeClient->attachBehavior()

#12 E:\xampp\framework\db\ar\CActiveRecord.php(373):

DemandeClient->attachBehaviors()

#13 E:\xampp\framework\db\ar\CActiveRecord.php(387): model()

#14 E:\xampp\framework\db\ar\CActiveRecord.php(62):

DemandeClient->getMetaData()

#15

E:\xampp\htdocs\LPForms\protected\controllers\DemandeClientController.php(48):

DemandeClient->__construct()

#16 E:\xampp\framework\web\actions\CInlineAction.php(50):

DemandeClientController->actionCreate()

#17 E:\xampp\framework\web\CController.php(300):

CInlineAction->runWithParams()

#18 E:\xampp\framework\web\filters\CFilterChain.php(134):

DemandeClientController->runAction()

#19 E:\xampp\framework\web\filters\CFilter.php(41): CFilterChain->run()

#20 E:\xampp\framework\web\CController.php(1144):

CAccessControlFilter->filter()

#21 E:\xampp\framework\web\filters\CInlineFilter.php(59):

DemandeClientController->filterAccessControl()

#22 E:\xampp\framework\web\filters\CFilterChain.php(131):

CInlineFilter->filter()

#23 E:\xampp\framework\web\CController.php(283): CFilterChain->run()

#24 E:\xampp\framework\web\CController.php(257):

DemandeClientController->runActionWithFilters()

#25 E:\xampp\framework\web\CWebApplication.php(277):

DemandeClientController->run()

#26 E:\xampp\framework\web\CWebApplication.php(136):

CWebApplication->runController()

#27 E:\xampp\framework\base\CApplication.php(158):

CWebApplication->processRequest()

#28 E:\xampp\htdocs\LPForms\index.php(13): CWebApplication->run()

REQUEST_URI=/lpforms/index.php?r=demandeclient/create

Could you give me a clue to solve this?

Many thanks

EDIT : No well slept this night… the answer was in front of me (in this case, the last post). Sorry guys!

Hi,

In my project, we are storing the status in a separate table, called statuses with a string column named status. What modification I need to do, to use this extension?

Thanks.

Hi Robezy,

I must say that the modification you suggest is quite heavy work to do, as the simpleWorkflow extension is designed to use a specific attribute (‘status’) in the same table of the concerned active record.

I’ll try to see if I can find an easy solution, but I don’t garantee anything …

ciao

B)

Hi, Raoul.

What a great work have you done.

I’m testing it, and I configured my workflow as in the docs, but when i do a Save, I get “value is not a valid status”

My workflow config is:


return array(

    'initial' => 'new',

    'node' => array(

        array('id' => 'new', 'transition' => 'pending,rejected'),

        array('id' => 'pending', 'transition' => 'activated,rejected'),

        array('id' => 'rejected', 'transition' => 'pending'),

        array('id' => 'activated'),

    )

);



Any guidance you might give me?

Thank you in advance!

Maybe there was some misunderstanding from myself.

I thought the behaviour will set the initial value for a status if the status is empty. Am I wrong?

If I set the status to a value before I save a new model, it works as expected, but if I leave the status empty, it throws a validation error.

Hi!

Small question:

How to get the initial status from a model?

I want to set the status as initial in a beforeValidate event.

TIA!

Hi jmariani,

(sorry I didn’t see your messages before)

By default, the simpleWorkflow behavior is configured as autoInsert=true, which means that the newly created model instance is automatically inserted into its associated default workflow… so you understood well ;)

To find out why it doesn’t occur in your case, my first suggestion would be to verify that a defautl workflow could be found.

First you could get the default Workflow Id associated with your model :


$workflowId = $model->swGetDefaultWorkflowId();

Then as you requested, get the intial status for this workflow :




Yii::app()->swSource->getInitialNode($workflowId);


// other option is to call swGetNextStatus() because if the model is not in a workflow, this method will return

// the initial node of the default workflow.


$next = $model->swGetNextStatus();

echo $next[0]->toString();




(I am currently away from my pc so unable to test the code above …but it should work )

If this does not help, could you please provide a complete sample so I can try to reproduce the error this week-end ? … or at least understan what’s goign wrong.

ciao

B)

Hi, Raoul.

Thank you for your support.

It looks like it never enters the “beforeSave” event and that’s why it never gets the default initial status.

Any clue?