static function removeGroup( $workflowID, $workflowVersion, $selectedGroup ) { $workflow = eZWorkflow::fetch( $workflowID ); if ( !$workflow ) return false; $groups = $workflow->attribute( 'ingroup_list' ); foreach ( array_keys( $groups ) as $key ) { if ( in_array( $groups[$key]->attribute( 'group_id' ), $selectedGroup ) ) { unset( $groups[$key] ); } } if ( count( $groups ) == 0 ) { return false; } else { $db = eZDB::instance(); $db->begin(); foreach( $selectedGroup as $group_id ) { eZWorkflowGroupLink::removeByID( $workflowID, $workflowVersion, $group_id ); } $db->commit(); } return true; }
function removeSelectedGroups($http, &$groups, $base) { if ($http->hasPostVariable("DeleteGroupButton")) { if (eZHTTPPersistence::splitSelected($base, $groups, $http, "id", $keepers, $rejects)) { $groups = $keepers; foreach ($rejects as $reject) { $group_id = $reject->attribute("id"); // Remove all workflows in current group $list_in_group = eZWorkflowGroupLink::fetchWorkflowList(0, $group_id, $asObject = true); $workflow_list = eZWorkflow::fetchList(); $list = array(); foreach ($workflow_list as $workflow) { foreach ($list_in_group as $group) { $id = $workflow->attribute("id"); $workflow_id = $group->attribute("workflow_id"); if ($id === $workflow_id) { $list[] = $workflow; } } } foreach ($list as $workFlow) { eZTrigger::removeTriggerForWorkflow($workFlow->attribute('id')); $workFlow->remove(); } $reject->remove(); eZWorkflowGroupLink::removeGroupMembers($group_id); } } } }
function ingroupIDList() { $list = eZWorkflowGroupLink::fetchGroupList($this->attribute("id"), $this->attribute("version"), false); $this->InGroupIDs = array(); foreach ($list as $item) { $this->InGroupIDs[] = $item['group_id']; } return $this->InGroupIDs; }
$workflowgroup->store(); } // Remove version 1 eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 1 ); eZWorkflow::removeEvents( false, $WorkflowID, 0 ); $workflow->removeThis( true ); $workflow->setVersion( 0, $event_list ); $workflow->adjustEventPlacements( $event_list ); // $workflow->store( $event_list ); $workflow->storeDefined( $event_list ); $workflow->cleanupWorkFlowProcess(); $db->commit(); $workflowGroups= eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true ); $groupID = false; if ( count( $workflowGroups ) > 0 ) $groupID = $workflowGroups[0]->attribute( 'group_id' ); if ( $groupID ) return $Module->redirectToView( 'workflowlist', array( $groupID ) ); else return $Module->redirectToView( 'grouplist' ); } // Remove events which are to be deleted else if ( $http->hasPostVariable( "DeleteButton" ) ) { if ( $canStore ) $workflow->store( $event_list ); } // Add new workflow event
$workflow = $workflows[$workflowID]; $workflowList[$workflow->attribute( 'id' )] = $workflow; } */ $user = eZUser::currentUser(); $list_in_group = eZWorkflowGroupLink::fetchWorkflowList(0, $WorkflowGroupID, $asObject = true); $workflow_list = eZWorkflow::fetchList(); $list = array(); foreach ($workflow_list as $workflow) { foreach ($list_in_group as $inGroup) { if ($workflow->attribute('id') === $inGroup->attribute('workflow_id')) { $list[] = $workflow; } } } $templist_in_group = eZWorkflowGroupLink::fetchWorkflowList(1, $WorkflowGroupID, $asObject = true); $tempworkflow_list = eZWorkflow::fetchList(1); $temp_list = array(); foreach ($tempworkflow_list as $tmpWorkflow) { foreach ($templist_in_group as $tmpInGroup) { if ($tmpWorkflow->attribute('id') === $tmpInGroup->attribute('workflow_id')) { $temp_list[] = $tmpWorkflow; } } } $Module->setTitle(ezpI18n::tr('kernel/workflow', 'Workflow list of group') . ' ' . $WorkflowGroupID); $WorkflowgroupInfo = eZWorkflowGroup::fetch($WorkflowGroupID); if (!$WorkflowgroupInfo) { return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $tpl = eZTemplate::factory();
function createApprovalWorkFlow($approvalUserID) { $workflow = eZWorkflow::create($approvalUserID); $workflow->setAttribute("name", "eZApproveTypeRegression Workflow"); $workflow->store(); $workflowID = $workflow->attribute("id"); $workflowVersion = $workflow->attribute("version"); $groupID = 1; $groupName = "Standard"; $ingroup = eZWorkflowGroupLink::create($workflowID, $workflowVersion, $groupID, $groupName); $ingroup->store(); $approveEvent = eZWorkflowEvent::create($workflowID, "event_ezapprove"); $approveEventType = $approveEvent->eventType(); $approveEventType->initializeEvent($approveEvent); // Affected sections, -1 == All sections $approveEvent->setAttribute("data_text1", "-1"); // Affected languages, 0 == All languages $approveEvent->setAttribute("data_int2", 0); // Affected versions $approveEvent->setAttribute("data_int3", eZApproveType::VERSION_OPTION_ALL); // Editors $approveEvent->setAttribute("data_text3", $approvalUserID); $approveEvent->store(); $eventList = array($approveEvent); $workflow->store($eventList); 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->setVersion(0, $eventList); $workflow->adjustEventPlacements($eventList); $workflow->storeDefined($eventList); $workflow->cleanupWorkFlowProcess(); $workflow->store($eventList); return $workflow; }
static function fetchGroupList($workflow_id, $workflow_version, $asObject = true) { return eZPersistentObject::fetchObjectList(eZWorkflowGroupLink::definition(), null, array("workflow_id" => $workflow_id, "workflow_version" => $workflow_version), null, null, $asObject); }
/** * Helper function used to remove a workflow. * Will remove the workflow, its events, its triggers and its group link. * * @param eZWorkflow $workflow * @return void */ protected function removeWorkflow(eZWorkflow $workflow) { // Remove trigger eZTrigger::removeTriggerForWorkflow($workflow->attribute('id')); // remove the workflow, its events and the group link eZWorkflow::removeEvents(false, $workflow->attribute('id'), $workflow->attribute('version')); eZWorkflow::removeWorkflow($this->workflow->attribute('id'), $workflow->attribute('version')); eZWorkflowGroupLink::removeWorkflowMembers($workflow->attribute('id'), $workflow->attribute('version')); }
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(); } } }