Sebastian Bergmann wrote:
> rumich wrote:
>> Maybe Sebastian's diploma thesis, that I believe is the best
>> documentation to this module ever, is ready and can be somehow
>> published?
>
> I hope to be able to finally publish the thesis soon as I was just
> yesterday informed that it has been (after 7 months) been graded.
>
Well, after 3 days of reading classes sources, I thought I understood
how to deal with workflow, but...
This is how I was trying to deploy the example from Workflow tutorial.
Unfortunately this does not work.
I can successfully create and save workflow execution instance, but I am
not able to resume (and end) it after loading back from database
(section wf_action.php). My observations are, when I am dumping $execute
object after loading it from database, that $waitingFor array of object
is empty. This is not the case when I create the object ($waitingFor has
value).
So step by step:
1. wf_create.php //$execute instance creation:
<?php
[...]
$execution = new ezcWorkflowDatabaseExecution( $db );
// Pass workflow object to workflow executer.
$execution->workflow = $workflow;
// Start workflow execution.
$id = $execution->start();
var_dump($execution);
?>
Results:
[...]
["waitingFor:protected"]=> array(1) { ["choice"]=> array(2) {
["node"]=> string(2) "44" ["condition"]=>
object(ezcWorkflowConditionIsBool)#12 (0) { } } }
2. wf_action.php //load execution instance by id to resume and end it
<?php
[...]
$db = ezcDbFactory::create( $dbparams );
// Set up database-based workflow executer.
$execution = new ezcWorkflowDatabaseExecution( $db, $id );
var_dump($execution);
?>
Results:
[...]
["waitingFor:protected"]=> array(0) { }
What I am doing wrong? Maybe my understanding of the whole idea is
wrong? Any help is appreciated :)
Full source below:
//***************************************
// *** Workflow definition *** test_1.xml
//***************************************
<?xml version="1.0" encoding="UTF-8" ?>
<workflow name="Test" version="1">
<node id="1" type="Start">
<outNode id="2" />
</node>
<node id="2" type="Input">
<variable name="choice">
<condition type="IsBool" />
</variable>
<outNode id="3" />
</node>
<node id="3" type="ExclusiveChoice">
<condition type="Variable" name="choice">
<condition type="IsTrue" />
<outNode id="4" />
</condition>
<condition type="Variable" name="choice">
<condition type="IsFalse" />
<outNode id="7" />
</condition>
</node>
<node id="4" type="Action" serviceObjectClass="MyServiceObject">
<arguments>
<boolean>true</boolean>
</arguments>
<outNode id="5" />
</node>
<node id="5" type="SimpleMerge">
<outNode id="6" />
</node>
<node id="6" type="End" />
<node id="7" type="Action" serviceObjectClass="MyServiceObject">
<arguments>
<boolean>false</boolean>
</arguments>
<outNode id="5" />
</node>
</workflow>
//*******************************************************
// *** Service object definition *** wf_serviceObject.php
//*******************************************************
<?php
class MyServiceObject implements ezcWorkflowServiceObject
{
private $message;
public function __construct( $message )
{
$this->message = $message;
}
public function execute( ezcWorkflowExecution $execution )
{
echo $this->message;
// Manipulate the workflow.
// Does not affect the workflow, for ilustration only.
$execution->setVariable( 'choice', true );
// Return true to signal that the service object has finished
// executing.
return true;
}
public function __toString()
{
return "MyServiceObject, message {$this->message}";
}
};//class MyServiceObject
?>
//*********************************************
// *** create new instance of workflow document
// *** based on xml definiion*** wf_create.php
//*********************************************
<?php
require_once "Base/src/base.php";
require_once 'wf_serviceObject.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
};
$definition = new ezcWorkflowDefinitionStorageXml( './wf_defs/' );
// Load latest version of workflow named "Test".
$workflow = $definition->loadByName( 'Test' );
//prepare for workflow instance (execution thread)
$dbparams = array(
'type' => 'mysql',
'dbname' => 'test',
'user' => 'root',
'pass' => 'passhere' );
$db = ezcDbFactory::create( $dbparams );
$definition = new ezcWorkflowDatabaseDefinitionStorage( $db );
// Save workflow definition to database.
$definition->save( $workflow );
// Generate GraphViz/dot markup for workflow "Test".
$visitor = new ezcWorkflowVisitorVisualization;
$workflow->accept( $visitor );
echo $visitor;
$execution = new ezcWorkflowDatabaseExecution( $db );
// Pass workflow object to workflow executer.
$execution->workflow = $workflow;
// Start workflow execution.
$id = $execution->start();
var_dump($execution);
echo "Document instance created. ID= ".$id;
if($execution->isSuspended())
{
echo "\nCreated document is suspended, waiting for approval\n";
$waitFor = $execution->getWaitingFor();
var_dump($waitFor);
printf("<p><a href='/wf_action.php?wid=$id'>Click here to approve
it</a></p>");
}
else
{
echo "Created document is NOT suspended, still wondering why";
};
?>
<p><a href="./index.html">Back to menu</a></p>
//******************************************************
//*** resume suspended workflow *** wf_action.php
//******************************************************
<?php
$id = $_GET['wid'];
require_once "Base/src/base.php";
require_once 'wf_serviceObject.php';
function __autoload( $className )
{
ezcBase::autoload( $className );
};
$dbparams = array(
'type' => 'mysql',
'dbname' => 'test',
'user' => 'root',
'pass' => 'passhere' );
$db = ezcDbFactory::create( $dbparams );
// Set up database-based workflow executer.
$execution = new ezcWorkflowDatabaseExecution( $db, $id );
var_dump($execution);
// Resume workflow execution.
$execution->resume( array( 'choice' => true ) );
echo "execution->resume fired";
?>
//*** END of source code ***
--
kind regards
rumich
----------------------------------------------------------------------
Bedac w WC czytala wiadomosci.
>>> http://link.interia.pl/f1b9c
--
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components