eZ Publish  [trunk]
ezworkflowprocess.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZWorkflowProcess class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /*!
00012   \class eZWorkflowProcess ezworkflowprocess.php
00013   \brief
00014 
00015 */
00016 
00017 class eZWorkflowProcess extends eZPersistentObject
00018 {
00019     function eZWorkflowProcess( $row )
00020     {
00021         $this->eZPersistentObject( $row );
00022     }
00023 
00024     static function definition()
00025     {
00026         return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00027                                                         'datatype' => 'integer',
00028                                                         'default' => 0,
00029                                                         'required' => true ),
00030                                          'process_key' => array( 'name' => 'ProcessKey',
00031                                                                  'datatype' => 'string',
00032                                                                  'default' => '',
00033                                                                  'required' => true ),
00034                                          'workflow_id' => array( 'name' => 'WorkflowID',
00035                                                                  'datatype' => 'integer',
00036                                                                  'default' => 0,
00037                                                                  'required' => true,
00038                                                                  'foreign_class' => 'eZWorkflow',
00039                                                                  'foreign_attribute' => 'id',
00040                                                                  'multiplicity' => '1..*' ),
00041                                          'user_id' => array( 'name' => 'UserID',
00042                                                              'datatype' => 'integer',
00043                                                              'default' => 0,
00044                                                              'required' => true,
00045                                                              'foreign_class' => 'eZUser',
00046                                                              'foreign_attribute' => 'contentobject_id',
00047                                                              'multiplicity' => '1..*' ),
00048                                          'content_id' => array( 'name' => 'ContentID',
00049                                                                 'datatype' => 'integer',
00050                                                                 'default' => 0,
00051                                                                 'required' => true ),
00052                                          'content_version' => array( 'name' => 'ContentVersion',
00053                                                                      'datatype' => 'integer',
00054                                                                      'default' => 0,
00055                                                                      'required' => true ),
00056                                          'session_key' => array( 'name' => 'SessionKey',
00057                                                                  'datatype' => 'string',
00058                                                                  'default' => '0',
00059                                                                  'required' => true ),
00060                                          'node_id' => array( 'name' => 'NodeID',
00061                                                              'datatype' => 'integer',
00062                                                              'default' => 0,
00063                                                              'required' => true ),
00064                                          'event_id' => array( 'name' => 'EventID',
00065                                                               'datatype' => 'integer',
00066                                                               'default' => 0,
00067                                                               'required' => true ),
00068                                          'event_position' => array( 'name' => 'EventPosition',
00069                                                                     'datatype' => 'integer',
00070                                                                     'default' => 0,
00071                                                                     'required' => true ),
00072                                          'event_state' => array( 'name' => 'EventState',
00073                                                                  'datatype' => 'integer',
00074                                                                  'default' => 0,
00075                                                                  'required' => true ),
00076                                          'last_event_id' => array( 'name' => 'LastEventID',
00077                                                                    'datatype' => 'integer',
00078                                                                    'default' => 0,
00079                                                                    'required' => true ),
00080                                          'last_event_position' => array( 'name' => 'LastEventPosition',
00081                                                                          'datatype' => 'integer',
00082                                                                          'default' => 0,
00083                                                                          'required' => true ),
00084                                          'last_event_status' => array( 'name' => 'LastEventStatus',
00085                                                                        'datatype' => 'integer',
00086                                                                        'default' => 0,
00087                                                                        'required' => true ),
00088                                          'event_status' => array( 'name' => 'EventStatus',
00089                                                                   'datatype' => 'integer',
00090                                                                   'default' => 0,
00091                                                                   'required' => true ),
00092                                          'created' => array( 'name' => 'Created',
00093                                                              'datatype' => 'integer',
00094                                                              'default' => 0,
00095                                                              'required' => true ),
00096                                          'modified' => array( 'name' => 'Modified',
00097                                                               'datatype' => 'integer',
00098                                                               'default' => 0,
00099                                                               'required' => true ),
00100                                          'activation_date' => array( 'name' => 'ActivationDate',
00101                                                                      'datatype' => 'integer',
00102                                                                      'default' => 0,
00103                                                                      'required' => true ),
00104                                          'status' => array( 'name' => 'Status',
00105                                                             'datatype' => 'integer',
00106                                                             'default' => 0,
00107                                                             'required' => true ),
00108                                          'parameters' => array( 'name' => 'Parameters',
00109                                                                 'datatype' => 'text',
00110                                                                 'default' => '',
00111                                                                 'required' => true ),
00112                                          'memento_key' => array( 'name' => 'MementoKey',
00113                                                                  'datatype' => 'string',
00114                                                                  'default' => '',
00115                                                                  'required' => true,
00116                                                                  'foreign_class' => 'eZOperationMemento',
00117                                                                  'foreign_attribute' => 'memento_key',
00118                                                                  'multiplicity' => '1..*' ) ),
00119                       'keys' => array( 'id' ),
00120                       'function_attributes' => array( 'user' => 'user',
00121                                                       'content' => 'content',
00122                                                       'node' => 'node',
00123                                                       'workflow' => 'workflow',
00124                                                       'workflow_event' => 'workflowEvent',
00125                                                       'last_workflow_event' => 'lastWorkflowEvent',
00126                                                       'parameter_list' => 'parameterList' ),
00127                       "increment_key" => "id",
00128                       'class_name' => 'eZWorkflowProcess',
00129                       'sort' => array( 'user_id' => 'asc' ),
00130                       'name' => 'ezworkflow_process' );
00131     }
00132 
00133     static function create( $processKey, $parameters )
00134     {
00135         $dateTime = time();
00136         if ( !isset( $parameters['user_id'] ) )
00137             $parameters['user_id'] = 0;
00138         $row = array( 'process_key' => $processKey,
00139                       'workflow_id' => $parameters['workflow_id'],
00140                       'user_id' => $parameters['user_id'],
00141                       'content_id' => 0,
00142                       'content_version' => 0,
00143                       'node_id' => 0,
00144                       'session_key' => 0,
00145                       'event_id' => 0,
00146                       'event_position' => 0,
00147                       'last_event_id' => 0,
00148                       'last_event_position' => 0,
00149                       'last_event_status' => 0,
00150                       'event_status' => 0,
00151                       'created' => $dateTime,
00152                       'modified' => $dateTime,
00153                       'parameters' => serialize( $parameters ) );
00154         return new eZWorkflowProcess( $row );
00155     }
00156 
00157     function reset()
00158     {
00159         $this->EventID = 0;
00160         $this->EventPosition = 0;
00161         $this->LastEventID = 0;
00162         $this->LastEventPosition = 0;
00163         $this->LastEventStatus = 0;
00164         $this->ActivationDate = 0;
00165         $this->EventStatus = 0;
00166         $this->EventState = 0;
00167     }
00168 
00169     function advance( $next_event_id = 0, $next_event_pos = 0, $status = 0 )
00170     {
00171         $this->LastEventID = $this->EventID;
00172         $this->LastEventPosition = $this->EventPosition;
00173         $this->LastEventStatus = $status;
00174         $this->EventID =  $next_event_id;
00175         $this->EventPosition = $next_event_pos;
00176         $this->ActivationDate = 0;
00177     }
00178 
00179 
00180     function run( &$workflow, &$workflowEvent, &$eventLog )
00181     {
00182         $eventLog = array();
00183         eZDebugSetting::writeDebug( 'workflow-process', $workflowEvent, "workflowEvent in process->run beginning" );
00184 
00185         $runCurrentEvent = true;
00186         $done = false;
00187         $workflowStatus = $this->attribute( 'status' );
00188         eZDebugSetting::writeDebug( 'workflow-process', $workflowStatus , 'workflowStatus' );
00189         $currentEventStatus = $this->attribute( 'event_status' );
00190 
00191         // just temporary. needs to be removed from parameters
00192         if ( $workflowEvent == null )
00193         {
00194             $workflowEvent = eZWorkflowEvent::fetch( $this->attribute( 'event_id' ) );
00195         }
00196 
00197         switch( $currentEventStatus )
00198         {
00199             case eZWorkflowType::STATUS_DEFERRED_TO_CRON:
00200             case eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT:
00201             case eZWorkflowType::STATUS_FETCH_TEMPLATE:
00202             case eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT:
00203             case eZWorkflowType::STATUS_REDIRECT:
00204             case eZWorkflowType::STATUS_REDIRECT_REPEAT:
00205             case eZWorkflowType::STATUS_WORKFLOW_RESET:
00206             {
00207                 if ( $workflowEvent !== null )
00208                 {
00209                     $activationDate = 0;
00210                     if ( $this->hasAttribute( 'activation_date' ) )
00211                     {
00212                         $activationDate = $this->attribute( "activation_date" );
00213                     }
00214                     eZDebugSetting::writeDebug( 'workflow-process', "Checking activation date" );
00215                     if ( $activationDate == 0  )
00216                     {
00217                         $eventType = $workflowEvent->eventType();
00218                         $eventLog[] = array( "status" => $currentEventStatus,
00219                                              "status_text" => eZWorkflowType::statusName( $currentEventStatus ),
00220                                              "information" => $eventType->attribute( "information" ),
00221                                              "description" => $workflowEvent->attribute( "description" ),
00222                                              "type_name" => $eventType->attribute( "name" ),
00223                                              "type_group" => $eventType->attribute( "group_name" ) );
00224                         if ( $currentEventStatus == eZWorkflowType::STATUS_DEFERRED_TO_CRON ||
00225                              $currentEventStatus == eZWorkflowType::STATUS_FETCH_TEMPLATE   ||
00226                              $currentEventStatus == eZWorkflowType::STATUS_REDIRECT )
00227                         {
00228                             $runCurrentEvent = false;
00229                         }
00230                     }
00231                     else if ( time() < $activationDate )
00232                     {
00233                         eZDebugSetting::writeDebug( 'workflow-process', "Date failed, not running events" );
00234                         $eventType = $workflowEvent->eventType();
00235                         $eventLog[] = array( "status" => $currentEventStatus,
00236                                              "status_text" => eZWorkflowType::statusName( $currentEventStatus ),
00237                                              "information" => $eventType->attribute( "information" ),
00238                                              "description" => $workflowEvent->attribute( "description" ),
00239                                              "type_name" => $eventType->attribute( "name" ),
00240                                              "type_group" => $eventType->attribute( "group_name" ) );
00241                         $done = true;
00242                     }
00243                     else
00244                     {
00245                         eZDebugSetting::writeDebug( 'workflow-process', "Date ok, running events" );
00246                         eZDebugSetting::writeDebug( 'workflow-process', $currentEventStatus, 'WORKFLOW_TYPE_STATUS' );
00247                         if ( $currentEventStatus == eZWorkflowType::STATUS_DEFERRED_TO_CRON ||
00248                              $currentEventStatus == eZWorkflowType::STATUS_FETCH_TEMPLATE   ||
00249                              $currentEventStatus == eZWorkflowType::STATUS_REDIRECT )
00250                         {
00251                             $runCurrentEvent = false;
00252                         }
00253                     }
00254                 }
00255             } break;
00256             default:
00257                 break;
00258         }
00259 
00260         while ( !$done )
00261         {
00262             if ( $runCurrentEvent )
00263             {
00264                 eZDebugSetting::writeDebug( 'workflow-process', "runCurrentEvent is true" );
00265             }
00266             else
00267             {
00268                 eZDebugSetting::writeDebug( 'workflow-process', "runCurrentEvent is false" );
00269             }
00270             if ( $workflowEvent != null )
00271             {
00272                 //eZDebugSetting::writeDebug( 'workflow-process', $workflowEvent ,"workflowEvent  is not null" );
00273             }
00274             else
00275             {
00276                 //eZDebugSetting::writeDebug( 'workflow-process', $workflowEvent ,"workflowEvent  is  null" );
00277             }
00278             if ( $workflowEvent instanceof eZWorkflowEvent )
00279             {
00280                 eZDebugSetting::writeDebug( 'workflow-process', get_class( $workflowEvent ), "workflowEvent class is ezworkflowevent" );
00281             }
00282             else if ( $workflowEvent !== null )
00283             {
00284                 eZDebugSetting::writeDebug( 'workflow-process', get_class( $workflowEvent ), "workflowEvent class is not ezworkflowevent" );
00285             }
00286             eZDebugSetting::writeDebug( 'workflow-process', $done , "in while" );
00287             if ( $runCurrentEvent and
00288                  $workflowEvent !== null and
00289                  $workflowEvent instanceof eZWorkflowEvent )
00290             {
00291                 $eventType = $workflowEvent->eventType();
00292 
00293                 if ( $eventType instanceof eZWorkflowType )
00294                 {
00295                     $currentEventStatus = $eventType->execute( $this, $workflowEvent );
00296                     $this->setAttribute( "event_status", $currentEventStatus );
00297 
00298                     $workflowParameters = $this->attribute( 'parameter_list' );
00299 
00300                     if ( isset( $workflowParameters['cleanup_list'] ) )
00301                     {
00302                         $cleanupList = $workflowParameters['cleanup_list'];
00303                     }
00304                     else
00305                     {
00306                         unset( $cleanupList );
00307                         $cleanupList = array();
00308                     }
00309 
00310                     if ( $eventType->needCleanup() )
00311                     {
00312                         $cleanupList[] = $workflowEvent->attribute( 'id' );
00313                         $workflowParameters['cleanup_list'] = $cleanupList;
00314                         $this->setAttribute( 'parameters', serialize( $workflowParameters ) );
00315                     }
00316 
00317                     eZDebugSetting::writeDebug( 'workflow-process', $currentEventStatus, "currentEventStatus" );
00318                     switch( $currentEventStatus )
00319                     {
00320                         case eZWorkflowType::STATUS_ACCEPTED:
00321                         {
00322                             $done = false;
00323                             $workflowStatus = eZWorkflow::STATUS_DONE;
00324                         }break;
00325                         case eZWorkflowType::STATUS_WORKFLOW_DONE:
00326                         {
00327                             $done = true;
00328                             $workflowStatus = eZWorkflow::STATUS_DONE;
00329                         } break;
00330                         case eZWorkflowType::STATUS_REJECTED:
00331                         {
00332                             $done = true;
00333                             $workflowStatus = eZWorkflow::STATUS_FAILED;
00334                         } break;
00335                         case eZWorkflowType::STATUS_DEFERRED_TO_CRON:
00336                         case eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT:
00337                         {
00338                             if ( $eventType->hasAttribute( "activation_date" ) )
00339                             {
00340                                 $date = $eventType->attribute( "activation_date" );
00341                                 $this->setAttribute( "activation_date", $date );
00342                             }
00343                             $workflowStatus = eZWorkflow::STATUS_DEFERRED_TO_CRON;
00344                             $done = true;
00345                         } break;
00346                         case eZWorkflowType::STATUS_FETCH_TEMPLATE:
00347                         {
00348                             $workflowStatus = eZWorkflow::STATUS_FETCH_TEMPLATE;
00349                             $done = true;
00350                         } break;
00351                         case eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT:
00352                         {
00353                             $workflowStatus = eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT;
00354                             $done = true;
00355                         } break;
00356                         case eZWorkflowType::STATUS_REDIRECT:
00357                         case eZWorkflowType::STATUS_REDIRECT_REPEAT:
00358                         {
00359                             $workflowStatus = eZWorkflow::STATUS_REDIRECT;
00360                             $done = true;
00361                             $this->advance();
00362                         } break;
00363                         case eZWorkflowType::STATUS_RUN_SUB_EVENT:
00364                         {
00365                             eZDebug::writeWarning( "Run sub event not supported yet", __METHOD__ );
00366                         } break;
00367                         case eZWorkflowType::STATUS_WORKFLOW_CANCELLED:
00368                         {
00369                             $done = true;
00370                             $this->advance();
00371                             $workflowStatus = eZWorkflow::STATUS_CANCELLED;
00372                         } break;
00373                         case eZWorkflowType::STATUS_WORKFLOW_RESET:
00374                         {
00375                             $done = true;
00376                             $this->reset();
00377                             $workflowStatus = eZWorkflow::STATUS_RESET;
00378                         } break;
00379                         case eZWorkflowType::STATUS_NONE:
00380                         {
00381                             eZDebug::writeWarning( "Workflow executing status is eZWorkflowType::STATUS_NONE", __METHOD__ );
00382                         } break;
00383                         default:
00384                         {
00385                             eZDebug::writeWarning( "Unknown status '$currentEventStatus'", __METHOD__ );
00386                         } break;
00387                     }
00388                     $eventLog[] = array( "status" => $currentEventStatus,
00389                                          "status_text" => eZWorkflowType::statusName( $currentEventStatus ),
00390                                          "information" => $eventType->attribute( "information" ),
00391                                          "description" => $workflowEvent->attribute( "description" ),
00392                                          "type_name" => $eventType->attribute( "name" ),
00393                                          "type_group" => $eventType->attribute( "group_name" ) );
00394                 }
00395                 else
00396                 {
00397                     eZDebug::writeError( "Expected an eZWorkFlowType object", __METHOD__ );
00398                 }
00399             }
00400             else
00401             {
00402                 eZDebugSetting::writeDebug( 'workflow-process', "Not running current event. Trying next" );
00403             }
00404             $runCurrentEvent = true;
00405             // still not done
00406             if ( !$done )
00407             {
00408                 // fetch next event
00409                 $event_pos = $this->attribute( "event_position" );
00410 
00411                 $next_event_pos = $event_pos + 1;
00412                 $next_event_id = $workflow->fetchEventIndexed( $next_event_pos );
00413                 if ( $next_event_id !== null )
00414                 {
00415                     eZDebugSetting::writeDebug( 'workflow-process', $event_pos , "workflow not done");
00416                     $this->advance( $next_event_id, $next_event_pos, $currentEventStatus );
00417                     $workflowEvent = eZWorkflowEvent::fetch( $next_event_id );
00418                 }
00419                 else
00420                 {
00421                     $done = true;
00422                     unset( $workflowEvent );
00423                     eZDebugSetting::writeDebug( 'workflow-process', $event_pos , "workflow done");
00424                     $workflowStatus = eZWorkflow::STATUS_DONE;
00425                     $this->advance();
00426                 }
00427             }
00428 
00429         }
00430 
00431         $this->setAttribute( "status", $workflowStatus );
00432         $this->setAttribute( "modified", time() );
00433         return $workflowStatus;
00434     }
00435 
00436     static function fetch( $id, $asObject = true )
00437     {
00438         return eZPersistentObject::fetchObject( eZWorkflowProcess::definition(),
00439                                                 null,
00440                                                 array( 'id' => $id ),
00441                                                 $asObject );
00442     }
00443 
00444     static function fetchList( $conds = null, $asObject = true, $offset = false, $limit = false )
00445     {
00446         $limitation = array( 'offset' => $offset,
00447                              'length' => $limit );
00448         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00449                                                     null, $conds, null, $limitation,
00450                                                     $asObject );
00451     }
00452 
00453     static function createKey( $parameters, $keys = null )
00454     {
00455         $string = '';
00456         if ( $keys != null )
00457         {
00458             foreach ( $keys as $key )
00459             {
00460                 $value = $parameters[$key];
00461                 if ( is_array( $value ) )
00462                 {
00463                     $value = serialize( $value );
00464                 }
00465                 $string .= $key . $value;
00466             }
00467         }else
00468         {
00469             foreach ( array_keys( $parameters ) as $key )
00470             {
00471                 $value = $parameters[$key];
00472                 if ( is_array( $value ) )
00473                 {
00474                     $value = serialize( $value );
00475                 }
00476                 $string .= $key . $value;
00477             }
00478         }
00479         return md5( $string );
00480     }
00481 
00482 
00483 
00484     static function fetchListByKey( $searchKey, $asObject = true )
00485     {
00486         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00487                                                     null,
00488                                                     array( 'process_key' => $searchKey ), null, null,
00489                                                     $asObject );
00490     }
00491 
00492     static function fetchUserList( $userID, $asObject = true )
00493     {
00494         $conds = array( 'user_id' => $userID );
00495         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00496                                                     null, $conds, null, null,
00497                                                     $asObject );
00498     }
00499 
00500     static function fetchForContent( $workflowID, $userID,
00501                                $contentID, $contentVersion, $nodeID,
00502                                $asObject = true )
00503     {
00504         $conds = array( 'workflow_id' => $workflowID,
00505                         'user_id' => $userID,
00506                         'content_id' => $contentID,
00507                         'content_version' => $contentVersion,
00508                         'node_id' => $nodeID );
00509         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00510                                                     null, $conds, null, null,
00511                                                     $asObject );
00512     }
00513 
00514     static function fetchForStatus( $status = eZWorkflow::STATUS_DEFERRED_TO_CRON,  $asObject = true )
00515     {
00516         $conds = array( 'status' => $status );
00517 
00518         $db = eZDB::instance();
00519         if ( $db->databaseName() == 'oracle' )
00520             $conds['LENGTH(memento_key)'] = array( '!=', 0 );
00521         else
00522             $conds['memento_key'] = array( '!=', '' );
00523 
00524         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00525                                                     null, $conds, null, null,
00526                                                     $asObject );
00527     }
00528 
00529     static function fetchForSession( $sessionKey, $workflowID, $asObject = true )
00530     {
00531         $conds = array( 'workflow_id' => $workflowID,
00532                         'session_key' => $sessionKey );
00533         return eZPersistentObject::fetchObjectList( eZWorkflowProcess::definition(),
00534                                                     null, $conds, null, null,
00535                                                     $asObject );
00536     }
00537 
00538     function currentEvent()
00539     {
00540     }
00541 
00542     function advanceToNext()
00543     {
00544     }
00545 
00546     function setParameters( $parameterList = null )
00547     {
00548         if ( $parameterList !== null )
00549         {
00550             $this->Parameters = $parameterList;
00551             unset( $this->ParameterList );
00552         }
00553         $this->setAttribute( 'parameters', serialize( $this->Parameters ) );
00554         return $this->attribute( 'parameter_list' );
00555     }
00556 
00557     function user()
00558     {
00559         if ( isset( $this->UserID ) and $this->UserID )
00560         {
00561             return eZUser::instance( $this->UserID );
00562         }
00563         return null;
00564     }
00565 
00566     function content()
00567     {
00568         if ( isset( $this->ContentID ) and $this->ContentID )
00569         {
00570             return eZContentObject::fetch( $this->ContentID );
00571         }
00572         return null;
00573     }
00574 
00575     function node()
00576     {
00577         if ( isset( $this->NodeID ) and $this->NodeID )
00578         {
00579             return eZContentObjectTreeNode::fetch( $this->NodeID );
00580         }
00581         return null;
00582     }
00583 
00584     function workflow()
00585     {
00586         if ( isset( $this->WorkflowID ) and $this->WorkflowID )
00587         {
00588             return eZWorkflow::fetch( $this->WorkflowID );
00589         }
00590         return null;
00591     }
00592 
00593     function workflowEvent()
00594     {
00595         if ( isset( $this->EventID ) and $this->EventID )
00596         {
00597             return eZWorkflowEvent::fetch( $this->EventID );
00598         }
00599         return null;
00600     }
00601 
00602     function lastWorkflowEvent()
00603     {
00604         if ( isset( $this->LastEventID ) and $this->LastEventID )
00605         {
00606             return eZWorkflowEvent::fetch( $this->LastEventID );
00607         }
00608         return null;
00609     }
00610 
00611     function parameterList()
00612     {
00613         if ( !isset( $this->ParameterList ) )
00614         {
00615             $this->ParameterList = unserialize( $this->attribute( 'parameters' ) );
00616         }
00617         return $this->ParameterList;
00618     }
00619 
00620     /*!
00621      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00622      the calls within a db transaction; thus within db->begin and db->commit.
00623      */
00624     function removeThis()
00625     {
00626         $workflowParameters = $this->attribute( 'parameter_list' );
00627         $cleanupList = array();
00628 
00629         $db = eZDB::instance();
00630         $db->begin();
00631         if ( isset( $workflowParameters['cleanup_list'] ) && is_array( $workflowParameters['cleanup_list'] ) )
00632         {
00633             $cleanupList = $workflowParameters['cleanup_list'];
00634             foreach ( $cleanupList as $workflowEventID )
00635             {
00636                 $workflowEvent = eZWorkflowEvent::fetch( $workflowEventID );
00637                 $workflowType = $workflowEvent->eventType();
00638                 $workflowType->cleanup( $this, eZWorkflowEvent::fetch( $workflowEventID ) );
00639             }
00640         }
00641         eZPersistentObject::removeObject( eZWorkflowProcess::definition(), array( 'id' => $this->attribute( 'id' ) ) );
00642         $db->commit();
00643     }
00644 
00645     /*!
00646      \static
00647      Removes all workflow processes from database.
00648      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00649      the calls within a db transaction; thus within db->begin and db->commit.
00650     */
00651     function cleanup()
00652     {
00653         $db = eZDB::instance();
00654         $db->query( "DELETE FROM ezworkflow_process" );
00655     }
00656 
00657     /// \privatesection
00658     public $ID;
00659     public $WorkflowID;
00660     public $UserID;
00661     public $ContentID;
00662     public $NodeID;
00663     public $EventID;
00664     public $EventPosition;
00665     public $LastEventID;
00666     public $LastEventPosition;
00667     public $LastEventStatus;
00668     public $EventStatus;
00669     public $Created;
00670     public $Modified;
00671     public $ActivationDate;
00672 }
00673 
00674 ?>