public function getReport() { // quick and dirty: use same data as for the web $tpl = sysInfoTools::eZTemplateFactory(); $tpl->setVariable('title', 'Workflows Report'); $workflows = eZWorkflow::fetchList(); $triggers = eZTrigger::fetchList(); $tpl->setVariable('workflows', $workflows); $tpl->setVariable('triggers', $triggers); $htmlReport = $tpl->fetch("design:sysinfo/workflowsreport.tpl"); return $htmlReport; }
} $moduleName = '*'; $functionName = '*'; if ($http->hasPostVariable('RemoveButton')) { if ($http->hasPostVariable('DeleteIDArray')) { $deleteIDArray = $http->postVariable('DeleteIDArray'); $db = eZDB::instance(); $db->begin(); foreach ($deleteIDArray as $deleteID) { eZTrigger::remove($deleteID); } $db->commit(); } } $tpl = eZTemplate::factory(); $triggers = eZTrigger::fetchList(array('module' => $moduleName, 'function' => $functionName)); $showModuleList = false; $showFunctionList = false; $functionList = array(); $moduleList = array(); if ($moduleName == '*') { $showModuleList = true; $ini = eZINI::instance('module.ini'); $moduleList = $ini->variable('ModuleSettings', 'ModuleList'); } elseif ($functionName == '*') { $mod = eZModule::exists($moduleName); $functionList = array_keys($mod->attribute('available_functions')); eZDebug::writeNotice($functionList, "functions"); $showFunctionList = true; } $tpl->setVariable('current_module', $moduleName);
$limit = $limitList[$limitId]; } $viewParameters = array('offset' => $offset); $plist = eZWorkflowProcess::fetchList($conds, true, $offset, $limit); $plistCount = eZWorkflowProcess::count(eZWorkflowProcess::definition(), $conds); $totalProcessCount = 0; $outList2 = array(); foreach ($plist as $p) { $mementoMain = eZOperationMemento::fetchMain($p->attribute('memento_key')); $mementoChild = eZOperationMemento::fetchChild($p->attribute('memento_key')); if (!$mementoMain or !$mementoChild) { continue; } $mementoMainData = $mementoMain->data(); $mementoChildData = $mementoChild->data(); $triggers = eZTrigger::fetchList(array('module_name' => $mementoChildData['module_name'], 'function_name' => $mementoChildData['operation_name'], 'name' => $mementoChildData['name'])); if (count($triggers) > 0) { $trigger = $triggers[0]; if (is_object($trigger)) { $nkey = $trigger->attribute('module_name') . '/' . $trigger->attribute('function_name') . '/' . $trigger->attribute('name'); if (!isset($outList2[$nkey])) { $outList2[$nkey] = array('trigger' => $trigger, 'process_list' => array()); } $outList2[$nkey]['process_list'][] = $p; $totalProcessCount++; } } } // Template handling $tpl = eZTemplate::factory(); $tpl->setVariable("module", $Module);
<?php $workflows = eZWorkflow::fetchList(); $triggers = eZTrigger::fetchList(); $tpl->setVariable('workflows', $workflows); $tpl->setVariable('triggers', $triggers);
function execute( $xml ) { $workflowGroupList = $xml->getElementsByTagName( 'WorkflowGroup' ); $user = eZUser::currentUser(); $userID = $user->attribute( "contentobject_id" ); foreach ( $workflowGroupList as $workflowGroupNode ) { $groupName = $workflowGroupNode->getAttribute( 'name' ); $referenceID = $workflowGroupNode->getAttribute( 'referenceID' ); $groupExistAction = $workflowGroupNode->getAttribute( 'groupExistAction' ); $workflowGroup = null; if ( $groupExistAction == 'keep' ) { $workflowGroupList = eZWorkflowGroup::fetchList(); foreach ( $workflowGroupList as $workflowGroupItem ) { if ( $workflowGroupItem->attribute( 'name' ) == $groupName ) { $workflowGroup = $workflowGroupItem; break; } } } if ( $workflowGroup !== null ) { $this->writeMessage( "\tWorkflow Group '$groupName' already exists." , 'notice' ); } else { $this->writeMessage( "\tWorkflow Group '$groupName' will be created." , 'notice' ); $workflowGroup = eZWorkflowGroup::create( $userID ); $workflowGroup->setAttribute( "name", $groupName ); $workflowGroup->store(); } $WorkflowGroupID = $workflowGroup->attribute( "id" ); $refArray = array(); if ( $referenceID ) { $refArray[$referenceID] = $WorkflowGroupID; } $this->addReference( $refArray ); $workflowList = $workflowGroupNode->getElementsByTagName( 'Workflow' ); foreach ( $workflowList as $workflowNode ) { $refArray = array(); $workflowName = $workflowNode->getAttribute( 'name' ); $workflowTypeString = $workflowNode->getAttribute( 'workflowTypeString' ); $referenceID = $workflowNode->getAttribute( 'referenceID' ); $workflowExistAction = $workflowNode->getAttribute( 'workflowExistAction' ); $WorkflowID = $workflowNode->getAttribute( 'id' ); $workflow = null; $hasWorkflowDraft = false; $db = eZDB::instance(); if ( !$workflowExistAction ) { $workflowExistAction = 'extend'; } if ( $WorkflowID ) { $workflow = eZWorkflow::fetch( $WorkflowID, true, 1 ); if ( !is_object( $workflow ) ) { $workflow = eZWorkflow::fetch( $WorkflowID, true, 0 ); if ( is_object( $workflow ) ) { $workflowGroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true ); $db->begin(); foreach ( $workflowGroups as $workflowGroup ) { $groupID = $workflowGroup->attribute( "group_id" ); $groupName = $workflowGroup->attribute( "group_name" ); $ingroup = eZWorkflowGroupLink::create( $WorkflowID, 1, $groupID, $groupName ); $ingroup->store(); } $db->commit(); } else { $this->writeMessage( "\tFailed to fetch workflow with ID '$WorkflowID'." , 'notice' ); $workflow = null; } } } $db->begin(); if ( $workflow === null ) { $this->writeMessage( "\tWorkflow '$workflowName' will be created." , 'notice' ); $workflow = eZWorkflow::create( $userID ); $workflow->setAttribute( "name", $workflowName ); if ( $workflowTypeString ) { $workflow->setAttribute( "workflow_type_string", $workflowTypeString ); } $workflow->store(); $ingroup = eZWorkflowGroupLink::create( $workflow->attribute( "id" ), $workflow->attribute( "version" ), $WorkflowGroupID, $groupName ); $ingroup->store(); } else { $hasWorkflowDraft = true; switch ( $workflowExistAction ) { case 'extend': { $this->writeMessage( "\tExtending existing workflow '" . $workflow->attribute( 'name' ) . "'." , 'notice' ); } break; case 'replace': { $this->writeMessage( "\tReplacing existing workflow '" . $workflow->attribute( 'name' ) . "'." , 'notice' ); eZWorkflow::removeEvents( false, $workflow->attribute( "id" ), $workflow->attribute( "version" ) ); } break; default: { $this->writeMessage( "\tUnknown workflowExistAction '" . $workflowExistAction . "'." , 'notice' ); } } } $WorkflowID = $workflow->attribute( "id" ); $WorkflowVersion = $workflow->attribute( "version" ); $db->commit(); if ( $referenceID ) { $refArray[$referenceID] = $WorkflowID; } $eventList = $workflow->fetchEvents(); $eventNodeList = $workflowNode->getElementsByTagName( 'Event' ); $maxPlacement = -1; foreach ( $eventList as $event ) { if ( $event->attribute( 'placement' ) > $maxPlacement ) { $maxPlacement = $event->attribute( 'placement' ); } } foreach ( $eventNodeList as $eventNode ) { $description = $eventNode->getAttribute( 'description' ); $workflowTypeString = $eventNode->getAttribute( 'workflowTypeString' ); $placement = $eventNode->getAttribute( 'placement' ); $event = eZWorkflowEvent::create( $WorkflowID, $workflowTypeString ); $eventType = $event->eventType(); $db->begin(); $workflow->store( $eventList ); $eventType->initializeEvent( $event ); if ( is_numeric( $placement ) ) { $eventType->setAttribute( 'placement', (int)$placement ); } else { ++$maxPlacement; $eventType->setAttribute( 'placement', $maxPlacement ); } $eventDataNode = $eventNode->getElementsByTagName( 'Data' )->item( 0 ); if ( $eventDataNode ) { $attributes = $eventDataNode->childNodes; foreach ( $attributes as $attribute ) { if ( $event->hasAttribute( $attribute->nodeName ) ) { $data = $this->parseAndReplaceStringReferences( $attribute->textContent ); $event->setAttribute( $attribute->nodeName, $data ); } } } $event->store(); $db->commit(); $eventList[] = $event; } // Discard existing events, workflow version 1 and store version 0 $db->begin(); $workflow->store( $eventList ); // store changes. // Remove old version 0 first eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 0 ); $workflowgroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 1 ); foreach( $workflowgroups as $workflowgroup ) { $workflowgroup->setAttribute("workflow_version", 0 ); $workflowgroup->store(); } // Remove version 1 eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 1 ); eZWorkflow::removeEvents( false, $WorkflowID, 0 ); $workflow->removeThis( true ); $workflow->setVersion( 0, $eventList ); $workflow->adjustEventPlacements( $eventList ); $workflow->storeDefined( $eventList ); $workflow->cleanupWorkFlowProcess(); $db->commit(); if ( $referenceID ) { $refArray[$referenceID] = $WorkflowID; } $this->addReference( $refArray ); } } $triggerList = $xml->getElementsByTagName( 'Trigger' ); foreach ( $triggerList as $triggerNode ) { $module = $triggerNode->getAttribute( 'module' ); $operation = $triggerNode->getAttribute( 'operation' ); $connectType = $triggerNode->getAttribute( 'connectType' ); $workflowID = $this->getReferenceID( $triggerNode->getAttribute( 'workflowID' ) ); $this->writeMessage( "\tTrigger '$module/$operation/$connectType' will be created/updated." , 'notice' ); if ( $connectType == 'before' ) { $connectType = 'b'; } else { $connectType = 'a'; } $parameters = array(); $parameters['module'] = $module; $parameters['function'] = $operation; $parameters['connectType'] = $connectType; $triggerList = eZTrigger::fetchList( $parameters ); if ( count( $triggerList ) ) { $trigger = $triggerList[0]; $trigger->setAttribute( 'workflow_id', $workflowID ); $trigger->store(); } else { $db = eZDB::instance(); $db->begin(); $newTrigger = eZTrigger::createNew( $module, $operation, $connectType, $workflowID ); $db->commit(); } } }