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