|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of Runcronworflows class 00004 // 00005 // Created on: <02-οΛΤ-2002 14:04:21 sp> 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 /*! \file runcronworflows.php 00032 */ 00033 00034 $runInBrowser = true; 00035 if ( isset( $webOutput ) ) 00036 $runInBrowser = $webOutput; 00037 00038 require_once( "lib/ezutils/classes/ezdebug.php" ); 00039 //include_once( "lib/ezutils/classes/ezini.php" ); 00040 00041 //include_once( "kernel/classes/ezworkflowprocess.php" ); 00042 //include_once( "kernel/classes/ezcontentobject.php" ); 00043 //include_once( "kernel/classes/datatypes/ezuser/ezuser.php" ); 00044 //include_once( "lib/ezutils/classes/ezoperationmemento.php" ); 00045 //include_once( "lib/ezutils/classes/ezoperationhandler.php" ); 00046 require_once( "lib/ezutils/classes/ezsession.php" ); 00047 00048 require_once( "lib/ezutils/classes/ezdebug.php" ); 00049 //include_once( "lib/ezutils/classes/ezini.php" ); 00050 //include_once( "lib/ezutils/classes/ezdebugsetting.php" ); 00051 00052 $workflowProcessList = eZWorkflowProcess::fetchForStatus( eZWorkflow::STATUS_DEFERRED_TO_CRON ); 00053 //var_dump( $workflowProcessList ); 00054 //$user = eZUser::instance( 14 ); 00055 00056 if ( !$isQuiet ) 00057 $cli->output( "Checking for workflow processes" ); 00058 $removedProcessCount = 0; 00059 $processCount = 0; 00060 $statusMap = array(); 00061 foreach( $workflowProcessList as $process ) 00062 { 00063 $workflow = eZWorkflow::fetch( $process->attribute( "workflow_id" ) ); 00064 00065 if ( $process->attribute( "event_id" ) != 0 ) 00066 $workflowEvent = eZWorkflowEvent::fetch( $process->attribute( "event_id" ) ); 00067 $process->run( $workflow, $workflowEvent, $eventLog ); 00068 // Store changes to process 00069 00070 ++$processCount; 00071 $status = $process->attribute( 'status' ); 00072 if ( !isset( $statusMap[$status] ) ) 00073 $statusMap[$status] = 0; 00074 ++$statusMap[$status]; 00075 00076 if ( $process->attribute( 'status' ) != eZWorkflow::STATUS_DONE ) 00077 { 00078 if ( $process->attribute( 'status' ) == eZWorkflow::STATUS_RESET || 00079 $process->attribute( 'status' ) == eZWorkflow::STATUS_FAILED || 00080 $process->attribute( 'status' ) == eZWorkflow::STATUS_NONE || 00081 $process->attribute( 'status' ) == eZWorkflow::STATUS_CANCELLED || 00082 $process->attribute( 'status' ) == eZWorkflow::STATUS_BUSY 00083 ) 00084 { 00085 $bodyMemento = eZOperationMemento::fetchMain( $process->attribute( 'memento_key' ) ); 00086 $mementoList = eZOperationMemento::fetchList( $process->attribute( 'memento_key' ) ); 00087 $bodyMemento->remove(); 00088 foreach( $mementoList as $memento ) 00089 { 00090 $memento->remove(); 00091 } 00092 } 00093 00094 if ( $process->attribute( 'status' ) == eZWorkflow::STATUS_CANCELLED ) 00095 { 00096 ++$removedProcessCount; 00097 $process->removeThis(); 00098 } 00099 else 00100 { 00101 $process->store(); 00102 } 00103 } 00104 else 00105 { //restore memento and run it 00106 $bodyMemento = eZOperationMemento::fetchChild( $process->attribute( 'memento_key' ) ); 00107 if ( is_null( $bodyMemento ) ) 00108 { 00109 eZDebug::writeError( $bodyMemento, "Empty body memento in workflow.php" ); 00110 continue; 00111 } 00112 $bodyMementoData = $bodyMemento->data(); 00113 $mainMemento = $bodyMemento->attribute( 'main_memento' ); 00114 if ( !$mainMemento ) 00115 continue; 00116 00117 $mementoData = $bodyMemento->data(); 00118 $mainMementoData = $mainMemento->data(); 00119 $mementoData['main_memento'] = $mainMemento; 00120 $mementoData['skip_trigger'] = true; 00121 $mementoData['memento_key'] = $process->attribute( 'memento_key' ); 00122 $bodyMemento->remove(); 00123 $operationParameters = array(); 00124 if ( isset( $mementoData['parameters'] ) ) 00125 $operationParameters = $mementoData['parameters']; 00126 $operationResult = eZOperationHandler::execute( $mementoData['module_name'], $mementoData['operation_name'], $operationParameters, $mementoData ); 00127 ++$removedProcessCount; 00128 $process->removeThis(); 00129 } 00130 00131 } 00132 if ( !$isQuiet ) 00133 { 00134 $cli->output( $cli->stylize( 'emphasize', "Status list" ) ); 00135 $statusTextList = array(); 00136 $maxStatusTextLength = 0; 00137 foreach ( $statusMap as $statusID => $statusCount ) 00138 { 00139 $statusName = eZWorkflow::statusName( $statusID ); 00140 $statusText = "$statusName($statusID)"; 00141 $statusTextList[] = array( 'text' => $statusText, 00142 'count' => $statusCount ); 00143 if ( strlen( $statusText ) > $maxStatusTextLength ) 00144 $maxStatusTextLength = strlen( $statusText ); 00145 } 00146 foreach ( $statusTextList as $item ) 00147 { 00148 $text = $item['text']; 00149 $count = $item['count']; 00150 $cli->output( $cli->stylize( 'success', $text ) . ': ' . str_repeat( ' ', $maxStatusTextLength - strlen( $text ) ) . $cli->stylize( 'emphasize', $count ) ); 00151 } 00152 $cli->output(); 00153 $cli->output( $cli->stylize( 'emphasize', $removedProcessCount ) . " out of " . $cli->stylize( 'emphasize', $processCount ) . " processes was finished" ); 00154 } 00155 00156 ?>